From 06c8b78fd08de1259b4c6c9046532c296db83e4d Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 2 Oct 2025 16:41:48 +0200 Subject: feat(backend): return not found instead of serving list of all files --- backend/router.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'backend/router.go') 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) }) } -- cgit v1.2.3