mirror of
https://github.com/linuxserver/core.git
synced 2026-02-20 05:07:19 +08:00
Merge pull request +7445 from c9/simplify-profile-more-further
Simplify profile more further
This commit is contained in:
commit
fb56160e20
27
node_modules/frontdoor/lib/section.js
generated
vendored
27
node_modules/frontdoor/lib/section.js
generated
vendored
@ -15,6 +15,7 @@ module.exports = function Section(name, description, types) {
|
||||
var self = this;
|
||||
|
||||
this.middlewares = [];
|
||||
this.globals = [];
|
||||
this.errorHandlers = [];
|
||||
this.name = name;
|
||||
|
||||
@ -45,10 +46,22 @@ 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.middlewares.push.apply(this.middlewares, flatten(middleware));
|
||||
};
|
||||
|
||||
|
||||
this.error = function(middleware) {
|
||||
this.errorHandlers.push.apply(this.errorHandlers, flatten(middleware));
|
||||
};
|
||||
@ -70,6 +83,13 @@ module.exports = function Section(name, description, types) {
|
||||
return section;
|
||||
};
|
||||
|
||||
this.mount = function(name, section) {
|
||||
if (!sections[name])
|
||||
sections[name] = [];
|
||||
|
||||
sections[name].push(section);
|
||||
};
|
||||
|
||||
this._rootHandler = function(req, res) {
|
||||
this.handle(req, res, function(err) {
|
||||
if (err) {
|
||||
@ -105,7 +125,7 @@ module.exports = function Section(name, description, types) {
|
||||
var method = req.method.toLowerCase();
|
||||
if (methods.indexOf(method) == -1)
|
||||
return next();
|
||||
|
||||
|
||||
var handler = this.match(req, path, method);
|
||||
if (!handler)
|
||||
return next();
|
||||
@ -118,6 +138,9 @@ module.exports = function Section(name, description, types) {
|
||||
handler = handler.parent;
|
||||
}
|
||||
|
||||
if (this.globals.length)
|
||||
middleware.splice.apply( middleware, [1, 0].concat( this.globals ) );
|
||||
|
||||
var i = 0;
|
||||
function processNext() {
|
||||
handler = middleware[i++];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user