Skip to content

Commit

Permalink
chore: remove tailing slash from CORS config. Closes #1735 (#1737)
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Wang <[email protected]>
  • Loading branch information
whynowy authored May 21, 2024
1 parent 8913e1c commit 52d839d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion server/cmd/server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,17 @@ func (s *server) Start(ctx context.Context) {
log := logging.FromContext(ctx)
router := gin.New()
router.Use(gin.LoggerWithConfig(gin.LoggerConfig{SkipPaths: []string{"/livez"}}))
allowedOrigins := make([]string, 0)
if s.options.CorsAllowedOrigins != "" {
allowedOrigins := strings.Split(s.options.CorsAllowedOrigins, ",")
for _, o := range strings.Split(s.options.CorsAllowedOrigins, ",") {
s := strings.TrimSpace(o)
s = strings.TrimRight(s, "/") // Remove trailing slash if any
if len(s) > 0 {
allowedOrigins = append(allowedOrigins, s)
}
}
}
if len(allowedOrigins) > 0 {
router.Use(cors.New(cors.Config{
AllowOrigins: allowedOrigins,
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"},
Expand Down

0 comments on commit 52d839d

Please sign in to comment.