react handler: check if there is an html file

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
Adphi 2024-11-19 15:11:11 +01:00
parent e5d84975a2
commit 828bf008ca
Signed by: adphi
GPG Key ID: 46BE4062DB2397FF

View File

@ -41,8 +41,13 @@ func newStatic(dir fs.FS, subpath string) (http.Handler, error) {
} }
fsrv := http.FileServer(http.FS(s)) fsrv := http.FileServer(http.FS(s))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if _, err := fs.Stat(s, strings.TrimPrefix(r.URL.Path, "/")); err != nil { p := strings.TrimPrefix(r.URL.Path, "/")
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) fsrv.ServeHTTP(w, r)
}), nil }), nil