fix: share CCTV startup and keep proxy diagnostics bounded

This commit is contained in:
Sameh Khamis committed 2026-09-10 23:01:51 -07:00
1 parent 8fc86e0780
commit f47cd792d1
6 files changed
+293 -217

No files matched your search

+12 -8
View File
@@ -1572,7 +1572,7 @@ function celestrakProxy() {
await fsp.mkdir(CACHE_DIR, { recursive: true });
await fsp.writeFile(diskPath(group), JSON.stringify(entry), 'utf8');
} catch (err) {
console.warn(`[celestrak-proxy] cache write failed for ${group}:`, err?.message || err);
console.warn('[celestrak-proxy] cache write failed');
}
}
@@ -1631,7 +1631,7 @@ function celestrakProxy() {
return fresh;
})
.catch((err) => {
console.warn(`[celestrak-proxy] ${group} refresh failed (${err?.message || err}) — serving cache if any`);
console.warn('[celestrak-proxy] refresh failed — serving cache if any');
return null;
})
.finally(() => inflight.delete(group)));
@@ -1645,6 +1645,7 @@ function celestrakProxy() {
send(502, 'celestrak fetch failed and no cache available', 'NONE');
}
} catch (err) {
console.error('[celestrak-proxy] request failed');
send(500, 'celestrak proxy error', 'ERROR');
}
});
@@ -1692,7 +1693,7 @@ function rocketLaunchesProxy() {
await fsp.mkdir(path.dirname(cachePath), { recursive: true });
await fsp.writeFile(cachePath, JSON.stringify(entry), 'utf8');
} catch (error) {
console.warn(`[launch-library-proxy] cache write failed: ${error?.message || error}`);
console.warn('[launch-library-proxy] cache write failed');
}
}
@@ -1721,7 +1722,6 @@ function rocketLaunchesProxy() {
if (!upstream.ok) {
const error = new Error(`upstream HTTP ${upstream.status}`);
error.upstreamStatus = upstream.status;
error.upstreamBody = body;
throw error;
}
const parsed = JSON.parse(body);
@@ -1750,14 +1750,16 @@ function rocketLaunchesProxy() {
const fresh = await request.promise;
send(res, 200, fresh.body, request.shared ? 'INFLIGHT' : 'MISS');
} catch (error) {
// Log only a bounded status, never upstream bodies, URLs, or credentials.
const status = Number.isInteger(error?.upstreamStatus) ? error.upstreamStatus : 502;
if (!request.shared) console.warn(`[launch-library-proxy] refresh failed (HTTP ${status})${stale ? ' — serving stale cache' : ''}`);
if (stale) {
if (!request.shared) console.warn(`[launch-library-proxy] refresh failed (${error?.message || error}) — serving stale cache`);
send(res, 200, stale.body, 'STALE-ERROR');
return;
}
send(
res,
Number.isInteger(error?.upstreamStatus) ? error.upstreamStatus : 502,
status,
JSON.stringify({ error: 'Launch Library 2 unavailable' }),
'NONE',
);
@@ -2296,7 +2298,7 @@ function terrainHeightsProxy() {
await fsp.writeFile(CACHE_PATH, JSON.stringify(obj), 'utf8');
} catch (err) {
diskDirty = true; // retry next tick
console.warn('[terrain-heights-proxy] cache write failed:', err?.message || err);
console.warn('[terrain-heights-proxy] cache write failed');
}
}, 15_000).unref?.();
}
@@ -2367,12 +2369,13 @@ function terrainHeightsProxy() {
if (outcome.cacheChanged) diskDirty = true;
if (outcome.upstreamError) {
console.warn(
`[terrain-heights-proxy] refresh incomplete (${outcome.upstreamError?.message || outcome.upstreamError})`
'[terrain-heights-proxy] refresh incomplete'
+ ' — serving stale points when available'
);
}
send(outcome.status, outcome.body);
} catch (err) {
console.error('[terrain-heights-proxy] request failed');
send(500, { error: 'terrain heights proxy error' });
}
});
@@ -2494,6 +2497,7 @@ function adsbdbProxy() {
}
return send(404, { error: 'unknown endpoint' });
} catch (err) {
console.error('[adsbdb-proxy] request failed');
return send(500, { error: 'adsbdb proxy error' });
}
});