Created
June 8, 2014 04:11
-
-
Save mindscratch/1ce05bf0906eaac22730 to your computer and use it in GitHub Desktop.
CORS middleware in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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