this repo has no description
1package middleware 2 3import "net/http" 4 5func CORS(next http.Handler) http.Handler { 6 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 7 // Set CORS headers 8 w.Header().Set("Access-Control-Allow-Origin", "*") 9 w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS") 10 w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") 11 w.Header().Set("Access-Control-Max-Age", "86400") 12 13 // Handle preflight requests 14 if r.Method == "OPTIONS" { 15 w.WriteHeader(http.StatusOK) 16 return 17 } 18 19 next.ServeHTTP(w, r) 20 }) 21}