Skip to content

Commit

Permalink
Update reverse proxy to handle options requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nitaliano committed Jul 31, 2024
1 parent 87cd75f commit 29af893
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions opsimulator/opsimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ func (a *OpSimulator) Stopped() bool {

func handler(proxy *httputil.ReverseProxy) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodOptions {
// handle preflight requests
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "*")
w.Header().Set("Access-Control-Allow-Headers", "*")
w.WriteHeader(http.StatusNoContent)
return
}

body, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, "Failed to read request body", http.StatusInternalServerError)
Expand Down

0 comments on commit 29af893

Please sign in to comment.