Fix static file serving by using fs.Sub on embed FS
build-and-push / test (push) Successful in 34s
build-and-push / build-and-push (push) Successful in 1m5s

The //go:embed static directive nests files under static/, so after
StripPrefix removes /static/ from the URL, the FileServer couldn't find
the files. Use fs.Sub to root the FS at the static/ subdirectory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-09 20:54:15 -04:00
parent 76b9f64141
commit da2d72e95d
+3 -1
View File
@@ -1,6 +1,7 @@
package httpserver package httpserver
import ( import (
"io/fs"
"net/http" "net/http"
"provisioning/internal/api" "provisioning/internal/api"
@@ -25,7 +26,8 @@ func NewRouter(d Deps) http.Handler {
r.Use(middleware.Logger) r.Use(middleware.Logger)
// Static files // Static files
r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.FS(web.Static)))) staticFS, _ := fs.Sub(web.Static, "static")
r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.FS(staticFS))))
// SSE // SSE
r.Get("/events", d.Hub.ServeSSE) r.Get("/events", d.Hub.ServeSSE)