feat(server/m7-363): branding-aware index handler with html/template

This commit is contained in:
2026-05-03 17:21:30 -04:00
parent 46ea9a761a
commit 004d935512
4 changed files with 137 additions and 3 deletions
+12 -2
View File
@@ -10,6 +10,8 @@ import (
"net/http"
"path"
"strings"
"git.fabledsword.com/bvandeusen/minstrel/internal/config"
)
//go:embed all:build
@@ -24,7 +26,10 @@ var buildFS embed.FS
//
// Callers are expected to register this as the router's NotFound/catch-all so
// explicitly-routed paths (like /api/* and /rest/*) take precedence.
func Handler() http.Handler {
//
// The branding parameter is applied to index.html once at construction via
// html/template; all requests serve the resulting cached bytes.
func Handler(branding config.BrandingConfig) http.Handler {
sub, err := fs.Sub(buildFS, "build")
if err != nil {
// fs.Sub on a valid embed path can only fail if the embed directive
@@ -32,11 +37,16 @@ func Handler() http.Handler {
panic("web: fs.Sub(build) failed: " + err.Error())
}
index, err := fs.ReadFile(sub, "index.html")
raw, err := fs.ReadFile(sub, "index.html")
if err != nil {
panic("web: embedded build/index.html missing: " + err.Error())
}
index, err := applyBrandingTemplate(string(raw), branding)
if err != nil {
panic("web: branding template failed: " + err.Error())
}
fileServer := http.FileServer(http.FS(sub))
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {