Last active
October 31, 2017 03:24
-
-
Save jtrein/b5b5a0474d2f74073e00cf251a280461 to your computer and use it in GitHub Desktop.
CORS Header Golang (Gorilla)
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
// https://stackoverflow.com/questions/40985920/making-golang-gorilla-cors-handler-work/40987389#40987389 | |
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With"}) | |
originsOk := handlers.AllowedOrigins([]string{os.Getenv("ORIGIN_ALLOWED")}) | |
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"}) | |
// start server listen | |
// with error handling | |
log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), handlers.CORS(originsOk, headersOk, methodsOk)(router))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment