From d56b3f456b2af69b76e9d811221ef9cd2b19b48c Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Tue, 9 Nov 2021 13:17:53 +0100 Subject: [PATCH] Writing points to instance-specific file. --- src/app.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app.js b/src/app.js index 5750bdd..728c0ba 100644 --- a/src/app.js +++ b/src/app.js @@ -8,6 +8,7 @@ const fs = require('fs').promises; const logger = require('simple-node-logger').createSimpleLogger(); const { argv } = require('yargs'); +const instance = process.env.NODE_APP_INSTANCE || 'main'; const points = {}; logger.setLevel(argv.level || 'info'); @@ -66,7 +67,7 @@ async function setPoints(gameKey, user, value, mode = 'add') { points[gameKey][userKey] = value; } - await fs.writeFile('./points.json', JSON.stringify(points, null, 4)); + await fs.writeFile(`./points-${instance}.json`, JSON.stringify(points, null, 4)); } function getPoints(game, { user, room }) { @@ -188,14 +189,14 @@ const messageHandlers = { async function initPoints() { try { - const pointsFile = await fs.readFile('./points.json', 'utf-8'); + const pointsFile = await fs.readFile(`./points-${instance}.json`, 'utf-8'); Object.assign(points, JSON.parse(pointsFile)); } catch (error) { if (error.code === 'ENOENT') { logger.info('Creating new points file'); - await fs.writeFile('./points.json', '{}'); + await fs.writeFile(`./points-${instance}.json`, '{}'); initPoints(); } }