Bump version to 1.0.3

webui: use fs.Sub to fix embed FS root so static assets are found

Previously http.FileServer searched for assets/foo.css in the embed FS
rooted at dist/, but only paths starting with dist/ resolve. fs.Sub
strips the dist/ prefix so FileServer finds the actual files.
This commit is contained in:
2026-07-07 19:46:03 -04:00
parent 79b6c958fd
commit 596981b63b
3 changed files with 9 additions and 5 deletions
+7 -3
View File
@@ -9,15 +9,19 @@ import (
//go:embed dist
var DistFS embed.FS
var Dist fs.FS = DistFS
var distSub, _ = fs.Sub(DistFS, "dist")
func ServeHTTP() http.Handler {
return http.FileServer(http.FS(DistFS))
return http.FileServer(http.FS(distSub))
}
func ServeSPA() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
if path == "/favicon.ico" {
w.WriteHeader(http.StatusNoContent)
return
}
if path == "/" || !isStaticAsset(path) {
data, err := DistFS.ReadFile("dist/index.html")
if err != nil {
@@ -28,7 +32,7 @@ func ServeSPA() http.Handler {
w.Write(data)
return
}
http.StripPrefix("/", http.FileServer(http.FS(DistFS))).ServeHTTP(w, r)
http.FileServer(http.FS(distSub)).ServeHTTP(w, r)
})
}