Last active
May 27, 2019 12:35
-
-
Save vcostin/a82a5bc6c33cd8d712974af3b89f8cfb to your computer and use it in GitHub Desktop.
GO http CORS middleware
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
package middleware | |
import ( | |
"net/http" | |
) | |
// Cors hello | |
func Cors(next http.Handler) http.HandlerFunc { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
w.Header().Set("Access-Control-Allow-Origin", "*") | |
w.Header().Set("Access-Control-Allow-Methods", "*") | |
w.Header().Set("Access-Control-Allow-Headers", "*") | |
if r.Method == http.MethodOptions { | |
return | |
} | |
next.ServeHTTP(w, r) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment