From 8ee3b8c848f055955b282e580d0e047bc53afd94 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Thu, 14 Nov 2019 14:58:22 +0100 Subject: [PATCH] React UI: Fix "/new" -> "/new/" redirect (#6319) Fixes https://github.com/prometheus/prometheus/issues/6163 Signed-off-by: Julius Volz --- web/web.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/web/web.go b/web/web.go index d8e7fcbb2..c2fcb24db 100644 --- a/web/web.go +++ b/web/web.go @@ -347,6 +347,15 @@ func New(logger log.Logger, o *Options) *Handler { fs.ServeHTTP(w, r) }) + // Make sure that "/new" is redirected to "/new/" and + // not just the naked "/new/", which would be the default behavior of the router + // with the "RedirectTrailingSlash" option (https://godoc.org/github.com/julienschmidt/httprouter#Router.RedirectTrailingSlash), + // and which breaks users with a --web.route-prefix that deviates from the path derived + // from the external URL. + router.Get("/new", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, path.Join(o.ExternalURL.Path, "new")+"/", http.StatusFound) + }) + router.Get("/new/*filepath", func(w http.ResponseWriter, r *http.Request) { p := route.Param(r.Context(), "filepath")