mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] add type to before and after to grab correct passes, fixes #537
This commit is contained in:
parent
c17b591b7d
commit
c47adac391
@ -117,23 +117,33 @@ ProxyServer.prototype.listen = function(port) {
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
ProxyServer.prototype.before = function(passName, callback) {
|
ProxyServer.prototype.before = function(type, passName, callback) {
|
||||||
var i = false;
|
if (type !== 'ws' || type !== 'web') {
|
||||||
this.passes.forEach(function(v, idx) {
|
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(v.name === passName) i = idx;
|
||||||
})
|
})
|
||||||
|
|
||||||
if(!i) throw new Error('No such pass');
|
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) {
|
ProxyServer.prototype.after = function(type, passName, callback) {
|
||||||
var i = false;
|
if (type !== 'ws' || type !== 'web') {
|
||||||
this.passes.forEach(function(v, idx) {
|
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(v.name === passName) i = idx;
|
||||||
})
|
})
|
||||||
|
|
||||||
if(!i) throw new Error('No such pass');
|
if(!i) throw new Error('No such pass');
|
||||||
|
|
||||||
this.passes.splice(i++, 0, callback);
|
passes.splice(i++, 0, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user