diff --git a/lib/modules/http.js b/lib/modules/http.js index 307cda6..2277903 100644 --- a/lib/modules/http.js +++ b/lib/modules/http.js @@ -64,6 +64,18 @@ module.exports.create = function (deps, conf) { proxyReq.setHeader('X-Forwarded-For', opts.remoteAddress || conn.remoteAddress); }); + proxy.on('error', function (err, req, res) { + console.log(err); + res.writeHead(502); + if (err.code === 'ECONNREFUSED') { + res.end('The connection was refused. Most likely the service being connected to ' + + 'has stopped running or the configuration is wrong.'); + } + else { + res.end('Bad Gateway: ' + err.code); + } + }); + return function (req, res, next) { var hostname = req.headers.host.split(':')[0]; var relevant = mod.domains.some(function (pattern) {