From fab51ab54b63b5df965ddf0ee42f0557a0536bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Fri, 14 Jul 2023 12:38:43 +0200 Subject: [PATCH] http: Use own multiplexer --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index a745739..bcd73b8 100644 --- a/main.go +++ b/main.go @@ -452,17 +452,19 @@ func main() { logger.Infof("Listening on %s, ntfy-alertmanager %s", cfg.HTTPAddress, version) + mux := http.NewServeMux() + if cfg.User != "" && cfg.Password != "" { logger.Info("Enabling HTTP Basic Authentication") - http.HandleFunc("/", bridge.basicAuthMiddleware(bridge.handleWebhooks)) - http.HandleFunc("/silences", bridge.basicAuthMiddleware(bridge.handleSilences)) + mux.HandleFunc("/", bridge.basicAuthMiddleware(bridge.handleWebhooks)) + mux.HandleFunc("/silences", bridge.basicAuthMiddleware(bridge.handleSilences)) } else { - http.HandleFunc("/", bridge.handleWebhooks) - http.HandleFunc("/silences", bridge.handleSilences) + mux.HandleFunc("/", bridge.handleWebhooks) + mux.HandleFunc("/silences", bridge.handleSilences) } if _, ok := c.(*cache.MemoryCache); ok { go bridge.runCleanup() } - logger.Fatal(http.ListenAndServe(cfg.HTTPAddress, nil)) + logger.Fatal(http.ListenAndServe(cfg.HTTPAddress, mux)) }