[Explore | develop]: server.ts: Added endpoint '/health-check' with basic information.
This commit is contained in:
parent
1fef8ce8e6
commit
14c289b719
|
@ -57,6 +57,29 @@ export function app() {
|
|||
res.end(register.metrics());
|
||||
});
|
||||
|
||||
server.get('/health-check', async (_req, res, _next) => {
|
||||
var uptime = process.uptime();
|
||||
const date = new Date(uptime*1000);
|
||||
const days = date.getUTCDate() - 1,
|
||||
hours = date.getUTCHours(),
|
||||
minutes = date.getUTCMinutes(),
|
||||
seconds = date.getUTCSeconds(),
|
||||
milliseconds = date.getUTCMilliseconds();
|
||||
|
||||
|
||||
const healthcheck = {
|
||||
uptime: days + " days, " + hours + " hours, " + minutes + " minutes, " + seconds + " seconds, " + milliseconds + " milliseconds",
|
||||
message: 'OK',
|
||||
timestamp: new Date()
|
||||
};
|
||||
try {
|
||||
res.send(healthcheck);
|
||||
} catch (error) {
|
||||
healthcheck.message = error;
|
||||
res.status(503).send();
|
||||
}
|
||||
});
|
||||
|
||||
// All regular routes use the Universal engine
|
||||
server.get('*', (req, res) => {
|
||||
if (routes.indexOf(req.path) !== -1) {
|
||||
|
|
Loading…
Reference in New Issue