diff --git a/internal/server/server.go b/internal/server/server.go index 33b574e..e62e360 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -8,6 +8,7 @@ import ( "context" "encoding/json" "fmt" + "io/fs" "log" "net/http" "os" @@ -53,14 +54,15 @@ func loadConfig(path string) (Config, error) { // ── Server ──────────────────────────────────────────────────────────────────── type Server struct { - cfg Config - wa *winamp.Controller - kl *killist.KillList - hub *hub - mux *http.ServeMux + cfg Config + wa *winamp.Controller + kl *killist.KillList + hub *hub + mux *http.ServeMux + staticFS fs.FS } -func New(configPath string) (*Server, error) { +func New(configPath string, staticFS fs.FS) (*Server, error) { cfg, err := loadConfig(configPath) if err != nil { return nil, fmt.Errorf("config: %w", err) @@ -69,7 +71,7 @@ func New(configPath string) (*Server, error) { if err != nil { return nil, fmt.Errorf("killist: %w", err) } - s := &Server{cfg: cfg, wa: winamp.New(), kl: kl, mux: http.NewServeMux()} + s := &Server{cfg: cfg, wa: winamp.New(), kl: kl, mux: http.NewServeMux(), staticFS: staticFS} s.hub = newHub(s.handleCommand) s.routes() return s, nil @@ -90,7 +92,7 @@ func (s *Server) Run() error { // ── Routes ──────────────────────────────────────────────────────────────────── func (s *Server) routes() { - s.mux.Handle("/", http.FileServer(http.Dir("web/static"))) + s.mux.Handle("/", http.FileServer(http.FS(s.staticFS))) // WebSocket (primary interface) s.mux.HandleFunc("/ws", s.handleWS) diff --git a/web/embed.go b/web/embed.go new file mode 100644 index 0000000..d639340 --- /dev/null +++ b/web/embed.go @@ -0,0 +1,7 @@ +// Package web embeds the frontend static files into the binary. +package web + +import "embed" + +//go:embed static +var FS embed.FS