From 399534aa2875f9976ec1e0986645e89ab9ec3b55 Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Tue, 22 Oct 2024 13:58:59 -0400 Subject: [PATCH] disable cors --- core/ginhelper/server.go | 20 +++++++++++++------- services/omnirpc/cmd/cmd.go | 1 + 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/core/ginhelper/server.go b/core/ginhelper/server.go index 3658296298..bdad5a10cf 100644 --- a/core/ginhelper/server.go +++ b/core/ginhelper/server.go @@ -85,18 +85,24 @@ func NewWithExperimentalLogger(ctx context.Context, logger logger.ExperimentalLo return server } +// TODO: this is an anti-pattern and needs to be replaced by an option asap. +var CorsEnabled = true + func newBase() *gin.Engine { server := gin.New() // required for opentracing. server.ContextWithFallback = true - server.Use(helmet.Default()) + server.Use(gin.Recovery()) - server.Use(cors.New(cors.Config{ - AllowAllOrigins: true, - AllowHeaders: []string{"*"}, - AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodPatch, http.MethodDelete, http.MethodOptions}, - MaxAge: 12 * time.Hour, - })) + if CorsEnabled { + server.Use(helmet.Default()) + server.Use(cors.New(cors.Config{ + AllowAllOrigins: true, + AllowHeaders: []string{"*"}, + AllowMethods: []string{http.MethodGet, http.MethodPut, http.MethodPost, http.MethodPatch, http.MethodDelete, http.MethodOptions}, + MaxAge: 12 * time.Hour, + })) + } // configure the request id server.Use(requestid.New( diff --git a/services/omnirpc/cmd/cmd.go b/services/omnirpc/cmd/cmd.go index 66e084b3f9..a0a548bba5 100644 --- a/services/omnirpc/cmd/cmd.go +++ b/services/omnirpc/cmd/cmd.go @@ -12,6 +12,7 @@ import ( // Start starts the command line. func Start(args []string, buildInfo config.BuildInfo) { app := cli.NewApp() + app.Name = buildInfo.Name() app.Version = buildInfo.Version() app.Usage = fmt.Sprintf("%s --help", buildInfo.Name())