Add healthcheck endpoint
This commit is contained in:
@@ -66,6 +66,18 @@ app.get('/api/health', async (_req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.get('/api/healthcheck', async (_req, res) => {
|
||||||
|
try {
|
||||||
|
await Promise.race([
|
||||||
|
db.raw('select 1'),
|
||||||
|
new Promise((_, reject) => setTimeout(() => reject(new Error('db-timeout')), 1000)),
|
||||||
|
]);
|
||||||
|
res.json({ success: true, data: { status: 'ok' } });
|
||||||
|
} catch (err: any) {
|
||||||
|
res.status(503).json({ success: false, error: 'db_unavailable' });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// ── Глобальный rate limit на /api/* — ДО docs чтобы не было unauthenticated DoS на swagger.json
|
// ── Глобальный rate limit на /api/* — ДО docs чтобы не было unauthenticated DoS на swagger.json
|
||||||
app.use('/api', globalLimiter);
|
app.use('/api', globalLimiter);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user