Fix page creation

This commit is contained in:
2026-04-13 13:07:20 +02:00
parent 95ca30509c
commit 19017bf136
4 changed files with 44 additions and 3 deletions

10
main.go
View File

@@ -86,7 +86,15 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
info, err := os.Stat(fsPath)
if err != nil {
if os.IsNotExist(err) && strings.HasSuffix(r.URL.Path, "/") {
if os.IsNotExist(err) {
// Non-existent path: redirect GETs to the canonical slash form so
// the browser URL is consistent, then serve an empty folder page.
// POSTs must not be redirected — the form action has no trailing
// slash (path.Clean strips it) and the content would be lost.
if !strings.HasSuffix(r.URL.Path, "/") && r.Method != http.MethodPost {
http.Redirect(w, r, r.URL.Path+"/", http.StatusMovedPermanently)
return
}
h.serveDir(w, r, urlPath, fsPath)
return
}