【问题标题】:Gcp app engine flex endpoints openapi CORSGcp 应用引擎 flex 端点 openapi CORS
【发布时间】:2018-11-08 07:32:51
【问题描述】:

尝试向服务器发送 OPTIONS 时出错。 错误:

{
    "code": 7,
    "message": "The service does not allow CORS traffic.",
    "details": [
        {
            "@type": "type.googleapis.com/google.rpc.DebugInfo",
            "stackEntries": [],
            "detail": "service_control"
        }
    ]
}

如果我发送 GET 请求(通过邮递员),我会得到正常响应。

节点服务器使用启用了 cors 的 KOA.js

app.use(cors());

它可以在没有端点的情况下工作,所以我认为服务器不会有问题。

app.yaml

runtime: nodejs
env: flex

env_variables:
  NODE_ENV: "dev"

handlers:
- url: /
  static_dir: /
  http_headers:
    Access-Control-Allow-Origin: '*'

endpoints_api_service:
  name: ******.appspot.com
  rollout_strategy: managed

openapi-appengine.yaml

swagger: "2.0"
info:
  description: "A simple Google Cloud Endpoints API example."
  title: "Endpoints Example"
  version: "1.0.0"
host: "******.appspot.com"
x-google-endpoints:
- name: "******.appspot.com"
  allowCors: "true"
x-google-allow: all

paths:
  /api/user:
    get:
      operationId: "getcurrentuser"
      produces:
      - "application/json"
      parameters: []
      responses:
        200:
          description: "successful operation"
          schema:
            type: "object"
      security:
      - firebase: []

securityDefinitions:
  firebase:
    authorizationUrl: ""
    flow: "implicit"
    type: "oauth2"
    x-google-issuer: "https://securetoken.google.com/******"
    x-google-jwks_uri: "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken@system.gserviceaccount.com"
    x-google-audiences: "******,******"

【问题讨论】:

  • 您找到解决方案了吗?
  • @FrancescoClementi 是的,我在“x-google-audiences”中添加了错误的数据。

标签: firebase google-app-engine cors google-cloud-endpoints


【解决方案1】:

您在发送 OPTIONS 时使用了什么路径? “/”还是“/api/user”?

在您的 Swagger 中,您只需设置“/api/user”路径,因此 OPTIONS 仅适用于该路径。

【讨论】:

  • 欢迎来到 Stack Overflow。这不是问题的答案,而是更多的评论。请查看How to Answer 以了解何时提供答案以及何时添加评论。
猜你喜欢
  • 2017-05-14
  • 1970-01-01
  • 1970-01-01
  • 2013-04-03
  • 2016-11-28
  • 2023-04-06
  • 1970-01-01
  • 2019-03-12
  • 2019-05-11
相关资源
最近更新 更多