added static page at buildtime
This commit is contained in:
parent
55d723997d
commit
ec65e3494c
16
main.go
16
main.go
|
|
@ -4,11 +4,13 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
@ -30,6 +32,9 @@ import (
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed static
|
||||||
|
var embeddedStaticFiles embed.FS
|
||||||
|
|
||||||
const version = "1.0.0"
|
const version = "1.0.0"
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
@ -2318,8 +2323,8 @@ async function activate(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// License OK — serve the full dashboard template
|
// License OK — serve the full dashboard template from the embedded static files
|
||||||
tmpl, err := template.ParseFiles(filepath.Join("static", "index.html"))
|
tmpl, err := template.ParseFS(embeddedStaticFiles, "static/index.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("template parse error: %v", err)
|
log.Printf("template parse error: %v", err)
|
||||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||||
|
|
@ -2715,8 +2720,11 @@ func main() {
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
|
|
||||||
staticDir := http.Dir("static")
|
staticFS, err := fs.Sub(embeddedStaticFiles, "static")
|
||||||
fileServer := http.FileServer(staticDir)
|
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.Handle("/static/", http.StripPrefix("/static/", fileServer))
|
||||||
mux.HandleFunc("/", serveUI)
|
mux.HandleFunc("/", serveUI)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue