【发布时间】:2020-01-07 14:43:48
【问题描述】:
我在灵活环境中的 Appengine 中有一个 API。它不支持 CORS。我相信是因为它默认不支持它
After ESP 1.0 is released on January 2, 2017, all Flexible Environment API deployments will feature the new version of ESP and will automatically disallow CORS requests by default. App Engine applications are automatically redeployed every 7 days, so sometime in the 7 days following the release of ESP 1.0, your app will be restarted with the latest version and will automatically be protected from unintended cross origin sharing.
If you are using Flexible Environments and would like to continue to allow CORS requests, you must add the "x-google-endpoints" snippet above to your API configuration (aka OpenAPI specification aka Swagger file). If you are relying on CORS, we recommend that you add the snippet as soon as possible and redeploy your service using the following command to avoid service interruption. Then you will not see changed behavior when the new version of ESP rolls out.
这个页面告诉我设置 allowCors = True 并在我的后端代码中实现支持(它们是指我的 main.go 吗?) https://cloud.google.com/endpoints/docs/openapi/openapi-extensions
此页面告诉我向我的 ESP 添加一些代码,但我不确定它的含义 - 在我的 openapi swagger 文件中? https://cloud.google.com/endpoints/docs/openapi/specify-proxy-startup-options#adding_cors_support_to_esp
本页https://enable-cors.org/server_appengine.html 告诉我添加这段代码,我假设我的 main.go,但这意味着什么?
func doGet(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Header().Add("Content-Type", "text/csv")
fmt.Fprintf(w, csvData)
}
我正在努力寻找直接的步骤来为我的 AppEngine API 上的一个网站启用 CORS 支持。有人可以支持吗?
谢谢:)
【问题讨论】:
标签: rest api google-cloud-platform cors yaml