GH-13 server.use()
This commit is contained in:
parent
fcfb73c2f1
commit
f8c46a4c20
|
@ -140,7 +140,14 @@ functions in the form `f(req, res, next)` or arrays of functions of the same
|
||||||
signature (ldapjs will unroll them).
|
signature (ldapjs will unroll them).
|
||||||
|
|
||||||
Unlike HTTP, LDAP operations do not have a heterogeneous wire format, so each
|
Unlike HTTP, LDAP operations do not have a heterogeneous wire format, so each
|
||||||
operation requires specific methods/fields on the request/response objects.
|
operation requires specific methods/fields on the request/response
|
||||||
|
objects. However, there is a `.use()` method availabe, similar to
|
||||||
|
that on express/connect, allowing you to chain up "middleware":
|
||||||
|
|
||||||
|
server.use(function(req, res, next) {
|
||||||
|
console.log('hello world');
|
||||||
|
return next();
|
||||||
|
});
|
||||||
|
|
||||||
## Common Request Elements
|
## Common Request Elements
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,7 @@ function Server(options) {
|
||||||
|
|
||||||
EventEmitter.call(this, options);
|
EventEmitter.call(this, options);
|
||||||
|
|
||||||
|
this._chain = [];
|
||||||
this.log4js = options.log4js;
|
this.log4js = options.log4js;
|
||||||
this.log = this.log4js.getLogger('Server');
|
this.log = this.log4js.getLogger('Server');
|
||||||
|
|
||||||
|
@ -617,6 +618,16 @@ Server.prototype.unbind = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Server.prototype.use = function use() {
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
var chain = mergeFunctionArgs(args, 0, args.length);
|
||||||
|
var self = this;
|
||||||
|
chain.forEach(function(c) {
|
||||||
|
self._chain.push(c);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Server.prototype.after = function() {
|
Server.prototype.after = function() {
|
||||||
if (!this._postChain)
|
if (!this._postChain)
|
||||||
this._postChain = [];
|
this._postChain = [];
|
||||||
|
@ -792,7 +803,12 @@ Server.prototype._mount = function(op, name, argv, notDN) {
|
||||||
index = 1;
|
index = 1;
|
||||||
}
|
}
|
||||||
var route = this._getRoute(notDN ? name : dn.parse(name), backend);
|
var route = this._getRoute(notDN ? name : dn.parse(name), backend);
|
||||||
route['0x' + op.toString(16)] = mergeFunctionArgs(argv.slice(index));
|
|
||||||
|
var chain = this._chain.slice();
|
||||||
|
argv.slice(index).forEach(function(a) {
|
||||||
|
chain.push(a);
|
||||||
|
});
|
||||||
|
route['0x' + op.toString(16)] = mergeFunctionArgs(chain);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue