Abhises commited on
Commit
59c9279
·
1 Parent(s): 08caca4

added health

Browse files
Files changed (1) hide show
  1. 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.json({ status: 'ok', timestamp: new Date().toISOString() });
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