Skip to content

Commit

Permalink
feat: adds support for websocket connections and cors (#204)
Browse files Browse the repository at this point in the history
Signed-off-by: Carson Farmer <[email protected]>
  • Loading branch information
carsonfarmer authored Jan 7, 2020
1 parent 0f80d0f commit 14ab402
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ func NewService(
}()

// Start a web RPC proxy
webrpc := grpcweb.WrapServer(t.rpc)
webrpc := grpcweb.WrapServer(
t.rpc,
grpcweb.WithOriginFunc(func(origin string) bool {
return true
}),
grpcweb.WithWebsockets(true),
grpcweb.WithWebsocketOriginFunc(func(req *http.Request) bool {
return true
}))
proxyAddr, err := util.TCPAddrFromMultiAddr(conf.ProxyAddr)
if err != nil {
return nil, err
Expand All @@ -124,7 +132,9 @@ func NewService(
Addr: proxyAddr,
}
t.proxy.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if webrpc.IsGrpcWebRequest(r) {
if webrpc.IsGrpcWebRequest(r) ||
webrpc.IsAcceptableGrpcCorsRequest(r) ||
webrpc.IsGrpcWebSocketRequest(r) {
webrpc.ServeHTTP(w, r)
}
})
Expand Down

0 comments on commit 14ab402

Please sign in to comment.