Skip to content

Commit

Permalink
Merge branch 'feature-cors' into develop
Browse files Browse the repository at this point in the history
Adds #167 and support for WebGL and fun things
  • Loading branch information
LukeHandle committed Oct 10, 2015
2 parents 76c05a4 + 2b295de commit 6af3a9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ type Router struct {
Mux *mux.Router
}

// Middleware function to manipulate our request and response.
func imgdHandler(router http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding")
router.ServeHTTP(w, r)
})
}

type NotFoundHandler struct{}

// Handles 404 errors
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func setupLog(logBackend *logging.LogBackend) {
func startServer() {
r := Router{Mux: mux.NewRouter()}
r.Bind()
http.Handle("/", r.Mux)
http.Handle("/", imgdHandler(r.Mux))
log.Notice("imgd %s starting on %s", ImgdVersion, config.Server.Address)
err := http.ListenAndServe(config.Server.Address, nil)
if err != nil {
Expand Down

0 comments on commit 6af3a9c

Please sign in to comment.