From 5c8956265048aee726f236bd83b4988a592242f4 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sun, 10 Oct 2021 02:23:27 +0800 Subject: [PATCH 1/2] not allow lower than 20s for demo mode --- server/model/monitor.js | 8 ++++++++ server/server.js | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index a50baccfd..b7b24971b 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -11,6 +11,7 @@ const { tcping, ping, dnsResolve, checkCertificate, checkStatusCode, getTotalCli const { R } = require("redbean-node"); const { BeanModel } = require("redbean-node/dist/bean-model"); const { Notification } = require("../notification"); +const { demoMode } = require("../server"); const version = require("../../package.json").version; /** @@ -334,6 +335,13 @@ class Monitor extends BeanModel { previousBeat = bean; if (! this.isStop) { + + if (demoMode) { + if (beatInterval < 20) { + beatInterval = 20; + } + } + this.heartbeatInterval = setTimeout(beat, beatInterval * 1000); } diff --git a/server/server.js b/server/server.js index ddd686951..984e73ad1 100644 --- a/server/server.js +++ b/server/server.js @@ -66,12 +66,13 @@ const sslCert = process.env.SSL_CERT || args["ssl-cert"] || undefined; // Demo Mode? const demoMode = args["demo"] || false; +exports.demoMode = demoMode; if (demoMode) { console.log("==== Demo Mode ===="); } -console.log("Creating express and socket.io instance") +console.log("Creating express and socket.io instance"); const app = express(); let server; From 56ae6f6117809d5d4c552ce3a5cfb50abed7b388 Mon Sep 17 00:00:00 2001 From: LouisLam Date: Sun, 10 Oct 2021 02:36:20 +0800 Subject: [PATCH 2/2] fix demoMode export --- server/model/monitor.js | 1 + server/server.js | 16 ++++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index b7b24971b..3c9e79b54 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -338,6 +338,7 @@ class Monitor extends BeanModel { if (demoMode) { if (beatInterval < 20) { + console.log("beat interval too low, reset to 20s"); beatInterval = 20; } } diff --git a/server/server.js b/server/server.js index 984e73ad1..cdbb447a7 100644 --- a/server/server.js +++ b/server/server.js @@ -1,12 +1,18 @@ console.log("Welcome to Uptime Kuma"); +const args = require("args-parser")(process.argv); +const { sleep, debug, getRandomInt } = require("../src/util"); + +debug(args); if (! process.env.NODE_ENV) { process.env.NODE_ENV = "production"; } -console.log("Node Env: " + process.env.NODE_ENV); +// Demo Mode? +const demoMode = args["demo"] || false; +exports.demoMode = demoMode; -const { sleep, debug, TimeLogger, getRandomInt } = require("../src/util"); +console.log("Node Env: " + process.env.NODE_ENV); console.log("Importing Node libraries"); const fs = require("fs"); @@ -50,8 +56,6 @@ const { basicAuth } = require("./auth"); const { login } = require("./auth"); const passwordHash = require("./password-hash"); -const args = require("args-parser")(process.argv); - const checkVersion = require("./check-version"); console.info("Version: " + checkVersion.version); @@ -64,10 +68,6 @@ const port = parseInt(process.env.PORT || args.port || 3001); const sslKey = process.env.SSL_KEY || args["ssl-key"] || undefined; const sslCert = process.env.SSL_CERT || args["ssl-cert"] || undefined; -// Demo Mode? -const demoMode = args["demo"] || false; -exports.demoMode = demoMode; - if (demoMode) { console.log("==== Demo Mode ===="); }