Fix the directory listing, once and for all
Signed-off-by: arzumify <jliwin98@danwin1210.de>
This commit is contained in:
parent
65de87137d
commit
144452f798
7
main.go
7
main.go
|
@ -288,7 +288,7 @@ func listDirectory(w http.ResponseWriter, r *http.Request, root string) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, entry := range entries {
|
for _, entry := range entries {
|
||||||
_, err = w.Write([]byte("<li><a href=\"./" + entry.Name() + "\">" + entry.Name() + "</a></li>"))
|
_, err = w.Write([]byte("<li><a href=\"" + filepath.Join(r.URL.Path, entry.Name()) + "\">" + entry.Name() + "</a></li>"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
serverError(w, 500)
|
serverError(w, 500)
|
||||||
slog.Error("Error writing directory listing: " + err.Error())
|
slog.Error("Error writing directory listing: " + err.Error())
|
||||||
|
@ -385,11 +385,6 @@ func newFileServer(root string, directoryListing bool) http.Handler {
|
||||||
_, err := os.Stat(filepath.Join(root, filepath.FromSlash(r.URL.Path), "index.html"))
|
_, err := os.Stat(filepath.Join(root, filepath.FromSlash(r.URL.Path), "index.html"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if directoryListing {
|
if directoryListing {
|
||||||
// Check if the path ends with a slash
|
|
||||||
if !strings.HasSuffix(r.URL.Path, "/") {
|
|
||||||
http.Redirect(w, r, r.URL.Path+"/", 301)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
listDirectory(w, r, root)
|
listDirectory(w, r, root)
|
||||||
} else {
|
} else {
|
||||||
serverError(w, 403)
|
serverError(w, 403)
|
||||||
|
|
Loading…
Reference in New Issue