diff --git a/lib/http-proxy.js b/lib/http-proxy.js index 196dded44..34029e864 100644 --- a/lib/http-proxy.js +++ b/lib/http-proxy.js @@ -8,6 +8,13 @@ var http = require('http'), */ module.exports = httpProxy.Server; +module.exports.createProxy = function(options) { + return { + web: httpProxy.createRightProxy('web')(options), + ws: httpProxy.createRightProxy('ws')(options) + }; +} + /** * Creates the proxy server. * diff --git a/lib/http-proxy/index.js b/lib/http-proxy/index.js index bd8b8a991..4436c1351 100644 --- a/lib/http-proxy/index.js +++ b/lib/http-proxy/index.js @@ -80,7 +80,7 @@ function createRightProxy(type) { }; }; } - +httpProxy.createRightProxy = createRightProxy; function ProxyServer(options) { EE3.call(this); @@ -96,6 +96,10 @@ function ProxyServer(options) { this.wsPasses = Object.keys(ws).map(function(pass) { return ws[pass]; }); + + this.on('error', function(err) { + console.log(err); + }); } require('util').inherits(ProxyServer, EE3); diff --git a/lib/http-proxy/passes/web-incoming.js b/lib/http-proxy/passes/web-incoming.js index 2b14c874c..305365f7a 100644 --- a/lib/http-proxy/passes/web-incoming.js +++ b/lib/http-proxy/passes/web-incoming.js @@ -117,7 +117,7 @@ web_o = Object.keys(web_o).map(function(pass) { (options.buffer || req).pipe(proxyReq); proxyReq.on('response', function(proxyRes) { - server.emit('proxyRes', proxyRes); + if(server) { server.emit('proxyRes', proxyRes); } for(var i=0; i < web_o.length; i++) { if(web_o[i](req, res, proxyRes)) { break; } }