Skip to content

Commit 2c8edc1

Browse files
committed
Merge pull request #539 from nodejitsu/fix-before-after
[fix] add `type` to before and after to grab correct `passes`, fixes #537
2 parents c17b591 + c47adac commit 2c8edc1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

lib/http-proxy/index.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,33 @@ ProxyServer.prototype.listen = function(port) {
117117
return this;
118118
};
119119

120-
ProxyServer.prototype.before = function(passName, callback) {
121-
var i = false;
122-
this.passes.forEach(function(v, idx) {
120+
ProxyServer.prototype.before = function(type, passName, callback) {
121+
if (type !== 'ws' || type !== 'web') {
122+
throw new Error('type must be `web` or `ws`');
123+
}
124+
var passes = (type === 'ws') ? this.wsPasses : this.webPasses,
125+
i = false;
126+
127+
passes.forEach(function(v, idx) {
123128
if(v.name === passName) i = idx;
124129
})
125130

126131
if(!i) throw new Error('No such pass');
127132

128-
this.passes.splice(i, 0, callback);
133+
passes.splice(i, 0, callback);
129134
};
130-
ProxyServer.prototype.after = function(passName, callback) {
131-
var i = false;
132-
this.passes.forEach(function(v, idx) {
135+
ProxyServer.prototype.after = function(type, passName, callback) {
136+
if (type !== 'ws' || type !== 'web') {
137+
throw new Error('type must be `web` or `ws`');
138+
}
139+
var passes = (type === 'ws') ? this.wsPasses : this.webPasses,
140+
i = false;
141+
142+
passes.forEach(function(v, idx) {
133143
if(v.name === passName) i = idx;
134144
})
135145

136146
if(!i) throw new Error('No such pass');
137147

138-
this.passes.splice(i++, 0, callback);
148+
passes.splice(i++, 0, callback);
139149
};

0 commit comments

Comments
 (0)