google-app-engine - 如何在 Google Cloud Endpoints 中允许 CORS?

标签 google-app-engine cors google-cloud-endpoints app-engine-flexible

January 2017 Endpoints release notes 中所述,我尝试通过添加 x-google-endpoints 来更新 openapi.yaml 文件,以阻止可扩展服务代理 (ESP) 阻止跨源请求:

swagger: "2.0"
info:
  description: "Market scan using technical indicators."
  title: "Talib Test"
  version: "1.0.0"
host: "YOUR-PROJECT-ID.appspot.com"
x-google-endpoints:
- name: "YOUR-PROJECT-ID.appspot.com"
  allowCors: "true"
basePath: "/"
consumes:
- "application/json"
produces:
- "application/json"
schemes:
- "http"
...

尝试从我的 Angular 应用程序进行 http 调用时,我继续在浏览器中收到错误。错误出现在开发人员模式下以及部署我的角度应用程序之后:

XMLHttpRequest cannot load
Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource.

当我查看 Google Cloud 日志记录时,我看到 requestMethod:"OPTIONS"status:200。 API 是 POST 方法,所以我猜测是 ESP 阻止了请求。另外,我已经使用 FLASK-CORS 在我的 python 应用程序中允许 CORS所以它应该可以工作。

我的应用程序有两项服务都位于 Google App Engine 上。首先是标准环境。我遇到的第二个问题是灵活的环境。我正在使用dispatch.yaml 文件和单独的openapi.yaml 文件(如果相关)。此外,该 API 适用于 hurl it和 postman 。

任何帮助都会很棒!

最佳答案

很可能您的后端应用程序没有正确处理 CORS 选项。 如果“allowCors”为 true,端点代理会将请求传递到您的后端应用程序。代理不会向请求添加任何内容。如果“allowCors”为 false,代理将返回 404。

关于google-app-engine - 如何在 Google Cloud Endpoints 中允许 CORS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45161311/

相关文章:

Spring,休眠与谷歌应用引擎

java - 在 App Engine 数据存储区查看器中编辑日期字段

jquery - 来自带有 CORS 的 jQuery ajax 的 Reddit API : No 'Access-Control-Allow-Origin' header is present on the requested resource

java - 严重 : Exception starting filter CORS

java - Google 教程中的这段 Java 代码在创建 Void 类型的变量时正确吗?

android - Gradle 中的并行任务未完成 (connectedAndroidTest)

google-app-engine - 如何在本地将 GAE 应用程序和 GCE 应用程序连接到同一数据存储区?

java - allocateIds DatastoreService 实际使用情况

java - netty 套接字 io CORS 错误 : Access-Control-Allow-Origin

google-app-engine - Google App Engine Cloud 端点,无 API