Skip to content

Commit

Permalink
Merge pull request #3 from Galactica-corp/feature/indexer-reconnect
Browse files Browse the repository at this point in the history
Add CORS headers
  • Loading branch information
yakud authored May 8, 2024
2 parents 2f739ef + ab120d2 commit 53e7786
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/query/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
"github.com/swaggest/swgui/v5cdn"
"google.golang.org/grpc"
"google.golang.org/protobuf/proto"

merklegen "github.com/Galactica-corp/merkle-proof-service/gen/galactica/merkle"
merkleswagger "github.com/Galactica-corp/merkle-proof-service/gen/openapiv2/galactica/merkle"
Expand Down Expand Up @@ -106,7 +107,18 @@ func (s *Server) RunGateway(ctx context.Context, address string) error {

gwmux := runtime.NewServeMux(
runtime.WithIncomingHeaderMatcher(runtime.DefaultHeaderMatcher),

// CORS middleware for all requests
runtime.WithForwardResponseOption(func(ctx context.Context, w http.ResponseWriter, msg proto.Message) error {
header := w.Header()
header.Set("Access-Control-Allow-Origin", "*")
header.Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
header.Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Request-ID, X-Client-ID")

return nil
}),
)

if err := merklegen.RegisterQueryHandlerServer(ctx, gwmux, s); err != nil {
return fmt.Errorf("failed to register gRPC gateway: %v", err)
}
Expand Down

0 comments on commit 53e7786

Please sign in to comment.