http: Use own multiplexer

This commit is contained in:
Thorben Günther 2023-07-14 12:38:43 +02:00
parent a9fa7e4b23
commit fab51ab54b
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED

12
main.go
View file

@ -452,17 +452,19 @@ func main() {
logger.Infof("Listening on %s, ntfy-alertmanager %s", cfg.HTTPAddress, version) logger.Infof("Listening on %s, ntfy-alertmanager %s", cfg.HTTPAddress, version)
mux := http.NewServeMux()
if cfg.User != "" && cfg.Password != "" { if cfg.User != "" && cfg.Password != "" {
logger.Info("Enabling HTTP Basic Authentication") logger.Info("Enabling HTTP Basic Authentication")
http.HandleFunc("/", bridge.basicAuthMiddleware(bridge.handleWebhooks)) mux.HandleFunc("/", bridge.basicAuthMiddleware(bridge.handleWebhooks))
http.HandleFunc("/silences", bridge.basicAuthMiddleware(bridge.handleSilences)) mux.HandleFunc("/silences", bridge.basicAuthMiddleware(bridge.handleSilences))
} else { } else {
http.HandleFunc("/", bridge.handleWebhooks) mux.HandleFunc("/", bridge.handleWebhooks)
http.HandleFunc("/silences", bridge.handleSilences) mux.HandleFunc("/silences", bridge.handleSilences)
} }
if _, ok := c.(*cache.MemoryCache); ok { if _, ok := c.(*cache.MemoryCache); ok {
go bridge.runCleanup() go bridge.runCleanup()
} }
logger.Fatal(http.ListenAndServe(cfg.HTTPAddress, nil)) logger.Fatal(http.ListenAndServe(cfg.HTTPAddress, mux))
} }