jbrown
jbrown

Reputation: 7986

Can't get CORS working on a Google Endpoints ESP

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?

Upvotes: 1

Views: 1171

Answers (2)

Davide Consonni
Davide Consonni

Reputation: 2124

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

Upvotes: 0

lizan
lizan

Reputation: 71

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

Upvotes: 1

Related Questions