🚸 Fix admin url requiring a slash at the end
This commit is contained in:
parent
a8b2db986a
commit
fd0d7ddee6
|
@ -98,7 +98,16 @@ func (cmd *CmdServe) Run(app *app) error {
|
||||||
h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), "mapping", &directoryMapping)))
|
h.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), "mapping", &directoryMapping)))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Setup the admin endpoint with convenience routing. (Should the user omit the trailing slash, we add
|
||||||
|
// it for them.)
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
adminPathWithoutSlash := strings.TrimSuffix(cmd.AdminPath, "/")
|
||||||
|
if !strings.HasSuffix(cmd.AdminPath, "/") {
|
||||||
|
cmd.AdminPath = cmd.AdminPath + "/"
|
||||||
|
}
|
||||||
|
r.Get(adminPathWithoutSlash, func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Redirect(w, r, cmd.AdminPath, http.StatusMovedPermanently)
|
||||||
|
})
|
||||||
r.Mount(cmd.AdminPath, newWebAdminHandler(app))
|
r.Mount(cmd.AdminPath, newWebAdminHandler(app))
|
||||||
|
|
||||||
// Can't use Chi at the root, since it can't properly handle the mounted WebDAV
|
// Can't use Chi at the root, since it can't properly handle the mounted WebDAV
|
||||||
|
|
Loading…
Reference in New Issue