kopia lustrzana https://github.com/c9/core
adds a global handler to frontdoor: allow injection of global middlewares
rodzic
5bd78f5ecc
commit
4ffa8c0e8e
|
@ -15,6 +15,7 @@ module.exports = function Section(name, description, types) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.middlewares = [];
|
this.middlewares = [];
|
||||||
|
this.globals = [];
|
||||||
this.errorHandlers = [];
|
this.errorHandlers = [];
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
||||||
|
@ -45,6 +46,18 @@ module.exports = function Section(name, description, types) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert global middleware(s) for this section: The parent section is
|
||||||
|
* always an empty container that delegates to it's sub-sections, and
|
||||||
|
* executes all the middelwares for that section.
|
||||||
|
*
|
||||||
|
* This method allows us to inject a "global" middleware that is inserted
|
||||||
|
* *after* decodeParams and *before* all other middelwares.
|
||||||
|
*/
|
||||||
|
this.global = function( middleware ){
|
||||||
|
this.globals.push.apply(this.globals, flatten(middleware));
|
||||||
|
};
|
||||||
|
|
||||||
this.use = function(middleware) {
|
this.use = function(middleware) {
|
||||||
this.middlewares.push.apply(this.middlewares, flatten(middleware));
|
this.middlewares.push.apply(this.middlewares, flatten(middleware));
|
||||||
};
|
};
|
||||||
|
@ -125,6 +138,9 @@ module.exports = function Section(name, description, types) {
|
||||||
handler = handler.parent;
|
handler = handler.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.globals.length)
|
||||||
|
middleware.splice.apply( middleware, [1, 0].concat( this.globals ) );
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
function processNext() {
|
function processNext() {
|
||||||
handler = middleware[i++];
|
handler = middleware[i++];
|
||||||
|
|
Ładowanie…
Reference in New Issue