From 828bf008ca466b90f5b717c46756e40be512eeb0 Mon Sep 17 00:00:00 2001 From: Adphi Date: Tue, 19 Nov 2024 15:11:11 +0100 Subject: [PATCH] react handler: check if there is an html file Signed-off-by: Adphi --- react/ui.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/react/ui.go b/react/ui.go index 51ce77e..09dbe52 100644 --- a/react/ui.go +++ b/react/ui.go @@ -41,8 +41,13 @@ func newStatic(dir fs.FS, subpath string) (http.Handler, error) { } fsrv := http.FileServer(http.FS(s)) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if _, err := fs.Stat(s, strings.TrimPrefix(r.URL.Path, "/")); err != nil { - r.URL.Path = "/" + p := strings.TrimPrefix(r.URL.Path, "/") + if _, err := fs.Stat(s, p); err != nil { + if _, err := fs.Stat(s, p+".html"); err == nil { + r.URL.Path += ".html" + } else { + r.URL.Path = "/" + } } fsrv.ServeHTTP(w, r) }), nil