router.js
function() {
      // Used for de-duping
      var paths = {};

      // Each controller has a `routes` object
      // Connect all routes defined in controllers
      _.forEach(router.controllers, function(controller) {
        _.forEach(controller.routes, function(route, method) {
          _.forEach(route, function(routeOptions, path) {
            // If path/method has already been defined, skip
            if (paths[path] === method) {
              debug.warn('Skipping duplicate route: [%s] %s', method, path);
              return;
            }

            // If no route action is defined, skip
            if (!routeOptions.action) {
              debug.warn('No action defined for route: [%s] %s', method, path);
              return;
            }

            // Setup controller scoped middleware
            // These apply to all routes in the controller
            var pre = _.invokeMap(controller.pre, 'bind', controller) || [];
            var before = _.invokeMap(controller.before, 'bind', controller) || [];
            var after = _.invokeMap(controller.after, 'bind', controller) || [];

            // Setup route scoped middleware
            // These apply only to this route
            var middleware = routeOptions.middleware || [];

            // Build the route handler (callback)
            var handler = router._buildHandler(controller, routeOptions);

            // Connect the route
            router[method](path, pre, middleware, before, handler, after);

            // Add route to set of connected routes
            router.routes.push({
              url: router.url,
              method: method,
              path: path
            });

            // Use for de-duping
            paths[path] = method;
          });
        });
      });

      // Debug logging
      _.forEach(router.routes, function(route) {
        debug.info('Route [%s] %s', route.method, route.url + route.path);
      });
    }
function() {
      // Used for de-duping
      var paths = {};

      // Each controller has a `routes` object
      // Connect all routes defined in controllers
      _.forEach(router.controllers, function(controller) {
        _.forEach(controller.routes, function(route, method) {
          _.forEach(route, function(routeOptions, path) {
            // If path/method has already been defined, skip
            if (paths[path] === method) {
              debug.warn('Skipping duplicate route: [%s] %s', method, path);
              return;
            }

            // If no route action is defined, skip
            if (!routeOptions.action) {
              debug.warn('No action defined for route: [%s] %s', method, path);
              return;
            }

            // Setup controller scoped middleware
            // These apply to all routes in the controller
            var pre = _.invokeMap(controller.pre, 'bind', controller) || [];
            var before = _.invokeMap(controller.before, 'bind', controller) || [];
            var after = _.invokeMap(controller.after, 'bind', controller) || [];

            // Setup route scoped middleware
            // These apply only to this route
            var middleware = routeOptions.middleware || [];

            // Build the route handler (callback)
            var handler = router._buildHandler(controller, routeOptions);

            // Connect the route
            router[method](path, pre, middleware, before, handler, after);

            // Add route to set of connected routes
            router.routes.push({
              url: router.url,
              method: method,
              path: path
            });

            // Use for de-duping
            paths[path] = method;
          });
        });
      });

      // Debug logging
      _.forEach(router.routes, function(route) {
        debug.info('Route [%s] %s', route.method, route.url + route.path);
      });
    }
function ( ) { // Used for de-duping var paths = { } ; // Each controller has a `routes` object // Connect all routes defined in controllers _ . forEach ( router . controllers , function ( controller ) { _ . forEach ( controller . routes , function ( route , method ) { _ . forEach ( route , function ( routeOptions , path ) { // If path/method has already been defined, skip if ( paths [ path ] === method ) { debug . warn ( 'Skipping duplicate route: [%s] %s' , method , path ) ; return ; } // If no route action is defined, skip if ( ! routeOptions . action ) { debug . warn ( 'No action defined for route: [%s] %s' , method , path ) ; return ; } // Setup controller scoped middleware // These apply to all routes in the controller var pre = _ . invokeMap ( controller . pre , 'bind' , controller ) || [ ] ; var before = _ . invokeMap ( controller . before , 'bind' , controller ) || [ ] ; var after = _ . invokeMap ( controller . after , 'bind' , controller ) || [ ] ; // Setup route scoped middleware // These apply only to this route var middleware = routeOptions . middleware || [ ] ; // Build the route handler (callback) var handler = router . _buildHandler ( controller , routeOptions ) ; // Connect the route router [ method ] ( path , pre , middleware , before , handler , after ) ; // Add route to set of connected routes router . routes . push ( { url : router . url , method : method , path : path } ) ; // Use for de-duping paths [ path ] = method ; } ) ; } ) ; } ) ; // Debug logging _ . forEach ( router . routes , function ( route ) { debug . info ( 'Route [%s] %s' , route . method , route . url + route . path ) ; } ) ; }
Iterates over all controllers and connects any routes defined
Iterates over all controllers and connects any routes defined