video-server-backend/api/middleware/cors.go
Jose134 a81d316635
All checks were successful
gitea/video-server-backend/pipeline/head This commit looks good
Structured the project in different files
2024-08-13 19:50:39 +02:00

17 lines
473 B
Go

package middleware
import "net/http"
func AddCORSHeaders(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
if r.Method == "OPTIONS" {
w.WriteHeader(http.StatusOK)
return
}
next.ServeHTTP(w, r)
})
}