【发布时间】:2021-10-22 09:21:02
【问题描述】:
我的 API 网关有以下 CDK 代码
this.restAPI = new RestApi(this, name, {
cloudWatchRole: true,
domainName: {
domainName: props.recordName,
certificate: props.cert,
endpointType: EndpointType.REGIONAL,
securityPolicy: SecurityPolicy.TLS_1_2
},
defaultCorsPreflightOptions: {
allowOrigins: Cors.ALL_ORIGINS,
allowMethods: ['OPTIONS', 'POST', 'GET', 'DELETE', 'PUT', 'PATCH'],
allowHeaders: Cors.DEFAULT_HEADERS,
maxAge: Duration.seconds(86400)
}
});
导致这个
但我仍然遇到这个错误:
/#/actors:1 Access to fetch at 'https://web-api.alpha.myapp.com/api/v1/actors?page=1' from origin 'https://alpha.myapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
但是,如果您查看我的 Access-Control-Allow-Origin,它设置为“*”。所以我不确定我错过了什么。
【问题讨论】:
-
UI 中的值用单引号括起来有什么原因吗?它们是由 CDK 生成的吗?您可以尝试删除它们,然后看看会发生什么?
-
CDK 就是这么干的。
标签: api cors aws-api-gateway aws-cdk