Enable grpc-web CORS origin checking
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
cf90100c5f
commit
bff15098e6
|
@ -2,6 +2,12 @@ CLIPPER_ENV=development # or production
|
||||||
|
|
||||||
CLIPPER_BIND_ADDR=localhost:8888
|
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.
|
# PostgreSQL connection string.
|
||||||
CLIPPER_DATABASE_URL=
|
CLIPPER_DATABASE_URL=
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,16 @@ func Start(options Options) error {
|
||||||
mediaSetController := &mediaSetServiceController{mediaSetService: mediaSetService, logger: options.Logger.Sugar().Named("controller")}
|
mediaSetController := &mediaSetServiceController{mediaSetService: mediaSetService, logger: options.Logger.Sugar().Named("controller")}
|
||||||
pbmediaset.RegisterMediaSetServiceServer(grpcServer, mediaSetController)
|
pbmediaset.RegisterMediaSetServiceServer(grpcServer, mediaSetController)
|
||||||
|
|
||||||
// TODO: implement CORS headers
|
// TODO: convert CORSAllowedOrigins to a map[string]struct{}
|
||||||
grpcHandler := grpcweb.WrapServer(grpcServer, grpcweb.WithOriginFunc(func(string) bool { return true }))
|
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"))
|
httpHandler := newHTTPHandler(grpcHandler, mediaSetService, conf, options.Logger.Sugar().Named("httpHandler"))
|
||||||
|
|
||||||
httpServer := http.Server{
|
httpServer := http.Server{
|
||||||
|
|
Loading…
Reference in New Issue