GCP App Engine Flex端点OpenAPI CORS

时间:2018-11-08 07:32:52

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

尝试将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: "******,******"

1 个答案:

答案 0 :(得分:0)

发送OPTIONS时使用什么路径? “ /”或“ / api /用户”?

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