Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 72490c2

Browse files
author
Dushyant Bhalgami
authored
Merge pull request #7 from topcoder-platform/circleci_merge
Healthcheck realted changes
2 parents 378b72b + afbda54 commit 72490c2

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Health Check Controller
3+
*/
4+
5+
const config = require('config')
6+
const db = require('../datasource').getDb(config.MONGODB_URL)
7+
8+
/**
9+
* Check for health of the app
10+
* @param req the request
11+
* @param res the response
12+
*/
13+
async function checkHealth (req, res) {
14+
if (db.readyState === 1) {
15+
res.status(200).json({
16+
checksRun: 1
17+
})
18+
19+
return
20+
}
21+
22+
res.status(503).json({
23+
checksRun: 1
24+
})
25+
}
26+
27+
module.exports = {
28+
checkHealth
29+
}

src/routes.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,11 @@ module.exports = {
88
controller: 'LeaderboardController',
99
method: 'getLeaderboard'
1010
}
11+
},
12+
'/health': {
13+
get: {
14+
controller: 'HealthCheckController',
15+
method: 'checkHealth'
16+
}
1117
}
12-
}
18+
}

0 commit comments

Comments
 (0)