CorsOptions
| Source | aws-apigateway/lib/cors.ts |
|---|
Example
apigateway.RestApi(self, "api",
default_cors_preflight_options=apigateway.CorsOptions(
allow_origins=apigateway.Cors.ALL_ORIGINS,
allow_methods=apigateway.Cors.ALL_METHODS
)
)
RestApi.Builder.create(this, "api")
.defaultCorsPreflightOptions(CorsOptions.builder()
.allowOrigins(Cors.ALL_ORIGINS)
.allowMethods(Cors.ALL_METHODS)
.build())
.build();
// Install: dotnet add package Amazon.CDK.Lib
new RestApi(this, "api", new RestApiProps {
DefaultCorsPreflightOptions = new CorsOptions {
AllowOrigins = Cors.ALL_ORIGINS,
AllowMethods = Cors.ALL_METHODS
}
});
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
apigateway.NewRestApi(this, jsii.String("api"), &RestApiProps{
DefaultCorsPreflightOptions: &CorsOptions{
AllowOrigins: apigateway.Cors_ALL_ORIGINS(),
AllowMethods: apigateway.Cors_ALL_METHODS(),
},
})
Properties
allowCredentialsoptionalbooleanallow_credentialsoptionalboolallowCredentialsoptionalBooleanAllowCredentialsoptionalboolAllowCredentialsoptional*bool = false #notes
When a request's credentials mode (Request.credentials) is "include", browsers will only expose the response to frontend JavaScript code if the Access-Control-Allow-Credentials value is true.
Credentials are cookies, authorization headers or TLS client certificates.
allowHeadersoptionalstring[]allow_headersoptionaltyping.List[str]allowHeadersoptionalList<String>AllowHeadersoptionalstring[]AllowHeadersoptional*[]*string = Cors.DEFAULT_HEADERS #allowMethodsoptionalstring[]allow_methodsoptionaltyping.List[str]allowMethodsoptionalList<String>AllowMethodsoptionalstring[]AllowMethodsoptional*[]*string = Cors.ALL_METHODS #If ANY is specified, it will be expanded to Cors.ALL_METHODS.
allowOriginsstring[]allow_originstyping.List[str]allowOriginsList<String>AllowOriginsstring[]AllowOrigins*[]*string required #notes
If you wish to allow all origins, specify Cors.ALL_ORIGINS or [ * ].
Responses will include the Access-Control-Allow-Origin response header. If specific origins are specified (not Cors.ALL_ORIGINS), the Vary: Origin response header will also be included.
disableCacheoptionalbooleandisable_cacheoptionalbooldisableCacheoptionalBooleanDisableCacheoptionalboolDisableCacheoptional*bool #Default: cache is enabled
This option cannot be used with maxAge.
exposeHeadersoptionalstring[]expose_headersoptionaltyping.List[str]exposeHeadersoptionalList<String>ExposeHeadersoptionalstring[]ExposeHeadersoptional*[]*string #Default: only the 6 CORS-safelisted response headers are exposed: Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, Pragma
If you want clients to be able to access other headers, you have to list them using the Access-Control-Expose-Headers header.
maxAgeoptionalDurationmax_ageoptionalDurationmaxAgeoptionalDurationMaxAgeoptionalDurationMaxAgeoptionalDuration #Default: browser-specific (see reference)
To disable caching altogether use disableCache: true.
statusCodeoptionalnumberstatus_codeoptionalint | floatstatusCodeoptionalNumberStatusCodeoptionaldoubleStatusCodeoptional*float64 = 204 #