diff --git a/server/routers/api-router.js b/server/routers/api-router.js new file mode 100644 index 00000000..1c2ff9ea --- /dev/null +++ b/server/routers/api-router.js @@ -0,0 +1,50 @@ +let express = require("express"); +const { allowDevAllOrigin, getSettings } = require("../util-server"); +const { R } = require("redbean-node"); +let router = express.Router(); + +// Status Page Config +router.get("/api/status-page/config", async (_request, response) => { + allowDevAllOrigin(response); + let config = getSettings("statusPage"); + + if (! config.statusPageTheme) { + config.statusPageTheme = "light"; + } + + response.json(config); +}); + +// Status Page - Monitor List +router.get("/api/status-page/monitor-list", async (_request, response) => { + allowDevAllOrigin(response); + + const monitorList = {}; + let list = await R.find("monitor", " public = 1 ORDER BY weight DESC, name ", [ + ]); + + for (let monitor of list) { + monitorList[monitor.id] = await monitor.toJSON(); + } + + response.json(monitorList); +}); + +// Status Page Polling Data +router.get("/api/status-page/heartbeat", async (_request, response) => { + allowDevAllOrigin(response); + + const monitorList = {}; + let list = await R.find("", " ", [ + ]) + + for (let monitor of list) { + monitorList[monitor.id] = await monitor.toJSON(); + } + + response.json({ + monitorList: monitorList, + }); +}); + +module.exports = router; diff --git a/server/server.js b/server/server.js index 226b3abc..71e52ca1 100644 --- a/server/server.js +++ b/server/server.js @@ -157,53 +157,9 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString(); response.redirect("https://github.com/louislam/uptime-kuma/wiki/Reset-Password-via-CLI"); }); - // *************************** - // Public API - // *************************** - - // Status Page Config - app.get("/api/status-page/config", async (_request, response) => { - allowDevAllOrigin(response); - let config = getSettings("statusPage"); - - if (! config.statusPageTheme) { - config.statusPageTheme = "light"; - } - - response.json(config); - }); - - // Status Page - Monitor List - app.get("/api/status-page/monitor-list", async (_request, response) => { - allowDevAllOrigin(response); - - const monitorList = {}; - let list = await R.find("monitor", " public = 1 ORDER BY weight DESC, name ", [ - ]); - - for (let monitor of list) { - monitorList[monitor.id] = await monitor.toJSON(); - } - - response.json(monitorList); - }); - - // Status Page Polling Data - app.get("/api/status-page/heartbeat", async (_request, response) => { - allowDevAllOrigin(response); - - const monitorList = {}; - let list = await R.find("", " ", [ - ]) - - for (let monitor of list) { - monitorList[monitor.id] = await monitor.toJSON(); - } - - response.json({ - monitorList: monitorList, - }); - }); + // API Router + const apiRouter = require("./routers/api-router"); + app.use(apiRouter); // Universal Route Handler, must be at the end of all express route. app.get("*", async (_request, response) => { diff --git a/src/assets/app.scss b/src/assets/app.scss index ee917e34..e02dab80 100644 --- a/src/assets/app.scss +++ b/src/assets/app.scss @@ -368,3 +368,9 @@ h2 { background-color: #f8d7da; border-color: #f8d7da; } + +.btn-success { + color: #fff; + background-color: #4caf50; + border-color: #4caf50; +} diff --git a/src/pages/StatusPage.vue b/src/pages/StatusPage.vue index 8ad92020..5fe53aab 100644 --- a/src/pages/StatusPage.vue +++ b/src/pages/StatusPage.vue @@ -31,6 +31,10 @@ +
+ Free text here. +
+