rudimentary CORS support

This commit is contained in:
mappu 2017-10-08 16:42:06 +13:00
parent d695bc1255
commit 8795db5150

View File

@ -107,7 +107,12 @@ func (this *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} else if r.Method == "POST" && r.URL.Path == `/upload` {
this.handleUpload(w, r)
} else if static, err := Asset(r.URL.Path[1:]); err == nil {
} else if r.Method == "OPTIONS" {
// Blanket allow
w.Header().Set(`Access-Control-Allow-Origin`, `*`)
w.WriteHeader(200)
} else if r.Method == "GET" && static, err := Asset(r.URL.Path[1:]); err == nil {
http.ServeContent(w, r, r.URL.Path[1:], this.startTime, bytes.NewReader(static))
} else {