Enable grpc-web CORS origin checking
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-01-27 20:40:33 +01:00
parent cf90100c5f
commit bff15098e6
2 changed files with 16 additions and 2 deletions

View File

@ -2,6 +2,12 @@ CLIPPER_ENV=development # or production
CLIPPER_BIND_ADDR=localhost:8888
# Required if serving grpc-web, assets, etc from a different hostname.
# Multiple domains can be separated with commas.
#
# Example: http://localhost:3000
CLIPPER_CORS_ALLOWED_ORIGINS=
# PostgreSQL connection string.
CLIPPER_DATABASE_URL=

View File

@ -99,8 +99,16 @@ func Start(options Options) error {
mediaSetController := &mediaSetServiceController{mediaSetService: mediaSetService, logger: options.Logger.Sugar().Named("controller")}
pbmediaset.RegisterMediaSetServiceServer(grpcServer, mediaSetController)
// TODO: implement CORS headers
grpcHandler := grpcweb.WrapServer(grpcServer, grpcweb.WithOriginFunc(func(string) bool { return true }))
// TODO: convert CORSAllowedOrigins to a map[string]struct{}
originChecker := func(origin string) bool {
for _, s := range conf.CORSAllowedOrigins {
if origin == s {
return true
}
}
return false
}
grpcHandler := grpcweb.WrapServer(grpcServer, grpcweb.WithOriginFunc(originChecker))
httpHandler := newHTTPHandler(grpcHandler, mediaSetService, conf, options.Logger.Sugar().Named("httpHandler"))
httpServer := http.Server{