Fix print page vendor load + persist authored scene across deploys

This commit is contained in:
2026-07-07 17:47:31 +10:00
parent f7de2c3b1f
commit 040b4006d8
3 changed files with 22 additions and 9 deletions
+13 -4
View File
@@ -13,9 +13,17 @@ const PORT = process.env.PORT || 34034;
const TICK_HZ = Number(process.env.TICK_HZ || 20); // server broadcast rate
// ---- Load scene ----------------------------------------------------------
// Two files:
// data/scene.json -> committed "seed" (tracked in git). Default/first-run.
// data/scene.live.json -> authored scene written by the admin (git-IGNORED),
// so `git reset --hard` on deploy never clobbers it.
// We read live if it exists, else fall back to the seed. Saves always go to live.
const SEED_PATH = join(ROOT, 'data', 'scene.json');
const LIVE_PATH = join(ROOT, 'data', 'scene.live.json');
function loadScene() {
const raw = readFileSync(join(ROOT, 'data', 'scene.json'), 'utf-8');
return JSON.parse(raw);
const path = existsSync(LIVE_PATH) ? LIVE_PATH : SEED_PATH;
return JSON.parse(readFileSync(path, 'utf-8'));
}
let scene = loadScene();
@@ -129,7 +137,7 @@ app.post('/api/scene', (req, res) => {
if (err) return res.status(400).json({ ok: false, error: err });
try {
const dataDir = join(ROOT, 'data');
const target = join(dataDir, 'scene.json');
const target = LIVE_PATH; // authored scene -> live file (survives deploys)
// timestamped backup so a bad save is always recoverable
const backupDir = join(dataDir, 'backups');
if (!existsSync(backupDir)) mkdirSync(backupDir, { recursive: true });
@@ -205,5 +213,6 @@ setInterval(() => {
httpServer.listen(PORT, () => {
console.log(`Newbury exhibit sync server on :${PORT} (broadcast ${TICK_HZ}Hz)`);
console.log(` Viewer: http://localhost:${PORT}/`);
console.log(` Scene: ${scene.spawns.length} spawns, ${scene.anchors.length} anchors`);
console.log(` Scene: ${scene.spawns.length} spawns, ${scene.anchors.length} anchors` +
` (${existsSync(LIVE_PATH) ? 'live: scene.live.json' : 'seed: scene.json'})`);
});