small pixel drawing of a pufferfish vore

ensure static handler takes priority over user handler
Jes Olson j3s@c3f.net
Thu, 25 May 2023 17:06:54 -0700
commit

1a1043a2103f5417a16d47e53ff0806fe0e3474e

parent

7305d42d83e957207b006f8502f7935679e5fe58

2 files changed, 14 insertions(+), 8 deletions(-)

jump to
M files/head.tmpl.htmlfiles/head.tmpl.html

@@ -9,7 +9,7 @@ <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">

<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"> <link rel='shortcut icon' href='/favicon.ico'> - <link rel="stylesheet" href="/static/style.css"> + <link rel="stylesheet" href="/style.css"> <link rel="manifest" href="/manifest.json"> <script>
M site.gosite.go

@@ -51,17 +51,23 @@ if r.URL.Path == "/" {

s.indexHandler(w, r) return } - // handles /<username> - if s.db.UserExists(strings.TrimPrefix(r.URL.Path, "/")) { - s.userHandler(w, r) - return - } - // handles static files - file := filepath.Join("files", "static", strings.TrimPrefix(r.URL.Path, "/")) + + // path can be /<username> or /<static-file> + requestPath := strings.TrimPrefix(r.URL.Path, "/") + + // handles static files first + file := filepath.Join("files", "static", requestPath) if _, err := os.Stat(file); !errors.Is(err, os.ErrNotExist) { http.ServeFile(w, r, file) return } + + // handles /<username> + if s.db.UserExists(requestPath) { + s.userHandler(w, r) + return + } + // 404 http.NotFound(w, r) }