Skip to content
Download

addCors

mach::AppBuilder::addCors

Adds CORS.

Adds CORS support to the application.

template <typename TConfigure>
requires std::invocable<TConfigure, CorsBuilder&>
AppBuilder& addCors(TConfigure&& configure);

A reference to the current AppBuilder instance.

Parameter Description
TConfigure The type of the callable used to configure CORS.
Parameter Description
configure A callable that receives a CorsBuilder used to configure CORS.
  • The configuration callable is invoked immediately and receives a CorsBuilder by reference.
  • Changes made after App::run() has been called do not take effect.

This method is not thread-safe and should only be called during application configuration, before the application starts handling requests.

builder.addCors([](mach::CorsBuilder& cors) {
cors.allowOrigin("https://example.com")
.allowMethods({mach::http::Method::Get, mach::http::Method::Post})
.allowHeaders({"Content-Type", "Authorization"})
.allowCredentials();
});
Name Description
CorsBuilder Configures CORS policies.