Spaces:
Paused
Paused
added health
Browse files- src/index.js +25 -1
src/index.js
CHANGED
|
@@ -19,8 +19,32 @@ app.use(express.json());
|
|
| 19 |
app.use(express.urlencoded({ extended: true }));
|
| 20 |
|
| 21 |
// Health check
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
app.get('/api/health', (req, res) => {
|
| 23 |
-
res.
|
| 24 |
});
|
| 25 |
|
| 26 |
// Routes
|
|
|
|
| 19 |
app.use(express.urlencoded({ extended: true }));
|
| 20 |
|
| 21 |
// Health check
|
| 22 |
+
app.get('/health', async (req, res) => {
|
| 23 |
+
const health = {
|
| 24 |
+
status: 'ok',
|
| 25 |
+
timestamp: new Date().toISOString(),
|
| 26 |
+
uptime: process.uptime(),
|
| 27 |
+
services: {
|
| 28 |
+
database: 'unknown'
|
| 29 |
+
}
|
| 30 |
+
};
|
| 31 |
+
|
| 32 |
+
try {
|
| 33 |
+
const prisma = require('./lib/prisma');
|
| 34 |
+
await prisma.$queryRaw`SELECT 1`;
|
| 35 |
+
health.services.database = 'healthy';
|
| 36 |
+
} catch (error) {
|
| 37 |
+
health.status = 'error';
|
| 38 |
+
health.services.database = 'unhealthy';
|
| 39 |
+
health.error = error.message;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
const httpStatus = health.status === 'ok' ? 200 : 503;
|
| 43 |
+
res.status(httpStatus).json(health);
|
| 44 |
+
});
|
| 45 |
+
|
| 46 |
app.get('/api/health', (req, res) => {
|
| 47 |
+
res.redirect('/health');
|
| 48 |
});
|
| 49 |
|
| 50 |
// Routes
|