Skip to content

Commit 777edd3

Browse files
authored
Merge pull request #213 from datopian/fix/status-endpoint
status check endpoint added for site up monitoring
2 parents a0b049b + 7896c8b commit 777edd3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const flash = require('connect-flash')
1010
const i18n = require("i18n")
1111
const moment = require('moment')
1212
const redis = require('redis')
13+
const fetch = require('node-fetch')
14+
const { URL, resolve } = require('url')
15+
1316

1417
const config = require('./config')
1518
const dmsRoutes = require('./routes/dms')
@@ -119,6 +122,28 @@ module.exports.makeApp = function () {
119122
// enable flash messages
120123
app.use(flash())
121124

125+
/*
126+
Route to check the status of the application by
127+
calling the package_search of backend with row count as 0
128+
to check whether the application is returning response or not
129+
*/
130+
app.get('/status', async (req, res) => {
131+
const url = resolve(
132+
config.get('API_URL'),
133+
`package_search?rows=0`
134+
)
135+
const response = await fetch(url)
136+
if (response.ok) {
137+
const body = await response.json()
138+
if (body.success == true) {
139+
res.status(200).send('Ok')
140+
} else {
141+
res.status(500).send('Not Ok')
142+
}
143+
144+
}
145+
})
146+
122147
// Auth
123148
if (authEnabled) {
124149
authRoutes(app)

0 commit comments

Comments
 (0)