package middleware import "net/http" func WithCors(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { var h http.Header h = w.Header() //h.Add("Vary", "Origin") //h.Add("Vary", "Access-Control-Request-Method") //h.Add("Vary", "Access-Control-Request-Headers") //h.Add("Access-Control-Allow-Headers", "Content-Type, Origin, Accept, token") h.Add("Access-Control-Allow-Headers", "*") //h.Add("Access-Control-Allow-Methods", "DELETE,GET,PUT,POST,OPTIONS") h.Add("Access-Control-Allow-Methods", "*") h.Add("Access-Control-Allow-Origin", "*") if r.Method == http.MethodOptions { w.WriteHeader(http.StatusOK) return } next.ServeHTTP(w, r) }) }