mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-11-08 08:10:08 +00:00
[core] Add support for OPTIONS requests
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
464212c757
commit
dbcd28a8b0
1 changed files with 10 additions and 0 deletions
10
main.go
10
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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue