1 個回答
- 最新
- 最多得票
- 最多評論
0
Based off of this reference to the CDK interface MethodOptions, I believe you could update the mapping template of the OPTIONS by using the addMethod function on the resource and specifying the OPTIONS method. In the integration parameter of this function, you can specify the requestTemplates property to define the mapping templates for the OPTIONS method. Here's an example:
contentResource.addMethod('OPTIONS', new apigateway.MockIntegration({
integrationResponses: [{
statusCode: '200',
responseParameters: {
'method.response.header.Access-Control-Allow-Headers': "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'",
'method.response.header.Access-Control-Allow-Origin': "'*'",
'method.response.header.Access-Control-Allow-Methods': "'OPTIONS,GET,PUT'"
}
}],
passthroughBehavior: apigateway.PassthroughBehavior.NEVER,
requestTemplates: {
"application/json": "{\"statusCode\": 200}"
}
}), {
methodResponses: [{
statusCode: '200',
responseParameters: {
'method.response.header.Access-Control-Allow-Headers': true,
'method.response.header.Access-Control-Allow-Methods': true,
'method.response.header.Access-Control-Allow-Origin': true,
}
}]
});
Hope this helps!
-Zac
已回答 1 年前
相關內容
- 已提問 10 個月前
- AWS 官方已更新 2 年前
- AWS 官方已更新 10 個月前
- AWS 官方已更新 1 年前
Hello Zac
Thanks for your response. I have tried this approach before, however when I build the app using
npm run build
and then runcdk synth
, this throws errorError: There is already a Construct with name 'OPTIONS' in Resource [{content}]
. It seems there is already anOPTIONS
method defined by default.Do you think removing the
defaultCorsPreflightOptions
in RestApi definition and then adding this sectionaddMethod('OPTIONS',...
would work?