【发布时间】:2017-03-19 17:21:09
【问题描述】:
我希望使用 HTTPS 调用我的 Cloud Endpoints API。我的app.yaml 文件包含以下内容:
# The endpoints handler must be mapped to /_ah/api.
- url: /_ah/api/.*
script: main.api
secure: always
如果客户端(即网站)对端点 URL 进行不安全 (HTTP) 调用,App Engine 会重定向到安全版本 (HTTPS)
例如,假设我的 App Engine 应用位于 http://api.endpoints.my-app.appspot.com 并且用于向方法 mymethod 发出 HTTP GET 请求的 API 端点是:
http://api.endpoints.my-app.appspot.com/_ah/api/myapp/v1/mymethod
App Engine 重定向到 HTTPS 版本:
https://api.endpoints.my-app.appspot.com/_ah/api/myapp/v1/mymethod
但是,来自的重定向被阻止:
blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
如何将所需的标头添加到我的资源(即 App Engine 上的 Cloud Endpoints API)? Google 的文档指出,默认情况下,在 App Engine Standard 上启用了 CORS——这就是我正在使用的。所以我不确定为什么这甚至是一个问题。
【问题讨论】:
标签: google-app-engine cors google-cloud-endpoints