diff --git a/routes/api.js b/routes/api.js index f93188f..9519d1b 100644 --- a/routes/api.js +++ b/routes/api.js @@ -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