Add status api
This commit is contained in:
parent
e6244a614a
commit
3bb32e1352
29
index.js
29
index.js
|
@ -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
4
log.js
|
@ -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}`);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue