diff --git a/cmd_serve.go b/cmd_serve.go index 8073bcb..e70ff83 100644 --- a/cmd_serve.go +++ b/cmd_serve.go @@ -98,7 +98,16 @@ func (cmd *CmdServe) Run(app *app) error { 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() + 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)) // Can't use Chi at the root, since it can't properly handle the mounted WebDAV