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.
This commit is contained in:
n.nakhostin
2025-09-02 15:28:52 +03:30
parent 9c13b3f27f
commit 8d3a021fbf
+2 -4
View File
@@ -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