Allow all CORS origins and headers
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
81013ce376
commit
0b53c16f9c
|
@ -42,9 +42,20 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Starting HTTP API server").Str("addr", ln.Addr().String()).Send()
|
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 {
|
if err != nil {
|
||||||
log.Fatal("Error while running server").Err(err).Send()
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue