【问题标题】:Can't get CORS working on a Google Endpoints ESP无法让 CORS 在 Google Endpoints ESP 上运行
【发布时间】:2017-07-05 15:35:43
【问题描述】:

我正在运行一个 K8s 集群,通过企业服务代理提供 gRPC 服务,同时通过 HTTPS 服务 gRPC 和 REST。

我正在尝试为此端点启用 CORS,但无法使其正常工作。

这是我的端点配置:

...
endpoints:
- name: <my-service>.endpoints.<my-project>.cloud.goog
  target: <ENDPOINT_IP>
  allow_cors: true

我已经更新了端点并更新了 ESP 配置。我已确认 /etc/nginx.d/service.json 中有一个部分或包含有关启用 CORS 的内容。

但是,当我向端点发出 OPTIONS 请求时,我会收到错误消息 The service does not allow CORS traffic.

我没有想法。有谁知道如何为我的端点启用 CORS?

【问题讨论】:

    标签: google-cloud-platform google-cloud-endpoints


    【解决方案1】:

    不幸的是,allow_cors 意味着 ESP 只会将 OPTIONS 请求传递到后端。虽然 gRPC 服务器不支持 OPTIONS 请求,但它不起作用。对此有解决方法,请参阅 https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/google-cloud-endpoints/THvCfetfzW8/luyH3tOUBgAJ

    【讨论】:

      【解决方案2】:

      记得使用 --cors_preset=basic 在 ESP 上启用 CORS

      例子:

          - name: esp
            image: gcr.io/endpoints-release/endpoints-runtime:1
            args: [
              "--http_port=8081",
              "--backend=127.0.0.1:8080",
              "--service=...",
              "--rollout_strategy=managed",
              "--cors_preset=basic",
            ]
      

      请参阅 Google 文档:https://cloud.google.com/endpoints/docs/openapi/specify-proxy-startup-options#adding_cors_support_to_esp

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-18
        • 2011-03-09
        • 2023-03-13
        • 2020-01-02
        • 2017-02-19
        • 2018-07-06
        • 2017-12-22
        • 2020-02-17
        相关资源
        最近更新 更多