From b0d6b5b13d59de628eeb8820cfb3023d8501566a Mon Sep 17 00:00:00 2001 From: George Tsomlektsis Date: Mon, 3 Oct 2022 17:48:34 +0300 Subject: [PATCH 1/3] Fixed entry route not redirecting correctly when the status entry page changes slug. --- server/server.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server/server.js b/server/server.js index 0c9a45e6..0f215245 100644 --- a/server/server.js +++ b/server/server.js @@ -155,7 +155,9 @@ let needSetup = false; Database.init(args); await initDatabase(testMode); - exports.entryPage = await setting("entryPage"); + const entryPage = (await getSettings("general"))["entryPage"]; + exports.entryPage = entryPage; + UptimeKumaServer.getInstance().entryPage = entryPage; await StatusPage.loadDomainMappingList(); log.info("server", "Adding route"); @@ -176,14 +178,15 @@ let needSetup = false; log.debug("entry", `Request Domain: ${hostname}`); + const uptimeKumaEntryPage=UptimeKumaServer.getInstance().entryPage; if (hostname in StatusPage.domainMappingList) { log.debug("entry", "This is a status page domain"); let slug = StatusPage.domainMappingList[hostname]; await StatusPage.handleStatusPageResponse(response, server.indexHTML, slug); - } else if (exports.entryPage && exports.entryPage.startsWith("statusPage-")) { - response.redirect("/status/" + exports.entryPage.replace("statusPage-", "")); + } else if (uptimeKumaEntryPage && uptimeKumaEntryPage.startsWith('statusPage-')) { + response.redirect("/status/" + uptimeKumaEntryPage.replace("statusPage-", "")); } else { response.redirect("/dashboard"); @@ -200,7 +203,7 @@ let needSetup = false; // Robots.txt app.get("/robots.txt", async (_request, response) => { let txt = "User-agent: *\nDisallow:"; - if (! await setting("searchEngineIndex")) { + if (!await setting("searchEngineIndex")) { txt += " /"; } response.setHeader("Content-Type", "text/plain"); @@ -1085,6 +1088,7 @@ let needSetup = false; await setSettings("general", data); exports.entryPage = data.entryPage; + UptimeKumaServer.getInstance().entryPage = data.entryPage; callback({ ok: true, From 3e699f8ac3c544cd0dd7d9459ef9b8da3c7efd65 Mon Sep 17 00:00:00 2001 From: George Tsomlektsis Date: Mon, 3 Oct 2022 18:01:52 +0300 Subject: [PATCH 2/3] Fix linting errors. --- server/server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/server.js b/server/server.js index 0f215245..620e5bb4 100644 --- a/server/server.js +++ b/server/server.js @@ -178,14 +178,14 @@ let needSetup = false; log.debug("entry", `Request Domain: ${hostname}`); - const uptimeKumaEntryPage=UptimeKumaServer.getInstance().entryPage; + const uptimeKumaEntryPage = UptimeKumaServer.getInstance().entryPage; if (hostname in StatusPage.domainMappingList) { log.debug("entry", "This is a status page domain"); let slug = StatusPage.domainMappingList[hostname]; await StatusPage.handleStatusPageResponse(response, server.indexHTML, slug); - } else if (uptimeKumaEntryPage && uptimeKumaEntryPage.startsWith('statusPage-')) { + } else if (uptimeKumaEntryPage && uptimeKumaEntryPage.startsWith("statusPage-")) { response.redirect("/status/" + uptimeKumaEntryPage.replace("statusPage-", "")); } else { From ad1a7c255f214d2ce0be9d71d0d232d246fb64f9 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sat, 8 Oct 2022 23:56:58 +0800 Subject: [PATCH 3/3] Drop exports.entryPage fully --- server/server.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/server/server.js b/server/server.js index 620e5bb4..2efad753 100644 --- a/server/server.js +++ b/server/server.js @@ -127,6 +127,7 @@ const StatusPage = require("./model/status_page"); const { cloudflaredSocketHandler, autoStart: cloudflaredAutoStart, stop: cloudflaredStop } = require("./socket-handlers/cloudflared-socket-handler"); const { proxySocketHandler } = require("./socket-handlers/proxy-socket-handler"); const { dockerSocketHandler } = require("./socket-handlers/docker-socket-handler"); +const { Settings } = require("./settings"); app.use(express.json()); @@ -155,9 +156,7 @@ let needSetup = false; Database.init(args); await initDatabase(testMode); - const entryPage = (await getSettings("general"))["entryPage"]; - exports.entryPage = entryPage; - UptimeKumaServer.getInstance().entryPage = entryPage; + server.entryPage = await Settings.get("entryPage"); await StatusPage.loadDomainMappingList(); log.info("server", "Adding route"); @@ -178,7 +177,7 @@ let needSetup = false; log.debug("entry", `Request Domain: ${hostname}`); - const uptimeKumaEntryPage = UptimeKumaServer.getInstance().entryPage; + const uptimeKumaEntryPage = server.entryPage; if (hostname in StatusPage.domainMappingList) { log.debug("entry", "This is a status page domain"); @@ -1087,8 +1086,7 @@ let needSetup = false; } await setSettings("general", data); - exports.entryPage = data.entryPage; - UptimeKumaServer.getInstance().entryPage = data.entryPage; + server.entryPage = data.entryPage; callback({ ok: true,