added static page at buildtime

This commit is contained in:
Dejan Rožič 2026-04-21 06:58:21 +02:00
parent 55d723997d
commit ec65e3494c

16
main.go
View file

@ -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)