diff --git a/node_modules/frontdoor/lib/section.js b/node_modules/frontdoor/lib/section.js index bf65ef79..69c84e6c 100644 --- a/node_modules/frontdoor/lib/section.js +++ b/node_modules/frontdoor/lib/section.js @@ -96,24 +96,30 @@ module.exports = function Section(name, description, types) { */ this.mount = function(name, section) { - if ( arguments.length == 1 ){ + var that = this; + + if (arguments.length == 1) { section = arguments[0]; - - if ( ! ( section instanceof Section ) ) + + if (!(section instanceof Section)) throw new Error("Single argument to mount must be a Section!"); - + var addRoutes = section.getRoutes(); - - Object.keys(addRoutes).forEach(function( method){ - routes[method] = [].concat( routes[method], addRoutes[method] ); + + Object.keys(addRoutes).forEach(function(method) { + var r = addRoutes[method]; + r.forEach(function(route) { + route.parent = that; + }) + routes[method] = [].concat(routes[method], r); }); - + return; } - + if (!sections[name]) sections[name] = []; - + section.parent = this; sections[name].push(section); }; @@ -126,15 +132,17 @@ module.exports = function Section(name, description, types) { * * Has a variable number of argumnets: no need to wrap handlers in an array */ - this.on = function( path, handler ){ - var middlewares = Array.prototype.slice.call( arguments, 1 ); + this.on = function(path, handler){ + var middlewares = Array.prototype.slice.call(arguments, 1); handler = middlewares.shift(); - middlewares.unshift(function(req, res, next){ - handler( req, res, next ); + middlewares.unshift(function(req, res, next) { + handler(req, res, next); }); - this._route( path, { method: "get" }, middlewares ); + this._route(path, { + method: "get" + }, middlewares); }; this._rootHandler = function(req, res) { @@ -172,7 +180,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(); @@ -184,7 +192,7 @@ module.exports = function Section(name, description, types) { errorHandlers.unshift.apply(errorHandlers, handler.errorHandlers || []); handler = handler.parent; } - + if (this.globals.length) middleware.splice.apply( middleware, [1, 0].concat( this.globals ) );