fixed problem with '/' causing loading issues with application

This commit is contained in:
2026-05-07 23:33:24 +02:00
parent 97a893952f
commit e4364b0c2f
+7 -1
View File
@@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"strings"
"github.com/go-chi/chi/v5"
chimiddleware "github.com/go-chi/chi/v5/middleware"
@@ -232,7 +233,12 @@ func mustParseURL(raw string) *url.URL {
func spaHandler(staticFiles fs.FS) http.Handler {
fileServer := http.FileServer(http.FS(staticFiles))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
_, err := staticFiles.Open(r.URL.Path)
// fs.FS paths must not have a leading slash.
path := strings.TrimPrefix(r.URL.Path, "/")
if path == "" {
path = "."
}
_, err := staticFiles.Open(path)
if err != nil {
r.URL.Path = "/"
}