Add CORS support for gRPC-Web on the frontend gRPC server
Author: killme2008Created Sep 24, 2026Updated Sep 24, 2026
LabelsC-enhancementgood first issue
What type of enhancement is this?
API improvement, Configuration
What does the enhancement do?
gRPC-Web was added to the frontend gRPC server in #8027, but browsers still can't call it cross-origin because there is no CORS handling. tonic_web::GrpcWebLayer (0.14) doesn't answer preflights itself; its docs expect a tower_http::cors::CorsLayer on top.
Repro on v1.2.1:
# gRPC-Web itself works
$ printf '\x00\x00\x00\x00\x00' | curl -s --http1.1 -i -X POST \
http://127.0.0.1:4001/greptime.v1.HealthCheck/HealthCheck \
-H 'content-type: application/grpc-web+proto' -H 'x-grpc-web: 1' \
-H 'Origin: http://example.com' --data-binary @-
HTTP/1.1 200 OK
content-type: application/grpc-web+proto
...
# the browser preflight fails
$ curl -s --http1.1 -i -X OPTIONS \
http://127.0.0.1:4001/greptime.v1.GreptimeDatabase/Handle \
-H 'Origin: http://example.com' \
-H 'Access-Control-Request-Method: POST' \
-H 'Access-Control-Request-Headers: content-type,x-grpc-web'
HTTP/1.1 400 Bad Request
content-length: 0No Access-Control-Allow-* headers come back on either request. Non-browser fetch runtimes (Workers, edge) work fine; browser clients need this. It blocks GreptimeTeam/greptimedb-ingester-ts#8.
Implementation challenges
The HTTP server already has this, so mirror it:
- Add
enable_corsandcors_allowed_originstoGrpcOptions(src/servers/src/grpc.rs), same semantics as the HTTP ones (src/servers/src/http.rs,HttpOptions). - In
GrpcServer::start, add aCorsLayernext toGrpcWebLayer. See how the HTTP server builds it aroundhttp.rs:1053. - gRPC-Web needs a bit more than the HTTP config:
- allow method
POST(plus theOPTIONSpreflight); - allow headers:
content-type,x-grpc-web,x-user-agent,grpc-timeout,authorization,x-greptime-hints(or justAny, like HTTP); - expose headers:
grpc-status,grpc-message,grpc-status-details-bin, otherwise the browser client can't read the call status.
- allow method
- Add the new options to
config/config.mdand the example config files. - Test: an OPTIONS preflight gets 2xx with the right
Access-Control-Allow-*headers, and a disallowed origin is rejected whencors_allowed_originsis set.
Open question for the reviewer: default on (matches HTTP) or off for gRPC.
Source: GreptimeTeam/greptimedb