From aa676150eb4cc803fe3de10f186a083f44a1c658 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Thu, 12 Oct 2023 21:26:11 +0800 Subject: [PATCH] Fix shutdown issue and tidy up --- server/server.js | 6 +----- server/util-server.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/server/server.js b/server/server.js index 2b9bed17..e48c720d 100644 --- a/server/server.js +++ b/server/server.js @@ -38,7 +38,6 @@ if (!semver.satisfies(nodeVersion, requiredNodeVersions)) { const args = require("args-parser")(process.argv); const { sleep, log, getRandomInt, genSecret, isDev } = require("../src/util"); -const config = require("./config"); log.info("server", "Welcome to Uptime Kuma"); log.debug("server", "Arguments"); @@ -71,6 +70,7 @@ const notp = require("notp"); const base32 = require("thirty-two"); const { UptimeKumaServer } = require("./uptime-kuma-server"); + const server = UptimeKumaServer.getInstance(args); const io = module.exports.io = server.io; const app = server.app; @@ -135,10 +135,6 @@ const twoFAVerifyOptions = { const testMode = !!args["test"] || false; const e2eTestMode = !!args["e2e"] || false; -if (config.demoMode) { - log.info("server", "==== Demo Mode ===="); -} - // Must be after io instantiation const { sendNotificationList, sendHeartbeatList, sendInfo, sendProxyList, sendDockerHostList, sendAPIKeyList } = require("./client"); const { statusPageSocketHandler } = require("./socket-handlers/status-page-socket-handler"); diff --git a/server/util-server.js b/server/util-server.js index 5f47561c..18107384 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -29,9 +29,6 @@ const { }, } = require("node-radius-utils"); const dayjs = require("dayjs"); -const readline = require("readline"); -const rl = readline.createInterface({ input: process.stdin, - output: process.stdout }); // SASLOptions used in JSDoc // eslint-disable-next-line no-unused-vars @@ -1079,7 +1076,15 @@ module.exports.shake256 = (data, len) => { .digest("hex"); }; -module.exports.prompt = (query) => new Promise((resolve) => rl.question(query, resolve)); +/** + * Non await sleep + * Source: https://stackoverflow.com/questions/59099454/is-there-a-way-to-call-sleep-without-await-keyword + * @param {number} n Milliseconds to wait + * @returns {void} + */ +module.exports.wait = (n) => { + Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n); +}; // For unit test, export functions if (process.env.TEST_BACKEND) {