API网关HTTP API CORS [英] API Gateway HTTP API CORS

查看:84
本文介绍了API网关HTTP API CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的API网关HTTP,它在配置过程中使您可以添加CORS.因此,我已将"*"设置为访问控制允许来源"标头.

I am using the new API Gateway HTTP which during the configuration enables you to add CORS. So I have set the Access-Control-Allow-Origin Header with the setting *.

但是,当我使用Postman发出请求时,看不到该标头,这导致我的VueJS Axios请求失败.

However when I make a request using Postman I do not see that header and this i causing my VueJS Axios request to fail.

我以前使用过Lambda代理集成,并在我的Lambda中进行了以下操作

I previously used a Lambda Proxy Integration and did the following in my Lambda

"headers": { 
            "Access-Control-Allow-Origin": "*" 
        }

但是,新的HTTP API似乎并没有实现CORS.也许我缺少一些简单的东西.

However the new HTTP API just does not seem to implement CORS. Maybe I am missing something simple.

-编辑-

因此,我一直在寻找答案,并且遇到了Serverless的那些设置以下内容的人的博客文章

So I have continue to find an answer and came across a blog post from the guys at Serverless who set the following

It’ll ensure following headers:

Access-Control-Allow-Origin: *
Access-Control-Allow-Headers:

Content-Type, X-Amz-Date, Authorization, X-Api-Key, X-Amz-Security-Token, X-Amz-User-Agent
Access-Control-Allow-Methods:

OPTIONS, and all the methods defined in your routes (GET, POST, etc.)

我已经尝试过并重新部署它们,但仍然只获得标准标头

I have tried these and redeployed and still only get the standard headers

谢谢

推荐答案

适用于使用HTTP API和代理路由的任何人 ANY/{proxy +}

For anyone using HTTP API and the proxy route ANY /{proxy+}

您需要显式定义路由方法,以便CORS正常工作.

You will need to explicitly define your route methods in order for CORS to work.

希望这在 AWS文档中更明确为HTTP API配置CORS

在与AWS Support进行了2小时的通话后,他们与一位提出此建议的高级HTTP API开发人员进行了交流.

Was on a 2 hour call with AWS Support and they looped in one of their senior HTTP API developers, who made this recommendation.

希望这篇文章可以节省一些人的时间和精力.

Hopefully this post can save some people some time and effort.

这篇关于API网关HTTP API CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆