Add the Access-Control-Allow-Methods header so that
DELETE operations are allowed.
Also move the write CORS headers method before
docker writes a 404 not found so that the client
receives the correct response and not an invalid
CORS request.
... | ... |
@@ -706,6 +706,7 @@ func postBuild(srv *Server, version float64, w http.ResponseWriter, r *http.Requ |
706 | 706 |
func writeCorsHeaders(w http.ResponseWriter, r *http.Request) { |
707 | 707 |
w.Header().Add("Access-Control-Allow-Origin", "*") |
708 | 708 |
w.Header().Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept") |
709 |
+ w.Header().Add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT, OPTIONS") |
|
709 | 710 |
} |
710 | 711 |
|
711 | 712 |
func ListenAndServe(addr string, srv *Server, logging bool) error { |
... | ... |
@@ -774,13 +775,13 @@ func ListenAndServe(addr string, srv *Server, logging bool) error { |
774 | 774 |
if err != nil { |
775 | 775 |
version = API_VERSION |
776 | 776 |
} |
777 |
+ if srv.enableCors { |
|
778 |
+ writeCorsHeaders(w, r) |
|
779 |
+ } |
|
777 | 780 |
if version == 0 || version > API_VERSION { |
778 | 781 |
w.WriteHeader(http.StatusNotFound) |
779 | 782 |
return |
780 | 783 |
} |
781 |
- if srv.enableCors { |
|
782 |
- writeCorsHeaders(w, r) |
|
783 |
- } |
|
784 | 784 |
if err := localFct(srv, version, w, r, mux.Vars(r)); err != nil { |
785 | 785 |
httpError(w, err) |
786 | 786 |
} |