Allow setting the path to the games backup in the server
authorLaurent Mazet <mazet@softndesign.org>
Wed, 29 Apr 2020 06:15:32 +0000 (08:15 +0200)
committerRaphaël Jakse <raphael.trivabble@jakse.fr>
Wed, 29 Apr 2020 06:15:55 +0000 (08:15 +0200)
trivabble-server.js

index 8b6fda2bbf67ad7f594db392735e7a0e24b67373..6f511e3bc4cbd38e512c535ba8c749cca44656d5 100644 (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");