From ec65e3494c450093cacdb64ba36c5337f6941dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dejan=20Ro=C5=BEi=C4=8D?= Date: Tue, 21 Apr 2026 06:58:21 +0200 Subject: [PATCH] added static page at buildtime --- main.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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)