Created
October 26, 2016 16:19
-
-
Save maleck13/7b9be9b0f694f0df69ae6abec6400c01 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 main | |
import ( | |
"log" | |
"net/http" | |
) | |
func main() { | |
h := http.FileServer(http.Dir("/Users/kelly/work/go/src/github.com/maleck13/restnode/app/swagger")) | |
h = handler(h) | |
if err := http.ListenAndServe(":3001", h); err != nil { | |
log.Fatal(err.Error()) | |
} | |
} | |
type cors struct { | |
handler http.Handler | |
} | |
func (c cors) ServeHTTP(res http.ResponseWriter, req *http.Request) { | |
res.Header().Add("Access-Control-Allow-Origin", "*") | |
c.handler.ServeHTTP(res, req) | |
} | |
func handler(h http.Handler) http.Handler { | |
c := cors{handler: h} | |
return c | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment