Can't get CORS working on a Google Endpoints ESP

泄露秘密 提交于 2019-12-11 04:49:50

问题


I'm running a K8s cluster, serving a gRPC service with an Enterprise Service Proxy serving both gRPC and REST over HTTPS.

I'm trying to enable CORS for this endpoint, but I can't get it working.

Here's my endpoint config:

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

I've updated the endpoint and updated the ESP config. I've confirmed that there's a section in /etc/nginx.d/service.json or something that contains something about CORS being enabled.

However, when I issue an OPTIONS request to my endpoint, I get back the error message The service does not allow CORS traffic.

I'm out of ideas. Does anyone know how I can enable CORS for my endpoint?


回答1:


Unfortunately, allow_cors means ESP will just pass-through the OPTIONS request to the backend. While gRPC server doesn't support OPTIONS requests, so it won't work. There is workaround on this, see https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/google-cloud-endpoints/THvCfetfzW8/luyH3tOUBgAJ




回答2:


Remember to enable CORS on ESP using --cors_preset=basic

Example:

    - 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",
      ]

see the Google Documentation: https://cloud.google.com/endpoints/docs/openapi/specify-proxy-startup-options#adding_cors_support_to_esp



来源:https://stackoverflow.com/questions/44930576/cant-get-cors-working-on-a-google-endpoints-esp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!