React UI: Fix "<path-prefix>/new" -> "<path-prefix>/new/" redirect
Fixes
@@ -347,6 +347,15 @@ func New(logger log.Logger, o *Options) *Handler {
fs.ServeHTTP(w, r)
})
+ // Make sure that "<path-prefix>/new" is redirected to "<path-prefix>/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")
