refactor: ETA templating engine for dashboard, shared nav/head/foot partials

This commit is contained in:
M1
2026-03-16 15:14:26 +04:00
parent 389c88e124
commit e36c239000
9 changed files with 724 additions and 10 deletions
+24 -10
View File
@@ -1,16 +1,30 @@
import { Elysia } from "elysia";
import { Eta } from "eta";
import { resolve } from "path";
const dir = resolve(import.meta.dir, "../dashboard");
const eta = new Eta({ views: resolve(import.meta.dir, "../views"), cache: true, defaultExtension: ".ejs" });
const hide = { detail: { hide: true } };
function render(template: string, data: Record<string, unknown> = {}) {
return new Response(eta.render(template, data), {
headers: { "content-type": "text/html; charset=utf-8" },
});
}
// Static dashboard assets
const dashDir = resolve(import.meta.dir, "../dashboard");
export const dashboard = new Elysia()
.get("/dashboard/app.js", () => Bun.file(`${dir}/app.js`), hide)
.get("/dashboard/query-builder.js", () => Bun.file(`${dir}/query-builder.js`), hide)
.get("/dashboard", () => Bun.file(`${dir}/index.html`), hide)
.get("/dashboard/home", () => Bun.file(`${dir}/home.html`), hide)
.get("/dashboard/monitors/new", () => Bun.file(`${dir}/new.html`), hide)
.get("/dashboard/monitors/:id", () => Bun.file(`${dir}/detail.html`), hide)
.get("/dashboard/settings", () => Bun.file(`${dir}/settings.html`), hide)
.get("/docs", () => Bun.file(`${dir}/docs.html`), hide);
.get("/dashboard/app.js", () => Bun.file(`${dashDir}/app.js`))
.get("/dashboard/query-builder.js",() => Bun.file(`${dashDir}/query-builder.js`))
// Auth / login page (static — no nav needed)
.get("/dashboard", () => Bun.file(`${dashDir}/index.html`))
// Rendered pages
.get("/dashboard/home", () => render("home", { nav: "monitors" }))
.get("/dashboard/settings", () => render("settings", { nav: "settings" }))
.get("/dashboard/monitors/new", () => render("new", { nav: "monitors" }))
.get("/dashboard/monitors/:id", () => render("detail", { nav: "monitors" }))
// Docs (static)
.get("/docs", () => Bun.file(`${dashDir}/docs.html`));