aboutsummaryrefslogtreecommitdiff
path: root/backend/router.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 16:41:48 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 16:41:48 +0200
commit06c8b78fd08de1259b4c6c9046532c296db83e4d (patch)
tree512b7e6fcff51fe163af7168e6974ac8de41e232 /backend/router.go
parent0fcdacfc691e17ca15dc7e0d48a439ef7a52d9c7 (diff)
feat(backend): return not found instead of serving list of all files
Diffstat (limited to 'backend/router.go')
-rw-r--r--backend/router.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/backend/router.go b/backend/router.go
index 4c3b2f8..f5d0cc6 100644
--- a/backend/router.go
+++ b/backend/router.go
@@ -61,9 +61,13 @@ func HandleStaticFiles(r *chi.Mux, path string, root fs.FS) {
}
path += "*"
- r.Get(path, func(w http.ResponseWriter, r *http.Request) {
- ctx := chi.RouteContext(r.Context())
+ r.Get(path, func(w http.ResponseWriter, req *http.Request) {
+ ctx := chi.RouteContext(req.Context())
pathPrefix := strings.TrimSuffix(ctx.RoutePattern(), "/*")
- http.StripPrefix(pathPrefix, http.FileServerFS(root)).ServeHTTP(w, r)
+ if pathPrefix+"/" == req.URL.Path {
+ r.NotFoundHandler().ServeHTTP(w, req)
+ return
+ }
+ http.StripPrefix(pathPrefix, http.FileServerFS(root)).ServeHTTP(w, req)
})
}