Skip to content

Commit

Permalink
refactor(server): refactoring of stopper (#3174)
Browse files Browse the repository at this point in the history
  • Loading branch information
lusarz authored and johnjbarton committed Oct 12, 2018
1 parent 8efb28d commit 5cc4089
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions lib/stopper.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
const http = require('http')

const cfg = require('./config')
const logger = require('./logger')
const helper = require('./helper')

exports.stop = function (config, done) {
config = config || {}
logger.setupFromConfig(config)
done = helper.isFunction(done) ? done : process.exit
const log = logger.create('stopper')
done = helper.isFunction(done) ? done : process.exit
config = cfg.parseConfig(config.configFile, config)

const options = {
const request = http.request({
hostname: config.hostname,
path: config.urlRoot + 'stop',
port: config.port,
method: 'GET'
}

const request = http.request(options)
})

request.on('response', function (response) {
if (response.statusCode !== 200) {
log.error('Server returned status code: ' + response.statusCode)
if (response.statusCode === 200) {
log.info('Server stopped.')
done(0)
} else {
log.error(`Server returned status code: ${response.statusCode}`)
done(1)
return
}

log.info('Server stopped.')
done(0)
})

request.on('error', function (e) {
if (e.code === 'ECONNREFUSED') {
log.error('There is no server listening on port %d', options.port)
log.error(`There is no server listening on port ${config.port}`)
done(1, e.code)
} else {
throw e
Expand Down

0 comments on commit 5cc4089

Please sign in to comment.