【发布时间】:2017-12-22 23:58:14
【问题描述】:
如January 2017 Endpoints release notes 中所述,我尝试更新我的 openapi.yaml 文件,以通过添加到 x-google-endpoints 来阻止可扩展服务代理 (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 调用时,浏览器中仍然出现错误。该错误出现在开发人员模式和部署我的 Angular 应用程序之后:
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 阻止了请求。此外,我已经在我的 python 应用程序中使用FLASK-CORS 允许 CORS,所以它应该可以工作。
我的应用程序有两个服务都在 Google App Engine 上。首先是标准环境。第二个,我遇到的问题是灵活的环境。如果相关,我正在使用 dispatch.yaml 文件和单独的 openapi.yaml 文件。此外,该 API 适用于 hurl it 和邮递员。
任何帮助都会很棒!
【问题讨论】:
标签: google-app-engine cors google-cloud-endpoints app-engine-flexible