问题描述
我正在运行K8s集群,并通过企业服务代理来提供gRPC服务,该服务同时通过HTTPS来提供gRPC和REST.
I'm running a K8s cluster, serving a gRPC service with an Enterprise Service Proxy serving both gRPC and REST over HTTPS.
我正在尝试为此端点启用CORS,但无法使其正常工作.
I'm trying to enable CORS for this endpoint, but I can't get it working.
这是我的端点配置:
...
endpoints:
- name: <my-service>.endpoints.<my-project>.cloud.goog
target: <ENDPOINT_IP>
allow_cors: true
我已经更新了端点并更新了ESP配置.我已经确认/etc/nginx.d/service.json
中有一个部分,或者包含有关启用CORS的内容.
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.
但是,当我向端点发出OPTIONS请求时,我会收到错误消息The service does not allow CORS traffic.
However, when I issue an OPTIONS request to my endpoint, I get back the error message The service does not allow CORS traffic.
我没主意了.有人知道我如何为端点启用CORS吗?
I'm out of ideas. Does anyone know how I can enable CORS for my endpoint?
推荐答案
不幸的是,allow_cors
表示ESP只会将OPTIONS请求传递给后端.尽管gRPC服务器不支持OPTIONS请求,所以它将无法工作.对此有解决方法,请参见 https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/google-cloud-endpoints/THvCfetfzW8/luyH3tOUBgAJ
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, seehttps://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/google-cloud-endpoints/THvCfetfzW8/luyH3tOUBgAJ
这篇关于无法让CORS在Google Endpoints ESP上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!