Do some headers to allow use from other domains

This commit is contained in:
Steve Howes
2023-10-21 20:39:18 +01:00
parent 8dc785d843
commit 910ff909b1
+2
View File
@@ -83,6 +83,7 @@ func makeHTTPServer(listenPort string) *http.Server {
} }
func handleError(w http.ResponseWriter, _ *http.Request, str string, _ error) { func handleError(w http.ResponseWriter, _ *http.Request, str string, _ error) {
w.Header().Add("Access-Control-Allow-Origin", "*")
w.WriteHeader(http.StatusBadRequest) w.WriteHeader(http.StatusBadRequest)
fmt.Fprintf(w, "Invalid request: %q\n", str) fmt.Fprintf(w, "Invalid request: %q\n", str)
} }
@@ -97,6 +98,7 @@ func handle(w http.ResponseWriter, _ *http.Request, ref osgridref.OsGridRef, lat
} }
w.Header().Add("Content-Type", "application/json") w.Header().Add("Content-Type", "application/json")
w.Header().Add("Access-Control-Allow-Origin", "*")
enc := json.NewEncoder(w) enc := json.NewEncoder(w)
enc.SetEscapeHTML(false) enc.SetEscapeHTML(false)
err := enc.Encode(reply) err := enc.Encode(reply)