Skip to content

Commit

Permalink
Merge pull request #539 from nodejitsu/fix-before-after
Browse files Browse the repository at this point in the history
[fix] add `type` to before and after to grab correct `passes`, fixes #537
  • Loading branch information
yawnt committed Dec 29, 2013
2 parents c17b591 + c47adac commit 2c8edc1
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lib/http-proxy/index.js
Expand Up @@ -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);
};

0 comments on commit 2c8edc1

Please sign in to comment.