addCors
mach::AppBuilder::addCors
Adds CORS.
Description
Section titled “Description”Adds CORS support to the application.
Syntax
Section titled “Syntax”template <typename TConfigure> requires std::invocable<TConfigure, CorsBuilder&>AppBuilder& addCors(TConfigure&& configure);Return Value
Section titled “Return Value”A reference to the current AppBuilder instance.
Template Parameters
Section titled “Template Parameters”| Parameter | Description |
|---|---|
TConfigure |
The type of the callable used to configure CORS. |
Parameters
Section titled “Parameters”| Parameter | Description |
|---|---|
configure |
A callable that receives a CorsBuilder used to configure CORS. |
Remarks
Section titled “Remarks”- The configuration callable is invoked immediately and receives a
CorsBuilderby reference. - Changes made after
App::run()has been called do not take effect.
Thread Safety
Section titled “Thread Safety”This method is not thread-safe and should only be called during application configuration, before the application starts handling requests.
Example
Section titled “Example”builder.addCors([](mach::CorsBuilder& cors) { cors.allowOrigin("https://example.com") .allowMethods({mach::http::Method::Get, mach::http::Method::Post}) .allowHeaders({"Content-Type", "Authorization"}) .allowCredentials();});See Also
Section titled “See Also”| Name | Description |
|---|---|
CorsBuilder |
Configures CORS policies. |