add healthcheck endpoint

This commit is contained in:
Christopher Cookman 2024-12-22 22:41:19 -07:00
parent e9f37775e3
commit 0eb5f44cc2

View file

@ -15,6 +15,25 @@ const pool = mariadb.createPool({
connectionLimit: 100 // Adjust connection limit as needed
});
router.get("/health", async (req,res) => {
try {
// Get a connection from the pool
const connection = await pool.getConnection();
try {
// Execute a simple query to check the connection
await connection.query('SELECT 1');
res.status(200).json({ status: 'OK' });
} finally {
// Release the connection back to the pool
connection.release();
}
} catch (err) {
console.error('Database connection error:', err);
res.status(500).json({ status: 'ERROR', error: 'Database connection error' });
}
});
router.get("/v1/myIP", (req,res) => {
res.json({
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress