Merge pull request +8038 from c9/mvh-testing-routing

Mvh testing routing
pull/117/merge
Nikolai Onken 2015-07-01 15:48:08 +02:00
commit dec38d9e7e
1 zmienionych plików z 48 dodań i 0 usunięć

48
node_modules/frontdoor/lib/section.js wygenerowano vendored
Wyświetl plik

@ -80,8 +80,37 @@ module.exports = function Section(name, description, types) {
sections[name].push(section);
return section;
};
this.getRoutes = function(){
return routes;
};
/**
* Mount an existing section on this instance.
*
* Note that when the first argument is omitted, the section's routes will
* be copied onto this instance's routing table.
*
* @param {string} mountpoint Where to mount this secion, e.g. "/capture/"
* @param {Section} section A frontdoor section
*/
this.mount = function(name, section) {
if ( arguments.length == 1 ){
section = arguments[0];
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] );
});
return;
}
if (!sections[name])
sections[name] = [];
@ -89,6 +118,25 @@ module.exports = function Section(name, description, types) {
sections[name].push(section);
};
/**
* Sortcut for client-side routing without a `next`
*
* Allows you to omit the third argument, "next" and avoid special
* treatment in router.js (see "wrapHandler").
*
* 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 );
handler = middlewares.shift();
middlewares.unshift(function(req, res, next){
handler( req, res, next );
});
this._route( path, { method: "get" }, middlewares );
};
this._rootHandler = function(req, res) {
this.handle(req, res, function(err) {
if (err) {