diff --git a/src/web/api/index.js b/src/web/api/index.js index 8380504..4447809 100644 --- a/src/web/api/index.js +++ b/src/web/api/index.js @@ -32,7 +32,20 @@ const VERSION = (() => { * Deployments that ship an archive make it easy to look at a stale copy and * wonder why a fix is missing; this gives the page something to state. */ -const BUILD_AT = (() => { +/** + * Newest file of the served interface. + * + * Read from disk rather than frozen at startup: the front-end is served from + * disk on every request, so a marker captured at boot would keep announcing an + * old build after an upload — the exact confusion it exists to prevent. Cached + * briefly so a health check does not walk the tree each time. + */ +const BUILD_TTL_MS = 10_000; +let buildCache = { at: null, readAt: 0 }; + +function buildAt() { + if (buildCache.readAt && Date.now() - buildCache.readAt < BUILD_TTL_MS) return buildCache.at; + const root = path.join(here, '../public'); let newest = 0; @@ -47,10 +60,13 @@ const BUILD_AT = (() => { try { walk(root); } catch { + buildCache = { at: null, readAt: Date.now() }; return null; } - return newest > 0 ? new Date(newest).toISOString() : null; -})(); + + buildCache = { at: newest > 0 ? new Date(newest).toISOString() : null, readAt: Date.now() }; + return buildCache.at; +} /** * Route registration order matters only for readability: the router matches on @@ -66,7 +82,7 @@ export function registerApiRoutes(router, { setupOnly = false } = {}) { setupOnly: context.setupOnly, uptimeMs: Date.now() - context.startedAt, version: VERSION, - buildAt: BUILD_AT, + buildAt: buildAt(), }), { public: true }, );