refactor: convert all static HTML to EJS with cssHash cache-busting, remove stale html files
This commit is contained in:
@@ -60,7 +60,7 @@ function escapeHtmlSSR(str: string): string {
|
||||
return str.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
|
||||
}
|
||||
|
||||
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", {}));
|
||||
|
||||
Reference in New Issue
Block a user