From dbcd28a8b01a1c8df376cbbfe2cb864b1c34d17f Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Tue, 29 Mar 2022 00:50:42 +0200 Subject: [PATCH] [core] Add support for OPTIONS requests Signed-off-by: Knut Ahlers --- main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.go b/main.go index 3f8bdbe..a6f26ba 100644 --- a/main.go +++ b/main.go @@ -187,6 +187,16 @@ func main() { router.HandleFunc("/openapi.json", handleSwaggerRequest) 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 { log.WithError(err).Fatal("Unable to load core plugins") }