Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: grpc-web add CORS handler #9493

Merged
merged 12 commits into from
Jun 16, 2021
11 changes: 10 additions & 1 deletion server/grpc/grpc_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ import (

// StartGRPCWeb starts a gRPC-Web server on the given address.
func StartGRPCWeb(grpcSrv *grpc.Server, config config.Config) (*http.Server, error) {
wrappedServer := grpcweb.WrapServer(grpcSrv)
var options []grpcweb.Option
if config.API.EnableUnsafeCORS {
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
options = append(options,
grpcweb.WithOriginFunc(func(origin string) bool {
return true
}),
)
}

wrappedServer := grpcweb.WrapServer(grpcSrv, options...)
handler := func(resp http.ResponseWriter, req *http.Request) {
wrappedServer.ServeHTTP(resp, req)
}
Expand Down