Skip to content

Instantly share code, notes, and snippets.

@mindscratch
Created June 8, 2014 04:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mindscratch/1ce05bf0906eaac22730 to your computer and use it in GitHub Desktop.
Save mindscratch/1ce05bf0906eaac22730 to your computer and use it in GitHub Desktop.
CORS middleware in Go
// original: https://slack-files.com/T029RQSE6-F02ATJ4RW-75d559
func (h *corsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "*")
if r.Method == "OPTIONS" {
fmt.Fprint(w)
return
}
h.handler.ServeHTTP(w, r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment