Skip to content

Commit 1325e13

Browse files
authored
feat(server): remove h2c for cloudrun grpc [VIZ-1734] (#1649)
1 parent 1318736 commit 1325e13

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

server/internal/app/server.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package app
33
import (
44
"context"
55
"net"
6-
"net/http"
76
"os"
87
"os/signal"
98

@@ -15,7 +14,6 @@ import (
1514
"github.com/reearth/reearthx/account/accountusecase/accountrepo"
1615
"github.com/reearth/reearthx/log"
1716
"golang.org/x/net/http2"
18-
"golang.org/x/net/http2/h2c"
1917
"google.golang.org/grpc"
2018
)
2119

@@ -86,22 +84,21 @@ func (w *WebServer) Run(ctx context.Context) {
8684

8785
if w.internalServer != nil {
8886
go func() {
89-
handler := h2c.NewHandler(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
90-
if r.ProtoMajor == 2 && r.Header.Get("Content-Type") == "application/grpc" {
91-
w.internalServer.ServeHTTP(rw, r)
92-
}
93-
}), &http2.Server{})
94-
if err := http.ListenAndServe(w.internalPort, handler); err != nil {
95-
log.Fatalf("ListenAndServe failed: %v", err)
87+
lis, err := net.Listen("tcp", w.internalPort) // e.g. ":8080"
88+
if err != nil {
89+
log.Fatalf("failed to listen: %v", err)
90+
}
91+
log.Infof("server: started internal grpc server at %s", w.internalPort)
92+
if err := w.internalServer.Serve(lis); err != nil {
93+
log.Fatalf("failed to serve gRPC: %v", err)
9694
}
9795
}()
98-
log.Infof("server: started internal grpc server at %d", w.internalPort)
9996
} else {
10097
go func() {
101-
err := w.appServer.StartH2CServer(w.address, &http2.Server{})
98+
err := w.appServer.StartH2CServer(w.address, &http2.Server{}) // Echo fallback
10299
log.Fatalc(ctx, err.Error())
103100
}()
104-
log.Infof("server: started%s at http://%s", debugLog, w.address)
101+
log.Infof("server: echo api started%s at http://%s", debugLog, w.address)
105102
}
106103

107104
quit := make(chan os.Signal, 1)

0 commit comments

Comments
 (0)