1 Risposta
- Più recenti
- Maggior numero di voti
- Maggior numero di commenti
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
con risposta un anno fa
Contenuto pertinente
- AWS UFFICIALEAggiornata 3 anni fa
- AWS UFFICIALEAggiornata 2 anni fa
- AWS UFFICIALEAggiornata un anno fa
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?