From 3d02120f1b080b03396526990d72acf2bb22bff6 Mon Sep 17 00:00:00 2001 From: Sven Nebel Date: Sun, 8 Sep 2019 20:15:40 +0100 Subject: [PATCH] Redirect over routePrefix on non-matching path Signed-off-by: Sven Nebel --- main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index f6ad1ee6..c8dd3e95 100644 --- a/main.go +++ b/main.go @@ -237,7 +237,7 @@ func run() int { *routePrefix = beURL.Path } - // RoutePrefix must always be at least '/'. + // routePrefix must always be at least '/'. *routePrefix = "/" + strings.Trim(*routePrefix, "/") level.Debug(logger).Log("routePrefix", *routePrefix) @@ -345,6 +345,15 @@ func run() int { w.Write(c) }) + // Match Prometheus behaviour and redirect over routePrefix for root path only + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + http.NotFound(w, r) + return + } + http.Redirect(w, r, *routePrefix, http.StatusFound) + }) + srv := http.Server{Addr: *listenAddress} srvc := make(chan struct{}) term := make(chan os.Signal, 1)