Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optionally disable cors #3325

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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
Loading