Add Access-Control-Allow-Origin and friends
All checks were successful
the build was successful

This commit is contained in:
Peter Stuifzand 2018-08-26 18:50:11 +02:00
parent 67c27a6139
commit a4416164cd
Signed by: peter
GPG Key ID: 374322D56E5209E8

View File

@ -63,6 +63,13 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
if r.Method == http.MethodOptions {
w.Header().Add("Access-Control-Allow-Origin", "*")
w.Header().Add("Access-Control-Allow-Methods", "GET, POST")
w.Header().Add("Access-Control-Allow-Headers", "Authorization")
return
}
if r.Method == http.MethodGet {
values := r.URL.Query()
action := values.Get("action")
@ -74,6 +81,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Access-Control-Allow-Origin", "*")
err = jw.Encode(map[string][]microsub.Channel{
"channels": channels,
})
@ -89,6 +97,7 @@ func (h *microsubHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
jw := json.NewEncoder(w)
w.Header().Add("Content-Type", "application/json")
w.Header().Add("Access-Control-Allow-Origin", "*")
jw.SetIndent("", " ")
jw.SetEscapeHTML(false)
err = jw.Encode(timeline)