From c47adac391ca2f80ac1adad52e4fd652d85ac2a4 Mon Sep 17 00:00:00 2001 From: Jarrett Cruger Date: Sun, 29 Dec 2013 15:59:33 -0500 Subject: [PATCH] [fix] add `type` to before and after to grab correct `passes`, fixes #537 --- lib/http-proxy/index.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/http-proxy/index.js b/lib/http-proxy/index.js index eb1c5dd..bd8b8a9 100644 --- a/lib/http-proxy/index.js +++ b/lib/http-proxy/index.js @@ -117,23 +117,33 @@ ProxyServer.prototype.listen = function(port) { return this; }; -ProxyServer.prototype.before = function(passName, callback) { - var i = false; - this.passes.forEach(function(v, idx) { +ProxyServer.prototype.before = function(type, passName, callback) { + if (type !== 'ws' || type !== 'web') { + throw new Error('type must be `web` or `ws`'); + } + var passes = (type === 'ws') ? this.wsPasses : this.webPasses, + i = false; + + passes.forEach(function(v, idx) { if(v.name === passName) i = idx; }) if(!i) throw new Error('No such pass'); - this.passes.splice(i, 0, callback); + passes.splice(i, 0, callback); }; -ProxyServer.prototype.after = function(passName, callback) { - var i = false; - this.passes.forEach(function(v, idx) { +ProxyServer.prototype.after = function(type, passName, callback) { + if (type !== 'ws' || type !== 'web') { + throw new Error('type must be `web` or `ws`'); + } + var passes = (type === 'ws') ? this.wsPasses : this.webPasses, + i = false; + + passes.forEach(function(v, idx) { if(v.name === passName) i = idx; }) if(!i) throw new Error('No such pass'); - this.passes.splice(i++, 0, callback); + passes.splice(i++, 0, callback); };