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年前
関連するコンテンツ
- AWS公式更新しました 10ヶ月前
- AWS公式更新しました 2年前
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?