Fix static file serving by using fs.Sub on embed FS
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:
@@ -1,6 +1,7 @@
|
||||
package httpserver
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
|
||||
"provisioning/internal/api"
|
||||
@@ -25,7 +26,8 @@ func NewRouter(d Deps) http.Handler {
|
||||
r.Use(middleware.Logger)
|
||||
|
||||
// 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
|
||||
r.Get("/events", d.Hub.ServeSSE)
|
||||
|
||||
Reference in New Issue
Block a user