Add CORS middleware
Fixes: https://todo.xenrox.net/~xenrox/ntfy-alertmanager/21
This commit is contained in:
parent
c0a0e3c264
commit
2dcfb7270e
1 changed files with 12 additions and 0 deletions
12
main.go
12
main.go
|
@ -402,6 +402,16 @@ func (br *bridge) handleWebhooks(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
func (br *bridge) corsMiddleware(handler http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
w.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
|
||||
handler.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (br *bridge) authMiddleware(handler http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
logger := br.logger.With(slog.String("url", r.URL.String()))
|
||||
|
@ -495,6 +505,8 @@ func main() {
|
|||
httpServer.Handler = bridge.authMiddleware(mux)
|
||||
}
|
||||
|
||||
httpServer.Handler = bridge.corsMiddleware(httpServer.Handler)
|
||||
|
||||
if _, ok := c.(*cache.MemoryCache); ok {
|
||||
go bridge.runCleanup(ctx)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue