[core] Add support for OPTIONS requests

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-03-29 00:50:42 +02:00
parent 464212c757
commit dbcd28a8b0
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

10
main.go
View file

@ -187,6 +187,16 @@ func main() {
router.HandleFunc("/openapi.json", handleSwaggerRequest) router.HandleFunc("/openapi.json", handleSwaggerRequest)
router.HandleFunc("/selfcheck", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(runID)) }) router.HandleFunc("/selfcheck", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(runID)) })
router.MethodNotAllowedHandler = corsMiddleware(http.HandlerFunc(func(res http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodOptions {
// Most likely JS client asking for CORS headers
res.WriteHeader(http.StatusNoContent)
return
}
res.WriteHeader(http.StatusMethodNotAllowed)
}))
if err = initCorePlugins(); err != nil { if err = initCorePlugins(); err != nil {
log.WithError(err).Fatal("Unable to load core plugins") log.WithError(err).Fatal("Unable to load core plugins")
} }