Skip to content

Commit 9a272a3

Browse files
committed
feat(cors): configure CORS with custom options
Replace AllowAll with custom CORS options using values from config. This enables fine-grained control over allowed origins, headers, and methods, and ensures credentials are supported. Improves security and flexibility for HTTP server CORS handling.
1 parent c08c8b3 commit 9a272a3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

cmd/serve_http.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ var serveHttpCmd = &cobra.Command{
6060
router := registerHandler(app)
6161

6262
// build cors
63-
muxCorsWithRouter := cors.AllowAll().Handler(router)
63+
muxCorsWithRouter := cors.New(cors.Options{
64+
AllowedOrigins: cfg.CORS_ALLOWED_ORIGINS,
65+
AllowedHeaders: cfg.CORS_ALLOWED_HEADERS,
66+
AllowedMethods: cfg.CORS_ALLOWED_METHODS,
67+
AllowCredentials: true,
68+
}).Handler(router)
6469

6570
srv := &http.Server{
6671
Addr: cfg.APP_PORT,

0 commit comments

Comments
 (0)