refactor hub dev server

- moved html replacement functionality from vite to go
This commit is contained in:
henrygd
2025-09-01 22:16:57 -04:00
parent fadfc5d81d
commit 86e87f0d47
4 changed files with 62 additions and 12 deletions

View File

@@ -24,9 +24,9 @@ func (h *Hub) startServer(se *core.ServeEvent) error {
// fix base paths in html if using subpath
basePath := strings.TrimSuffix(parsedURL.Path, "/") + "/"
indexFile, _ := fs.ReadFile(site.DistDirFS, "index.html")
indexContent := strings.ReplaceAll(string(indexFile), "./", basePath)
indexContent = strings.Replace(indexContent, "{{V}}", beszel.Version, 1)
indexContent = strings.Replace(indexContent, "{{HUB_URL}}", h.appURL, 1)
html := strings.ReplaceAll(string(indexFile), "./", basePath)
html = strings.Replace(html, "{{V}}", beszel.Version, 1)
html = strings.Replace(html, "{{HUB_URL}}", h.appURL, 1)
// set up static asset serving
staticPaths := [2]string{"/static/", "/assets/"}
serveStatic := apis.Static(site.DistDirFS, false)
@@ -45,7 +45,7 @@ func (h *Hub) startServer(se *core.ServeEvent) error {
e.Response.Header().Del("X-Frame-Options")
e.Response.Header().Set("Content-Security-Policy", csp)
}
return e.HTML(http.StatusOK, indexContent)
return e.HTML(http.StatusOK, html)
})
return nil
}