[Status Page] WIP: Checkpoint

This commit is contained in:
LouisLam
2021-09-11 19:40:03 +08:00
parent 4b0a8087a2
commit 3e25f0e9d9
7 changed files with 159 additions and 18 deletions

View File

@@ -26,7 +26,7 @@ console.log("Importing this project modules");
debug("Importing Monitor");
const Monitor = require("./model/monitor");
debug("Importing Settings");
const { getSettings, setSettings, setting, initJWTSecret } = require("./util-server");
const { getSettings, setSettings, setting, initJWTSecret, allowDevAllOrigin } = require("./util-server");
debug("Importing Notification");
const { Notification } = require("./notification");
@@ -127,7 +127,9 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
console.log("Adding route")
// ***************************
// Normal Router here
// ***************************
// Robots.txt
app.get("/robots.txt", async (_request, response) => {
@@ -147,7 +149,28 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
app.use("/", express.static("dist"));
// Universal Route Handler, must be at the end
// ***************************
// 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 Polling Data
app.get("/api/status-page", async (_request, response) => {
allowDevAllOrigin(response);
});
// Universal Route Handler, must be at the end of all express route.
app.get("*", async (_request, response) => {
response.send(indexHTML);
});
@@ -172,7 +195,7 @@ let indexHTML = fs.readFileSync("./dist/index.html").toString();
});
// ***************************
// Public API
// Public Socket API
// ***************************
socket.on("loginByToken", async (token, callback) => {