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:
@@ -9,8 +9,8 @@ import (
|
|||||||
|
|
||||||
func CommonMiddleware() []func(http.Handler) http.Handler {
|
func CommonMiddleware() []func(http.Handler) http.Handler {
|
||||||
return []func(http.Handler) http.Handler{
|
return []func(http.Handler) http.Handler{
|
||||||
|
HandleOptions,
|
||||||
CORS,
|
CORS,
|
||||||
middleware.Logger,
|
|
||||||
ZapLogger,
|
ZapLogger,
|
||||||
middleware.Recoverer,
|
middleware.Recoverer,
|
||||||
middleware.RequestID,
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user