尝试从新的Google Cloud API网关中获取时发生CORS错误 [英] CORS errors when trying to fetch from new Google Cloud API Gateway

查看:100
本文介绍了尝试从新的Google Cloud API网关中获取时发生CORS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试新的API网关,以确保我的React应用程序具有云功能.到目前为止,这个过程比以前的替代方案要好得多,但是当我尝试从我的React应用程序访问我的API网关时,我当前遇到了CORS错误.我在Cloud Function中正确设置了CORS标头,但是我不知道在API Gateway端点上执行相同操作的方式.我正在使用Postman来测试对网关端点的请求,并且一切都很好,所以就在我从我的React应用程序发出请求时.

I was testing out the new API Gateway to secure a cloud function for my React application. So far the process has been much nicer than the previous alternatives, but I am currently getting CORS errors when trying to reach out to my API Gateway from my React app. I am setting the CORS headers correctly in my Cloud Function, but I have no known way of doing the same on the API Gateway endpoint. I am using Postman to test a request to the gateway endpoint and everything is working great, so it is just when I request from my React app.

错误:从来源"https://example.netlify.app"访问"https://my-gateway-a12bcd345e67f89g0h.uc.gateway.dev/hello?key=example"的访问已被阻止通过CORS策略:对预检请求的响应未通过访问控制检查:在所请求的资源上不存在"Access-Control-Allow-Origin"标头.如果不透明的响应满足您的需求,请将请求的模式设置为"no-cors",以在禁用CORS的情况下获取资源."

Error: "Access to fetch at 'https://my-gateway-a12bcd345e67f89g0h.uc.gateway.dev/hello?key=example' from origin 'https://example.netlify.app' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: 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."

希望您能对此问题有所了解.谢谢!

Would love some insight into this issue. Thanks!

推荐答案

结果表明API Gateway当前不支持CORS.

Turns out that API Gateway does not currently have CORS support.

参考.

这篇关于尝试从新的Google Cloud API网关中获取时发生CORS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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