add middleware for perflite requests and delete cors from user and auth

handlers
This commit is contained in:
2025-10-11 11:07:43 +05:00
parent 6850701b47
commit 2ccab0a17f
5 changed files with 33 additions and 25 deletions
+25
View File
@@ -0,0 +1,25 @@
// pkg/middleware/cors.go
package middleware
import (
"net/http"
)
// CORS middleware для обработки preflight запросов
func CORS(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Устанавливаем CORS заголовки
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With")
// Если это OPTIONS запрос (preflight), сразу отвечаем
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
next.ServeHTTP(w, r)
})
}
@@ -9,6 +9,8 @@ import (
func CommonMiddleware() []func(http.Handler) http.Handler {
return []func(http.Handler) http.Handler{
CORS,
middleware.Logger,
ZapLogger,
middleware.Recoverer,
middleware.RequestID,