添加Health健康检查端点
This commit is contained in:
13
server/db.js
13
server/db.js
@@ -18,9 +18,20 @@ function initPool() {
|
||||
});
|
||||
}
|
||||
|
||||
async function checkHealth() {
|
||||
try {
|
||||
if (!pool) return { status: 'down', error: 'Database pool not initialized' };
|
||||
await pool.query('SELECT 1');
|
||||
return { status: 'up' };
|
||||
} catch (err) {
|
||||
return { status: 'down', error: err.message };
|
||||
}
|
||||
}
|
||||
|
||||
initPool();
|
||||
|
||||
module.exports = {
|
||||
query: (...args) => pool.query(...args),
|
||||
initPool
|
||||
initPool,
|
||||
checkHealth
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user