add healthcheck endpoint
This commit is contained in:
parent
e9f37775e3
commit
0eb5f44cc2
|
@ -15,6 +15,25 @@ const pool = mariadb.createPool({
|
||||||
connectionLimit: 100 // Adjust connection limit as needed
|
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) => {
|
router.get("/v1/myIP", (req,res) => {
|
||||||
res.json({
|
res.json({
|
||||||
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress
|
ip: req.headers['x-forwarded-for'] || req.connection.remoteAddress
|
||||||
|
|
Loading…
Reference in a new issue