Skip to content

Commit

Permalink
optionally disable cors (#3325)
Browse files Browse the repository at this point in the history
Co-authored-by: Trajan0x <[email protected]>
  • Loading branch information
trajan0x and trajan0x authored Oct 22, 2024
1 parent a813e05 commit 0651118
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
20 changes: 13 additions & 7 deletions core/ginhelper/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Check failure on line 88 in core/ginhelper/server.go

View workflow job for this annotation

GitHub Actions / Lint (core)

exported: comment on exported var CorsEnabled should be of the form "CorsEnabled ..." (revive)
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(
Expand Down
1 change: 1 addition & 0 deletions services/omnirpc/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 0651118

Please sign in to comment.