Skip to content

Commit

Permalink
make /api/ h2c compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
therealak12 authored and geakstr committed Jul 24, 2023
1 parent 0a6ed74 commit 4b35b3d
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 2 deletions.
2 changes: 1 addition & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/improbable-eng/grpc-web v0.15.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
golang.org/x/net v0.9.0
golang.org/x/sys v0.10.0
google.golang.org/grpc v1.56.2
google.golang.org/protobuf v1.31.0
Expand Down Expand Up @@ -45,7 +46,6 @@ require (
github.com/rs/cors v1.7.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/spf13/pflag v1.0.6-0.20200504143853-81378bbcd8a1 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/term v0.7.0 // indirect
Expand Down
5 changes: 4 additions & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
gops "github.com/google/gops/agent"
"github.com/improbable-eng/grpc-web/go/grpcweb"
"github.com/sirupsen/logrus"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"golang.org/x/sys/unix"
"google.golang.org/grpc"

Expand Down Expand Up @@ -55,6 +57,7 @@ func runServer(cfg *config.Config) {
req.URL.Path = req.URL.Path[len("/api/"):]
wrappedGrpc.ServeHTTP(resp, req)
})
h2cHandler := h2c.NewHandler(handler, &http2.Server{})

ctx, cancel := signal.NotifyContext(context.Background(), unix.SIGINT, unix.SIGTERM)
defer cancel()
Expand All @@ -63,7 +66,7 @@ func runServer(cfg *config.Config) {

httpSrv := &http.Server{
Addr: addr,
Handler: handler,
Handler: h2cHandler,
BaseContext: func(net.Listener) context.Context {
return ctx
},
Expand Down
240 changes: 240 additions & 0 deletions backend/vendor/golang.org/x/net/http2/h2c/h2c.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ github.com/spf13/pflag
golang.org/x/net/context
golang.org/x/net/http/httpguts
golang.org/x/net/http2
golang.org/x/net/http2/h2c
golang.org/x/net/http2/hpack
golang.org/x/net/idna
golang.org/x/net/internal/timeseries
Expand Down

0 comments on commit 4b35b3d

Please sign in to comment.