onlinemodus fix failed
This commit is contained in:
@@ -72,7 +72,14 @@ app.delete(/^\/db\/(.*)\.json$/, (req, res) => {
|
||||
});
|
||||
|
||||
// --- static game (same origin: no CORS, no mixed content) ------------------------------------------
|
||||
app.use(express.static(path.join(__dirname, '..', 'game')));
|
||||
app.use(express.static(path.join(__dirname, '..', 'game'), {
|
||||
etag: true,
|
||||
setHeaders(res, p) {
|
||||
// images / fonts / audio rarely change -> cache hard (fast re-renders, no re-fetch flicker)
|
||||
if (/\.(png|jpe?g|webp|gif|svg|woff2?|ttf|otf|mp3|ogg|wav|m4a)$/i.test(p)) res.setHeader('Cache-Control', 'public, max-age=31536000, immutable');
|
||||
else res.setHeader('Cache-Control', 'no-cache'); // code/html: revalidate so deploys show up
|
||||
},
|
||||
}));
|
||||
|
||||
const PORT = process.env.PORT || 8080;
|
||||
app.listen(PORT, () => console.log('Robot Clash server on :' + PORT));
|
||||
|
||||
15
server/db.js
15
server/db.js
@@ -29,13 +29,26 @@ function resolveSV(v) {
|
||||
}
|
||||
|
||||
// --- RTDB-like tree over the nodes table ---------------------------------------------------------
|
||||
// objects are stored as ONE json node, so a deep path (e.g. matches/<id>/meta/seed) has no own row -
|
||||
// read it from the nearest ancestor blob by descending into its parsed json (Firebase-like deep reads)
|
||||
function readInside(p) {
|
||||
const seg = p.split('/');
|
||||
for (let i = seg.length - 1; i >= 1; i--) {
|
||||
const row = db.prepare('SELECT data FROM nodes WHERE path = ?').get(seg.slice(0, i).join('/'));
|
||||
if (!row) continue;
|
||||
let v = parse(row.data);
|
||||
for (let j = i; j < seg.length; j++) { if (v && typeof v === 'object' && !Array.isArray(v)) v = v[seg[j]]; else { v = undefined; break; } }
|
||||
return v === undefined ? null : v;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
function getTree(p) {
|
||||
p = norm(p);
|
||||
const like = p ? p + '/%' : '%';
|
||||
const rows = p
|
||||
? db.prepare('SELECT path, data FROM nodes WHERE path = ? OR path LIKE ?').all(p, like)
|
||||
: db.prepare('SELECT path, data FROM nodes').all();
|
||||
if (!rows.length) return null;
|
||||
if (!rows.length) return p ? readInside(p) : null;
|
||||
let result;
|
||||
rows.sort((a, b) => a.path.length - b.path.length);
|
||||
for (const row of rows) {
|
||||
|
||||
Reference in New Issue
Block a user