lib/js/Server.js
function(request, response, next) {
      var t = this;

      // URL rewrites
      var url = URL.resolve('', request.url);
      if (url === '/favicon.ico') {
        var faviconUrl = t.site.get('favicon');
        url = request.url = faviconUrl || request.url;
      }

      // Remove the leading slash for page manipulation
      url = url.substr(1);

      // Rewrite the url and forward if it points to static content
      var urlParts = url.split('/');
      if (urlParts[0] === 'static') {

        // Replace static with lib, and put the leading slash back in
        request.url = url.replace('static/', '/lib/');

        // Forward to the monitor distribution
        if (request.url.indexOf('monitor-all.js') > 0) {
          request.url = '/monitor-all.js';
          return t.monitorDist(request, response, next);
        }

        // Next is the static server
        return next();
      }

      // If it's an URL to an app, route to the app
      if (urlParts[0] === 'app') {
        var appName = urlParts[1],
            app = t.apps[appName];

        // Route to a monitor page if the app doesn't handle the request
        var appNext = function() {
          t._monitorPageRoute(request, response, next);
        };

        // Continue if the app isn't defined
        if (!app) {
          return appNext();
        }

        // Make the app request relative to the app
        var appUrl = '/' + url.split('/').slice(2).join('/'),
            appRequest = _.extend({}, request, {url: appUrl});

        // Forward the request to the app server
        var server = typeof app.server === 'function' ? app.server : app.staticServer;
        return server(appRequest, response, appNext);
      }

      // Forward to a monitor page
      t._monitorPageRoute(request, response, next);
    }
function(request, response, next) {
      var t = this;

      // URL rewrites
      var url = URL.resolve('', request.url);
      if (url === '/favicon.ico') {
        var faviconUrl = t.site.get('favicon');
        url = request.url = faviconUrl || request.url;
      }

      // Remove the leading slash for page manipulation
      url = url.substr(1);

      // Rewrite the url and forward if it points to static content
      var urlParts = url.split('/');
      if (urlParts[0] === 'static') {

        // Replace static with lib, and put the leading slash back in
        request.url = url.replace('static/', '/lib/');

        // Forward to the monitor distribution
        if (request.url.indexOf('monitor-all.js') > 0) {
          request.url = '/monitor-all.js';
          return t.monitorDist(request, response, next);
        }

        // Next is the static server
        return next();
      }

      // If it's an URL to an app, route to the app
      if (urlParts[0] === 'app') {
        var appName = urlParts[1],
            app = t.apps[appName];

        // Route to a monitor page if the app doesn't handle the request
        var appNext = function() {
          t._monitorPageRoute(request, response, next);
        };

        // Continue if the app isn't defined
        if (!app) {
          return appNext();
        }

        // Make the app request relative to the app
        var appUrl = '/' + url.split('/').slice(2).join('/'),
            appRequest = _.extend({}, request, {url: appUrl});

        // Forward the request to the app server
        var server = typeof app.server === 'function' ? app.server : app.staticServer;
        return server(appRequest, response, appNext);
      }

      // Forward to a monitor page
      t._monitorPageRoute(request, response, next);
    }
function ( request , response , next ) { var t = this ; // URL rewrites var url = URL . resolve ( '' , request . url ) ; if ( url === '/favicon.ico' ) { var faviconUrl = t . site . get ( 'favicon' ) ; url = request . url = faviconUrl || request . url ; } // Remove the leading slash for page manipulation url = url . substr ( 1 ) ; // Rewrite the url and forward if it points to static content var urlParts = url . split ( '/' ) ; if ( urlParts [ 0 ] === 'static' ) { // Replace static with lib, and put the leading slash back in request . url = url . replace ( 'static/' , '/lib/' ) ; // Forward to the monitor distribution if ( request . url . indexOf ( 'monitor-all.js' ) > 0 ) { request . url = '/monitor-all.js' ; return t . monitorDist ( request , response , next ) ; } // Next is the static server return next ( ) ; } // If it's an URL to an app, route to the app if ( urlParts [ 0 ] === 'app' ) { var appName = urlParts [ 1 ] , app = t . apps [ appName ] ; // Route to a monitor page if the app doesn't handle the request var appNext = function ( ) { t . _monitorPageRoute ( request , response , next ) ; } ; // Continue if the app isn't defined if ( ! app ) { return appNext ( ) ; } // Make the app request relative to the app var appUrl = '/' + url . split ( '/' ) . slice ( 2 ) . join ( '/' ) , appRequest = _ . extend ( { } , request , { url : appUrl } ) ; // Forward the request to the app server var server = typeof app . server === 'function' ? app . server : app . staticServer ; return server ( appRequest , response , appNext ) ; } // Forward to a monitor page t . _monitorPageRoute ( request , response , next ) ; }
Internal route for all non-static site endpoints

@method siteRoute
@param request {Connect.Request} The http request object
@param response {Connect.Response} The http response object
@param next {Function()} Function to pass control if this doesn't handle the url.
Internal route for all non - static site endpoints