From a09c66986537ca98287950e736ebeb5df7d4fe0b Mon Sep 17 00:00:00 2001 From: Ryo <36154873+RyoJerryYu@users.noreply.github.com> Date: Fri, 21 Jun 2024 18:13:59 +0800 Subject: [PATCH] fix: allow cors for grpc gateway handler (#3574) --- server/router/api/v1/v1.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/server/router/api/v1/v1.go b/server/router/api/v1/v1.go index a7b098d4..3170438a 100644 --- a/server/router/api/v1/v1.go +++ b/server/router/api/v1/v1.go @@ -7,6 +7,7 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" "github.com/improbable-eng/grpc-web/go/grpcweb" "github.com/labstack/echo/v4" + "github.com/labstack/echo/v4/middleware" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/reflection" @@ -104,8 +105,12 @@ func (s *APIV1Service) RegisterGateway(ctx context.Context, echoServer *echo.Ech if err := v1pb.RegisterIdentityProviderServiceHandler(ctx, gwMux, conn); err != nil { return err } - echoServer.Any("/api/v1/*", echo.WrapHandler(gwMux)) - echoServer.Any("/file/*", echo.WrapHandler(gwMux)) + gwGroup := echoServer.Group("") + gwGroup.Use(middleware.CORS()) + handler := echo.WrapHandler(gwMux) + + gwGroup.Any("/api/v1/*", handler) + gwGroup.Any("/file/*", handler) // GRPC web proxy. options := []grpcweb.Option{