Skip to content

Commit

Permalink
feat: add healthcheck script for docker use
Browse files Browse the repository at this point in the history
  • Loading branch information
jrassa committed Feb 13, 2024
1 parent b90634c commit b1bf8f3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/healthcheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

/* eslint-disable no-console */
import http from 'node:http';

import config from 'config';

const options = {
hostname: 'localhost',
port: config.get('port'),
path: '/actuator/health',
method: 'GET'
};

http
.request(options, (res) => {
let body = '';

res.on('data', (chunk) => {
body += chunk;
});

res.on('end', () => {
try {
const response = JSON.parse(body);
if (response.status === 'UP') {
process.exit(0);
}

console.log('Unhealthy response received: ', body);
process.exit(1);
} catch (err) {
console.log('Error parsing JSON response body: ', err);
process.exit(1);
}
});
})
.on('error', (err) => {
console.log('Error: ', err);
process.exit(1);
})
.end();

0 comments on commit b1bf8f3

Please sign in to comment.