我有这个创建 http api 的代码,但是 cors 配置不起作用,即使它在部署后在控制台中正确显示。我仍然可以从邮递员发送请求并在 api 后面执行 lambda,考虑到这种 cors 配置,这不应该发生。
const someApiDomain = new apigateway.DomainName(this, 'mydomain', {
domainName: 'api.example.com',
endpointType: apigateway.EndpointType.REGIONAL,
certificate: someCert
})
const httpApi = new apigateway.HttpApi(this, 'my-api', {
apiName: `my-api`,
createDefaultStage: true,
disableExecuteApiEndpoint: true,
defaultDomainMapping: {
domainName: someApiDomain
},
corsPreflight: {
allowHeaders: [
'Content-Type',
'X-Amz-Date'
],
allowMethods: [
apigateway.CorsHttpMethod.OPTIONS,
apigateway.CorsHttpMethod.POST,
],
allowCredentials: false,
allowOrigins: ['https://example.com']
},
});
httpApi.addRoutes({
methods: [apigateway.HttpMethod.POST],
path: '/myapi',
integration: new apigatewayintegrations.LambdaProxyIntegration({
handler: myFunction,
}),
});
new route53.ARecord(this, 'myapirecord', {
zone: someHostedZone,
recordName: 'api.example.com',
target: route53.RecordTarget.fromAlias(
new route53targets.ApiGatewayv2DomainProperties(someApiDomain.regionalDomainName, someApiDomain.regionalHostedZoneId)
),
});
route53 记录是否在这里绕过了某些东西?