I'm learning about gRPC-Web and saw Traefik recently added GrpcWeb Middleware.
I've attempted to make a minimal project trying it out using a combination of Traefik and protobuf-ts here:
However I can't seem to get it to work.
Traefik says:
500 Internal Server Error error="stream error: stream ID 3; PROTOCOL_ERROR; received from peer"
and the frontend (browser) says:
Access to fetch at 'http://mooncar.docker.localhost/helloworld.Greeter/SayHello' from origin 'http://localhost:5173' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
grpc-web-transport.js:123 POST http://mooncar.docker.localhost/helloworld.Greeter/SayHello net::ERR_FAILED
helloworld.ts:18 RpcError: Failed to fetch
at grpc-web-transport.js:183:25
The docker-compose file looks like this:
version: '3'
services:
reverse-proxy:
image: traefik:v3.0.0-beta2
command: --api.insecure=true --providers.docker --log.level=DEBUG
ports:
- "80:80"
- "8080:8080" # The Web UI (enabled by --api.insecure=true)
volumes:
- /var/run/docker.sock:/var/run/docker.sock
mooncar:
build:
context: .
dockerfile: docker/backend.dockerfile
ports:
- "50051:50051"
labels:
- "traefik.enable=true"
- "traefik.http.routers.mooncar.rule=Host(`mooncar.docker.localhost`)"
- "traefik.http.services.mooncar.loadbalancer.server.scheme=h2c"
- "traefik.http.middlewares.mooncar.grpcweb.allowOrigins=*"
The gRPC server works fine through traefik, but when I try with the grpc-web-transport
it seems to hit a blocker and I'm not sure how to verify the grpc-web middleware works as expected.
Any one have some thoughts on how to go about this?
Thanks!