]> git.cworth.org Git - zombocom-ai/commitdiff
And now read in saved comments at server start
authorCarl Worth <cworth@cworth.org>
Wed, 7 Dec 2022 06:02:26 +0000 (22:02 -0800)
committerCarl Worth <cworth@cworth.org>
Wed, 7 Dec 2022 06:03:21 +0000 (22:03 -0800)
So we should now have persistent messages across server restarts.

index.js

index 9279c877250c9e6055d142f9839dddd22dae775d..5e88926ae3e29db5bf7161a44e0deb10eb008d13 100644 (file)
--- a/index.js
+++ b/index.js
@@ -8,7 +8,17 @@ const { Server } = require("socket.io");
 const io = new Server(server);
 const port = 2122;
 
-comments = [];
+const state_file = 'zombocom-state.json'
+
+var comments;
+
+// Load comments at server startup
+fs.readFile(state_file, (err, data) => {
+    if (err)
+        comments = [];
+    else
+        comments = JSON.parse(data);
+});
 
 // Save comments when server is shutting down
 function cleanup() {