all repos — flounder @ 8bda7b71d80f1a3ca6c25209c1a95f4d9fa29051

A small site builder for the Gemini protocol

Add index.gmi to subfolders
alex wennerberg alex@alexwennerberg.com
Sun, 22 Nov 2020 14:11:36 -0800
commit

8bda7b71d80f1a3ca6c25209c1a95f4d9fa29051

parent

b018dfaaadf20d89645330d7acaf094d60779f69

1 files changed, 9 insertions(+), 3 deletions(-)

jump to
M http.gohttp.go

@@ -432,13 +432,19 @@ // Server a user's file

func userFile(w http.ResponseWriter, r *http.Request) { userName := filepath.Clean(strings.Split(r.Host, ".")[0]) // clean probably unnecessary p := filepath.Clean(r.URL.Path) - if p == "/" { - p = "index.gmi" + // chcek if is directory for index.gmi file + var isDir bool + fileName := path.Join(c.FilesDirectory, userName, p) + stat, _ := os.Stat(fileName) + if stat != nil { + isDir = stat.IsDir() + } + if p == "/" || isDir { + fileName = path.Join(fileName, "index.gmi") } else if strings.HasPrefix(p, "/.hidden") { renderError(w, "404: file not found", 404) return } - fileName := path.Join(c.FilesDirectory, userName, p) extension := path.Ext(fileName) if r.URL.Path == "/style.css" { http.ServeFile(w, r, path.Join(c.TemplatesDirectory, "static/style.css"))