zrok/util/cors.go

16 lines
511 B
Go
Raw Normal View History

2024-10-07 22:40:07 +02:00
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)
})
}