traefik/pkg/middlewares/grpcweb/grpcweb.go

27 lines
734 B
Go
Raw Normal View History

package grpcweb
import (
"context"
"net/http"
"github.com/traefik/grpc-web/go/grpcweb"
2023-02-03 14:24:05 +00:00
"github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/middlewares"
)
const typeName = "grpc-web"
// New builds a new gRPC web request converter.
func New(ctx context.Context, next http.Handler, config dynamic.GrpcWeb, name string) http.Handler {
2022-11-21 17:36:05 +00:00
middlewares.GetLogger(ctx, name, typeName).Debug().Msg("Creating middleware")
return grpcweb.WrapHandler(next, grpcweb.WithCorsForRegisteredEndpointsOnly(false), grpcweb.WithOriginFunc(func(origin string) bool {
for _, originCfg := range config.AllowOrigins {
if originCfg == "*" || originCfg == origin {
return true
}
}
return false
}))
}