diff --git a/main.go b/main.go index aa46825..06f2771 100644 --- a/main.go +++ b/main.go @@ -4,11 +4,13 @@ import ( "bytes" "context" "database/sql" + "embed" "encoding/json" "errors" "fmt" "html/template" "io" + "io/fs" "log" "math" "net/http" @@ -30,6 +32,9 @@ import ( "gopkg.in/yaml.v3" ) +//go:embed static +var embeddedStaticFiles embed.FS + const version = "1.0.0" // --------------------------------------------------------------------------- @@ -2318,8 +2323,8 @@ async function activate(){ } } - // License OK — serve the full dashboard template - tmpl, err := template.ParseFiles(filepath.Join("static", "index.html")) + // License OK — serve the full dashboard template from the embedded static files + tmpl, err := template.ParseFS(embeddedStaticFiles, "static/index.html") if err != nil { log.Printf("template parse error: %v", err) http.Error(w, "Internal Server Error", http.StatusInternalServerError) @@ -2715,8 +2720,11 @@ func main() { mux := http.NewServeMux() - staticDir := http.Dir("static") - fileServer := http.FileServer(staticDir) + staticFS, err := fs.Sub(embeddedStaticFiles, "static") + if err != nil { + log.Fatalf("failed to prepare embedded static files: %v", err) + } + fileServer := http.FileServer(http.FS(staticFS)) mux.Handle("/static/", http.StripPrefix("/static/", fileServer)) mux.HandleFunc("/", serveUI)