Fix page creation
This commit is contained in:
10
main.go
10
main.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user