diff --git a/cmd/thanos/query.go b/cmd/thanos/query.go index 9433f5601d..ddbb315d2a 100644 --- a/cmd/thanos/query.go +++ b/cmd/thanos/query.go @@ -9,6 +9,7 @@ import ( "math" "net/http" "path" + "strings" "time" "github.com/go-kit/kit/log" @@ -324,11 +325,15 @@ func runQuery( { router := route.New() + // RoutePrefix must always start with '/'. + webRoutePrefix = "/" + strings.Trim(webRoutePrefix, "/") + // Redirect from / to /webRoutePrefix. - if webRoutePrefix != "" { + if webRoutePrefix != "/" { router.Get("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, webRoutePrefix, http.StatusFound) }) + router = router.WithPrefix(webRoutePrefix) } flagsMap := map[string]string{ @@ -338,7 +343,7 @@ func runQuery( } ins := extpromhttp.NewInstrumentationMiddleware(reg) - ui.NewQueryUI(logger, reg, stores, flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) + ui.NewQueryUI(logger, reg, stores, flagsMap).Register(router, ins) api := v1.NewAPI(logger, reg, engine, queryableCreator, enableAutodownsampling, enablePartialResponse, replicaLabels, instantDefaultMaxSourceResolution) diff --git a/cmd/thanos/rule.go b/cmd/thanos/rule.go index 9db7ba17e7..a9dcc857be 100644 --- a/cmd/thanos/rule.go +++ b/cmd/thanos/rule.go @@ -558,11 +558,15 @@ func runRule( { router := route.New() + // RoutePrefix must always start with '/'. + webRoutePrefix = "/" + strings.Trim(webRoutePrefix, "/") + // Redirect from / to /webRoutePrefix. - if webRoutePrefix != "" { + if webRoutePrefix != "/" { router.Get("/", func(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, webRoutePrefix, http.StatusFound) }) + router = router.WithPrefix(webRoutePrefix) } router.WithPrefix(webRoutePrefix).Post("/-/reload", func(w http.ResponseWriter, r *http.Request) { @@ -577,7 +581,7 @@ func runRule( ins := extpromhttp.NewInstrumentationMiddleware(reg) - ui.NewRuleUI(logger, reg, ruleMgr, alertQueryURL.String(), flagsMap).Register(router.WithPrefix(webRoutePrefix), ins) + ui.NewRuleUI(logger, reg, ruleMgr, alertQueryURL.String(), flagsMap).Register(router, ins) api := v1.NewAPI(logger, reg, ruleMgr) api.Register(router.WithPrefix(path.Join(webRoutePrefix, "/api/v1")), tracer, logger, ins)