refactor: convert all static HTML to EJS with cssHash cache-busting, remove stale html files

This commit is contained in:
M1
2026-03-17 09:54:44 +04:00
parent ac693e55e0
commit 5c91cbc522
10 changed files with 15 additions and 757 deletions
+6 -4
View File
@@ -60,7 +60,7 @@ function escapeHtmlSSR(str: string): string {
return str.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
}
function html(template: string, data: Record<string, unknown> = {}) {
export function html(template: string, data: Record<string, unknown> = {}) {
return new Response(eta.render(template, { ...data, timeAgoSSR, sparklineSSR, latencyChartSSR, escapeHtmlSSR, cssHash }), {
headers: { "content-type": "text/html; charset=utf-8" },
});
@@ -82,6 +82,8 @@ async function getAccountId(cookie: any, headers: any): Promise<string | null> {
const dashDir = resolve(import.meta.dir, "../dashboard");
export const dashboard = new Elysia()
.get("/", () => html("landing", {}))
.get("/dashboard/app.js", () => new Response(Bun.file(`${dashDir}/app.js`), { headers: { "cache-control": "public, max-age=31536000, immutable" } }))
.get("/dashboard/app.css", () => new Response(Bun.file(`${dashDir}/app.css`), { headers: { "cache-control": "public, max-age=31536000, immutable" } }))
.get("/dashboard/tailwind.css", () => new Response(Bun.file(`${dashDir}/tailwind.css`), { headers: { "cache-control": "public, max-age=31536000, immutable" } }))
@@ -96,7 +98,7 @@ export const dashboard = new Elysia()
// Invalid/stale key — clear it and show login
cookie.pingql_key?.remove();
}
return Bun.file(`${dashDir}/index.html`);
return html("login", {});
})
// Logout
@@ -235,5 +237,5 @@ export const dashboard = new Elysia()
})
// Docs
.get("/docs", () => Bun.file(`${dashDir}/docs.html`))
.get("/privacy", () => Bun.file(`${dashDir}/privacy.html`));
.get("/docs", () => html("docs", {}))
.get("/privacy", () => html("privacy", {}));