ensure static handler takes priority over user handler
Jes Olson j3s@c3f.net
Thu, 25 May 2023 17:06:54 -0700
2 files changed,
14 insertions(+),
8 deletions(-)
M
files/head.tmpl.html
→
files/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.go
→
site.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) }