在API Gateway中进行配置,添加“Access-Control-Allow-Origin”头部信息。
可以通过以下示例代码实现:
app.options('/path/to/your/resource', function(req, res) { res.header('Access-Control-Allow-Origin', '*'); res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'); res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With'); res.send(200); });
"responseParameters":{ "method.response.header.Access-Control-Allow-Headers":"'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Requested-With'", "method.response.header.Access-Control-Allow-Origin":"'YOUR_ORIGIN'" },
记得将YOUR_ORIGIN替换成你的origin。
完成后,再重新测试API就可以通过了。
上一篇:AWSAPIGateway路由请求到$default而不是路由
下一篇:AWSAPIGatewayMockIntegration不接受Content-Type`application/vnd.nasa.cmr.umm+json;version=1.6.3`。