diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-02 16:41:48 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-02 16:41:48 +0200 |
| commit | 06c8b78fd08de1259b4c6c9046532c296db83e4d (patch) | |
| tree | 512b7e6fcff51fe163af7168e6974ac8de41e232 /backend | |
| parent | 0fcdacfc691e17ca15dc7e0d48a439ef7a52d9c7 (diff) | |
feat(backend): return not found instead of serving list of all files
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/router.go | 10 |
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) }) } |
