-
-
Save lovellfelix/70d12cb3f4a97e2381b24cdb62d4ae13 to your computer and use it in GitHub Desktop.
Healthcheck cmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const config = require('./config'); | |
const log = require('./log'); | |
const constants = require('./constants'); | |
const options = { | |
host: 'localhost', | |
port: config.httpPort, | |
timeout: 2000, | |
method: 'GET', | |
path: '/api/health/', | |
}; | |
const request = http.request(options, (result) => { | |
log.info(`Performed health check, result ${result.statusCode}`); | |
if (result.statusCode === constants.HTTP_STATUS_OK) { | |
process.exit(0); | |
} else { | |
process.exit(1); | |
} | |
}); | |
request.on('error', (err) => { | |
log.error(`An error occurred while performing health check, error: ${err}`); | |
process.exit(1); | |
}); | |
request.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment