Add status api

This commit is contained in:
Christopher Cookman 2025-01-20 19:18:38 -07:00
parent e6244a614a
commit 3bb32e1352
2 changed files with 31 additions and 2 deletions

View file

@ -37,6 +37,35 @@ app.use((req, res, next) => {
next();
});
app.get("/health", async (req, res) => {
const status = {
webServer: 'OK',
discordClient: 'OK',
mariaDB: 'OK',
errors: []
};
if (!client.isReady()) {
status.discordClient = 'FAIL';
status.errors.push('Discord client is not ready.');
}
try {
const connection = await pool.getConnection();
connection.release();
} catch (error) {
status.mariaDB = 'FAIL';
status.errors.push('MariaDB connection failed.');
}
if (status.errors.length > 0) {
status.status = 'FAIL';
} else {
status.status = 'OK';
}
res.json(status);
});
global.discord_client = client
client.on("ready", async () => {

4
log.js
View file

@ -1,9 +1,9 @@
const colors = require("colors");
module.exports = {
info(msg) {
console.log(`${colors.cyan.bold("[INFO]")} ${msg}`);
console.log(`${colors.cyan.bold("[INFO]")}@${new Date().toISOString()} ${msg}`);
},
error(msg) {
console.log(`${colors.red.bold("[ERROR]")} ${msg}`);
console.log(`${colors.red.bold("[ERROR]")}@${new Date().toISOString()} ${msg}`);
}
}