modified: serv_nginx/api_bb/pkg/middleware/middleware.go

new file:   serv_nginx/api_bb/pkg/middleware/options.go
delete one middleware
This commit is contained in:
2025-10-11 11:21:39 +05:00
parent 3d921c01e0
commit 556780fd28
2 changed files with 20 additions and 1 deletions
@@ -9,8 +9,8 @@ import (
func CommonMiddleware() []func(http.Handler) http.Handler {
return []func(http.Handler) http.Handler{
HandleOptions,
CORS,
middleware.Logger,
ZapLogger,
middleware.Recoverer,
middleware.RequestID,
@@ -0,0 +1,19 @@
// pkg/middleware/options.go
package middleware
import "net/http"
// HandleOptions автоматически обрабатывает OPTIONS запросы
func HandleOptions(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method == "OPTIONS" {
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")
w.WriteHeader(http.StatusOK)
return
}
next.ServeHTTP(w, r)
})
}