grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.55k stars 762 forks source link

gRPC Web with Google Endpoint ESPv2? #1132

Open nsadeh opened 3 years ago

nsadeh commented 3 years ago

I’d like to use this in a Firebase app using Google Cloud Run for the backend. I don’t see any examples using ESPv2 Google Endpoint as a proxy, but based on the docs I think there’s a chance it might work. Does someone have experience with this?

sorry if the issues isn’t the place to ask for support, didn’t know where else to ask :)

ldaniluk commented 1 year ago

So late response but have just configured similar setup and maybe someone will google for help.

I am using GKE not Cloud Run, other than that it is Endpoints + ESPv2, with GRPC service backend, accessed both by grpc-web client and regular grpc clients.

For endpoints you can just roll with basic definition like "Bookstore" example in documentation for deploying GRPC service with Endpoints + ESPv2. Going through any guide will enable "normal" grpc access with HTTP2 clients.

For access from your browser you will want to enable CORS config with these options to ESPv2: --cors_preset=basic and, if you are using this lib, you will need to allow two more headers - X-Grpc-Web and X-User-Agent by extending basic preset headers. At the moment of writing this comment you should add this argument to ESPv2 setup: --cors_allow_headers=DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,X-User-Agent,X-Grpc-Web.

References: GRPC + GKE + ESPv2 guide https://cloud.google.com/endpoints/docs/grpc/get-started-kubernetes-engine-espv2

GRPC + Cloud Run + ESPv2 guide https://cloud.google.com/endpoints/docs/grpc/set-up-cloud-run-espv2

More CORS option if you encounter errors related to that are here: https://cloud.google.com/endpoints/docs/openapi/specify-esp-v2-startup-options#cors

djs-CS commented 9 months ago

I've been researching this as well recently. If you're primarily interested in using grpc-Web for your Cloud Run backend and don't care about the additional features offered by Cloud Endpoints, I'd recommend checking out Cloud Run sidecars and using them directly with Envoy. It's what ESPv2 uses under the hood and, from what I can tell, simplifies things significantly since it wouldn't require you to rebuild your proxy container every time your api changes as is the case with ESPv2 (see here).