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)) }