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

本文介绍了尝试从新的 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天全站免登陆