Allow all CORS origins and headers
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2022-12-20 14:02:57 -08:00
parent 81013ce376
commit 0b53c16f9c
1 changed files with 13 additions and 2 deletions

View File

@ -42,9 +42,20 @@ func main() {
}
log.Info("Starting HTTP API server").Str("addr", ln.Addr().String()).Send()
err = http.Serve(ln, srv)
err = http.Serve(ln, allowAllCORSHandler(srv))
if err != nil {
log.Fatal("Error while running server").Err(err).Send()
}
}
func allowAllCORSHandler(h http.Handler) http.Handler {
return http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Access-Control-Allow-Origin", "*")
res.Header().Set("Access-Control-Allow-Headers", "*")
if req.Method == http.MethodOptions {
return
}
h.ServeHTTP(res, req)
})
}