云端点处理程序被CORS阻止的SSL重定向
问题描述:
我希望我的Cloud Endpoints API可以使用HTTPS进行调用。我app.yaml
文件包含以下内容:云端点处理程序被CORS阻止的SSL重定向
# The endpoints handler must be mapped to /_ah/api.
- url: /_ah/api/.*
script: main.api
secure: always
如果一个客户端(即网站),使不安全的(HTTP)调用端点URL,App Engine的执行重定向到安全版本(HTTPS)
对于例如,假设我的应用程序引擎应用程序是在http://api.endpoints.my-app.appspot.com
和用于制造HTTP GET请求方法的mymethod
API端点是:
http://api.endpoints.my-app.appspot.com/_ah/api/myapp/v1/mymethod
App引擎重定向到HTTP 小号版本:
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 - 这正是我正在使用的。所以我不确定这是甚么问题。
答
您应该可以在app.yml
中配置Access-Control-Allow-Origin
标头。对于你的情况,请尝试以下的app.yml
文件:
handlers:
- url: /_ah/api/.*
script: main.api
secure: always
http_headers:
Access-Control-Allow-Origin: http://localhost:4000
更多阅读: