From 9d5904e9ba05d2e8b201c6e37ee056d94c5740a3 Mon Sep 17 00:00:00 2001 From: Nikolai Onken Date: Sat, 4 Jul 2015 22:07:10 +0000 Subject: [PATCH 1/4] Simplify --- node_modules/frontdoor/lib/section.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node_modules/frontdoor/lib/section.js b/node_modules/frontdoor/lib/section.js index bf65ef79..2eac24da 100644 --- a/node_modules/frontdoor/lib/section.js +++ b/node_modules/frontdoor/lib/section.js @@ -151,7 +151,7 @@ module.exports = function Section(name, description, types) { this.handle = (function(path, req, res, next) { var that = this; - + debugger; if (arguments.length == 2) { return this._rootHandler.apply(this, arguments); } From bf2d7fec2f59cd689373d553170aaaed501c55bf Mon Sep 17 00:00:00 2001 From: Nikolai Onken Date: Sun, 5 Jul 2015 07:17:52 +0000 Subject: [PATCH 2/4] Simplify util and config --- node_modules/frontdoor/lib/section.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node_modules/frontdoor/lib/section.js b/node_modules/frontdoor/lib/section.js index 2eac24da..3ad67591 100644 --- a/node_modules/frontdoor/lib/section.js +++ b/node_modules/frontdoor/lib/section.js @@ -151,7 +151,7 @@ module.exports = function Section(name, description, types) { this.handle = (function(path, req, res, next) { var that = this; - debugger; + if (arguments.length == 2) { return this._rootHandler.apply(this, arguments); } @@ -172,7 +172,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(); From 37286ec01219d8cfc024d7b3e9f5218e7aafbfa9 Mon Sep 17 00:00:00 2001 From: Nikolai Onken Date: Tue, 7 Jul 2015 08:50:06 +0000 Subject: [PATCH 3/4] Fix login / error handling --- node_modules/frontdoor/lib/section.js | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/node_modules/frontdoor/lib/section.js b/node_modules/frontdoor/lib/section.js index 3ad67591..0b21c861 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); }; From 7fabaaa51f687e2ea5019e17560f7c8a5a18f525 Mon Sep 17 00:00:00 2001 From: Nikolai Onken Date: Tue, 7 Jul 2015 09:45:22 +0000 Subject: [PATCH 4/4] Simplify routing --- node_modules/frontdoor/lib/section.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/node_modules/frontdoor/lib/section.js b/node_modules/frontdoor/lib/section.js index 0b21c861..69c84e6c 100644 --- a/node_modules/frontdoor/lib/section.js +++ b/node_modules/frontdoor/lib/section.js @@ -132,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) { @@ -190,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 ) );