Created
January 5, 2020 14:52
-
-
Save PatrickKalkman/77dd7d84aba2eb9a1fe32efa62ed903a 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