Skip to content

Commit

Permalink
Added CORS support for the monitoring server
Browse files Browse the repository at this point in the history
  • Loading branch information
mdawar committed Aug 23, 2023
1 parent 5a926f1 commit e5836fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/monitor.go
Expand Up @@ -2313,6 +2313,7 @@ func ResponseHandler(w http.ResponseWriter, r *http.Request, data []byte) {
} else {
// Otherwise JSON
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Write(data)
}
}
Expand Down
9 changes: 8 additions & 1 deletion server/monitor_test.go
Expand Up @@ -157,7 +157,14 @@ func readBodyEx(t *testing.T, url string, status int, content string) []byte {
}
ct := resp.Header.Get("Content-Type")
if ct != content {
stackFatalf(t, "Expected %s content-type, got %s\n", content, ct)
stackFatalf(t, "Expected %q content-type, got %q\n", content, ct)
}
// Check the CORS header for "application/json" requests only.
if ct == appJSONContent {
acao := resp.Header.Get("Access-Control-Allow-Origin")
if acao != "*" {
stackFatalf(t, "Expected with %q Content-Type an Access-Control-Allow-Origin header with value %q, got %q\n", appJSONContent, "*", acao)
}
}
body, err := io.ReadAll(resp.Body)
if err != nil {
Expand Down

0 comments on commit e5836fc

Please sign in to comment.