added error handling when HTTP proxy doesn't connect
This commit is contained in:
parent
ab011d1829
commit
bcba0abddc
|
@ -64,6 +64,18 @@ module.exports.create = function (deps, conf) {
|
||||||
proxyReq.setHeader('X-Forwarded-For', opts.remoteAddress || conn.remoteAddress);
|
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) {
|
return function (req, res, next) {
|
||||||
var hostname = req.headers.host.split(':')[0];
|
var hostname = req.headers.host.split(':')[0];
|
||||||
var relevant = mod.domains.some(function (pattern) {
|
var relevant = mod.domains.some(function (pattern) {
|
||||||
|
|
Loading…
Reference in New Issue