fix(web): read the interface build date instead of freezing it at startup
The marker was captured once at import, while the front-end is served from disk on every request. Uploading new files therefore left it announcing the old build until the next restart — the exact confusion it was added to prevent. It is now read from disk, cached ten seconds so a health check does not walk the tree each time. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 file changed
+20
-4
+20
-4
@@ -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 },
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user