flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 06055f4269d3561e701595efa385e13bfbd3aa7b
parent 81e460a74946d2c930ea600cbea947e34a8d9174
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sat,  5 Dec 2020 15:36:19 -0800

404 all pages not just gmi

Diffstat:
Mhttp.go | 15++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/http.go b/http.go @@ -432,6 +432,7 @@ func getFavicon(user string) string { // Server a user's file func userFile(w http.ResponseWriter, r *http.Request) { userName := filepath.Clean(strings.Split(r.Host, ".")[0]) // clean probably unnecessary + query := r.URL.Query() p := filepath.Clean(r.URL.Path) // chcek if is directory for index.gmi file var isDir bool @@ -450,16 +451,16 @@ func userFile(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/style.css" { http.ServeFile(w, r, path.Join(c.TemplatesDirectory, "static/style.css")) } - query := r.URL.Query() - _, raw := query["raw"] + _, err := os.Stat(fileName) + if err != nil { + renderError(w, "404: file not found", 404) + return + } // dumb content negotiation + _, raw := query["raw"] acceptsGemini := strings.Contains(r.Header.Get("Accept"), "text/gemini") if !raw && !acceptsGemini && (extension == ".gmi" || extension == ".gemini") { - _, err := os.Stat(fileName) - if err != nil { - renderError(w, "404: file not found", 404) - return - } + file, _ := os.Open(fileName) htmlString := textToHTML(gmi.ParseText(file))