← back to build-pages
api: add /api/health + /api/version (joins fleet-status digest)
27818e5794c6bcaaf2c01e0b26b85e43d459ddfe · 2026-05-13 12:32:09 -0700 · SteveStudio2
Files touched
Diff
commit 27818e5794c6bcaaf2c01e0b26b85e43d459ddfe
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date: Wed May 13 12:32:09 2026 -0700
api: add /api/health + /api/version (joins fleet-status digest)
---
server.js | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/server.js b/server.js
index 2d6be10..2d12bde 100644
--- a/server.js
+++ b/server.js
@@ -14,6 +14,21 @@ const exec = promisify(execFile);
const PORT = parseInt(process.env.PORT || '9700', 10);
const HOME = process.env.HOME;
+// Boot-cached version metadata so /api/version stays sub-1ms. git SHA is
+// best-effort — falls back to 'unknown' if git isn't on PATH at startup.
+const PKG_VERSION = (() => {
+ try { return require('./package.json').version || '0.0.0'; }
+ catch (_) { return '0.0.0'; }
+})();
+const GIT_SHA = (() => {
+ try {
+ return require('child_process')
+ .execSync('git rev-parse --short HEAD', { cwd: __dirname, stdio: ['ignore', 'pipe', 'ignore'] })
+ .toString().trim() || 'unknown';
+ } catch (_) { return 'unknown'; }
+})();
+const STARTED_AT_ISO = new Date().toISOString();
+
// Registry: kebab-slug → {name, repo, blurb}. Add a project by appending here.
// Slug is the URL path /p/<slug>; repo is an absolute path to the working tree.
const PROJECTS = {
@@ -160,6 +175,31 @@ app.get('/healthz', (_req, res) => {
res.json({ ok: true, ts: Date.now() });
});
+// /api/health — liveness + project count snapshot. Mirrors the asim/sod shape
+// so fleet-status.sh can render every site through one digest path.
+app.get('/api/health', (_req, res) => {
+ res.setHeader('Cache-Control', 'no-store');
+ res.json({
+ ok: true,
+ counts: { projects: Object.keys(PROJECTS).length },
+ uptime_s: Math.floor(process.uptime()),
+ ts: Date.now(),
+ as_of: new Date().toISOString(),
+ });
+});
+
+// /api/version — deploy fingerprint, sub-1ms (all resolved at boot).
+app.get('/api/version', (_req, res) => {
+ res.setHeader('Cache-Control', 'no-store');
+ res.json({
+ name: 'build-pages',
+ version: PKG_VERSION,
+ git: GIT_SHA,
+ node: process.version,
+ started_at: STARTED_AT_ISO,
+ });
+});
+
// Index — all projects.
app.get('/', (_req, res) => {
const rows = Object.entries(PROJECTS).map(([slug, p]) => {
← cd73726 initial scaffold — build-pages live git-as-DB doc site (port
·
back to build-pages
·
smoke: 23-assertion harness covering healthz, /api/health, / 6e35230 →