package util import ( "net/http" ) // Cors writes cors headers func Cors(h 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-Credentials", "true") w.Header().Set("Access-Control-Allow-Methods", "GET,POST,PATCH,PUT,DELETE,OPTIONS") w.Header().Set("Access-Control-Expose-Headers", "*") w.Header().Set("Access-Control-Allow-Headers", "*") if r.Method == "OPTIONS" { WriteResponse(w, http.StatusOK, "Ok", "Ok") return } else { h.ServeHTTP(w, r) } }) }