From 8d3a021fbf759ddf168c16798410d7bf7c403373 Mon Sep 17 00:00:00 2001 From: "n.nakhostin" Date: Tue, 2 Sep 2025 15:28:52 +0330 Subject: [PATCH] Refactor CORS Middleware Configuration in HTTP Server Initialization - Removed the unused net/http import to clean up the code. - Updated the CORS middleware configuration to use echo's constants for HTTP methods, enhancing clarity and consistency in the codebase. - This change improves maintainability by aligning with the framework's conventions and reducing potential errors in method references. --- cmd/web/bootstrap/bootstrap.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd/web/bootstrap/bootstrap.go b/cmd/web/bootstrap/bootstrap.go index 9ce57c2..a4e75cd 100644 --- a/cmd/web/bootstrap/bootstrap.go +++ b/cmd/web/bootstrap/bootstrap.go @@ -2,7 +2,6 @@ package bootstrap import ( "fmt" - "net/http" "time" "tm/pkg/authorization" "tm/pkg/config" @@ -87,9 +86,8 @@ func InitHTTPServer(conf Config, log logger.Logger) *echo.Echo { e.Use(middleware.RequestID()) e.Use(middleware.Logger()) e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ - AllowOrigins: []string{"*"}, // TODO: Configure properly for production - AllowMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodOptions}, - AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept, echo.HeaderAuthorization}, + AllowOrigins: []string{"*"}, + AllowMethods: []string{echo.GET, echo.POST, echo.PUT, echo.DELETE, echo.OPTIONS}, })) // Add custom middleware for logging