Skip to content

Commit

Permalink
Fix to allow CORS pre-flight requests to daemon, allow CORS requests to
Browse files Browse the repository at this point in the history
unregistered (unknown) gRPC services
  • Loading branch information
vforvalerio87 committed Nov 1, 2018
1 parent 9a1cc34 commit 0a717b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

[[constraint]]
name = "github.com/improbable-eng/grpc-web"
version = "0.6.2"
version = "0.6.3"

[[constraint]]
name = "github.com/sirupsen/logrus"
Expand Down
7 changes: 4 additions & 3 deletions snetd/cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,14 @@ func (d daemon) start() {
grpcL := mux.MatchWithWriters(cmux.HTTP2MatchHeaderFieldPrefixSendSettings("content-type", "application/grpc"))
httpL := mux.Match(cmux.HTTP1Fast())

grpcWebServer := grpcweb.WrapServer(d.grpcServer)
grpcWebServer := grpcweb.WrapServer(d.grpcServer, grpcweb.WithCorsForRegisteredEndpointsOnly(false))

httpHandler := http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
if grpcWebServer.IsGrpcWebRequest(req) {
if grpcWebServer.IsGrpcWebRequest(req) || grpcWebServer.IsAcceptableGrpcCorsRequest(req) {
grpcWebServer.ServeHTTP(resp, req)
} else {
if strings.Split(req.URL.Path, "/")[1] == "encoding" {
resp.Header().Set("Access-Control-Allow-Origin", "*")
fmt.Fprintln(resp, config.GetString(config.WireEncodingKey))
} else {
http.NotFound(resp, req)
Expand All @@ -181,7 +182,7 @@ func (d daemon) start() {
log.Debug("starting daemon")

go d.grpcServer.Serve(grpcL)
go http.Serve(httpL, handlers.CORS(corsOptions...)(httpHandler))
go http.Serve(httpL, httpHandler)
go mux.Serve()
} else {
log.Debug("starting simple HTTP daemon")
Expand Down

0 comments on commit 0a717b1

Please sign in to comment.