feat: show version in nav

This commit is contained in:
2026-02-04 21:47:46 -08:00
parent 4327750d2a
commit 5eae636f2f
2 changed files with 52 additions and 2 deletions
+30
View File
@@ -0,0 +1,30 @@
import type { FastifyInstance } from "fastify";
import { readFileSync } from "fs";
import { join } from "path";
interface PackageJson {
version: string;
}
let cachedVersion: string | null = null;
function getVersion(): string {
if (cachedVersion) {
return cachedVersion;
}
try {
const packageJsonPath = join(process.cwd(), "package.json");
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as PackageJson;
cachedVersion = packageJson.version;
return cachedVersion;
} catch {
return "unknown";
}
}
export default async function (app: FastifyInstance): Promise<void> {
app.get("/", async (_request, reply) => {
reply.send({ version: getVersion() });
});
}