zrok/util/cors.go
2024-10-07 16:40:07 -04:00

16 lines
511 B
Go

package util
import "net/http"
func cors(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin"))
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, Authorization, ResponseType, User-Agent")
if r.Method == "OPTIONS" {
return
}
h.ServeHTTP(w, r)
})
}