Allow setting the path to the games backup in the server

This commit is contained in:
Laurent Mazet 2020-04-29 08:15:32 +02:00 committed by Raphaël Jakse
parent 9fad558c24
commit 01d13f4dec
1 changed files with 3 additions and 2 deletions

View File

@ -30,6 +30,7 @@
const port = parseInt(process.env.TRIVABBLE_PORT || "3000");
const SAVE_TIMEOUT = 5000;
const KEEP_ALIVE = 30000;
const GAMES_BACKUP = process.env.TRIVABBLE_GAMES_BACKUP || "games.backup.json";
const VERSION = 202004281800;
@ -126,7 +127,7 @@ const server = http.createServer(handleRequest);
server.setTimeout(0); // The default in node 13 is 0. Earlier versions have 120.
function saveGames(callback) {
fs.writeFile("games.backup.json", JSON.stringify(games), function (err) {
fs.writeFile(GAMES_BACKUP, JSON.stringify(games), function (err) {
if (err) {
console.error("ERROR: Cannot save games!");
}
@ -1040,7 +1041,7 @@ function handleRequest(request, response) {
});
}
fs.readFile("games.backup.json", function (err, data) {
fs.readFile(GAMES_BACKUP, function (err, data) {
try {
if (err) {
console.error("WARNING: Could not restore previous backup of the games");