小编Swa*_*nil的帖子

在Google App Engine上为Django应用程序启用CORS

我一直在尝试在Google应用引擎上启用CORS标头,但我在互联网上找到的方法都不适合我.

我的应用程序是在Python/Django上,我希望我的前端应用程序(单独托管)能够在Google App Engine上对我的后端平台进行API调用.

2017年1月发行说明说明了这一点

我们正在改变可扩展服务代理(ESP)的行为以默认拒绝跨源资源共享(CORS)请求

这里可以看到

并且启用它们提供的CORS的解决方案是将以下片段添加到服务的OpenAPI配置中.

"host": "echo-api.endpoints.YOUR_PROJECT_ID.cloud.goog",
"x-google-endpoints": [
    {
      "name": "echo-api.endpoints.YOUR_PROJECT_ID.cloud.goog",
      "allowCors": "true"
    }
 ],
...
Run Code Online (Sandbox Code Playgroud)

所以我按照这个例子在我的代码库中创建了两个文件

openapi.yml:

swagger: "2.0"
info:
  description: "Google Cloud Endpoints APIs"
  title: "APIs"
  version: "1.0.0"
host: "echo-api.endpoints.<PROJECT-ID>.cloud.goog"  
x-google-endpoints:
 - name: "echo-api.endpoints.<PROJECT-ID>.cloud.goog"
   allowCors: "true"
paths:
  "/api/v1/sign-up":
    post:
      description: "Sends an email for verfication"
      operationId: "signup"
      produces:
      - "application/json"
      responses:
        200:
          description: "OK"
      parameters:
      - description: "Email address of the user"
        in: body
        name: email
        required: true
        schema:
          type: string …
Run Code Online (Sandbox Code Playgroud)

django google-app-engine nginx cors

8
推荐指数
1
解决办法
937
查看次数

标签 统计

cors ×1

django ×1

google-app-engine ×1

nginx ×1