lib/js/Server.js
function(url, callback) {
      var t = this,
          originalUrl = url,
          page = null;

      // Change urls that end in / to /index
      if (url.substr(-1) === '/') {
        url = url + 'index';
      }

      // Return if it's in cache
      page = pageCache.get(url);
      if (page) {
        return callback(null, page);
      }

      // Read from storage
      page = new Page({id: url});
      page.fetch({liveSync: true, silenceErrors: true}, function(error) {

        // Process a 404.  This returns a transient page copied from
        // the default 404 page, with the id replaced by the specified url.
        if (error && error.code === 'NOTFOUND' && url !== '/app/core/404') {

          // Default the home page if notfound
          if (originalUrl === '/') {
            return t._getPage('/app/core/index', callback);
          }

          // Default the 404 page if notfound
          if (originalUrl === '/404') {
            return t._getPage('/app/core/404', callback);
          }

          // Otherwise it's a new page.  Create it.
          t._getPage('/404', function(error, page404) {
            if (error) {
              console.error("Error loading the 404 page", error);
              return callback('404 page load error');
            }

            // Copy the 404 page into a new page
            var newPage = new Page(JSON.parse(JSON.stringify(page404)));

            // Build a sane starting title.  TitleCase the last url element, separate words, replace underscores
            var title = $.titleCase(url.split('/').pop(), true).replace(/([A-Z])/g," $1").replace(/^ /,'').replace(/_/g,' ');
            var title = url.split('/').pop().replace(/([A-Z])/g," $1").replace(/^ /,'').replace(/_/g,' ');
            newPage.set({id:url, title:title, is404page:true});
            callback(null, newPage);
          });
          return;
        }

        // Process other errors
        if (error) {
          return callback(error);
        }

        // Assure the page model ID is correct on disk
        if (url !== page.get('id')) {
          page.set('id', url);
        }

        // Put the page into cache and return it
        pageCache.add(page);
        return callback(null, page);
      });
    }
function(url, callback) {
      var t = this,
          originalUrl = url,
          page = null;

      // Change urls that end in / to /index
      if (url.substr(-1) === '/') {
        url = url + 'index';
      }

      // Return if it's in cache
      page = pageCache.get(url);
      if (page) {
        return callback(null, page);
      }

      // Read from storage
      page = new Page({id: url});
      page.fetch({liveSync: true, silenceErrors: true}, function(error) {

        // Process a 404.  This returns a transient page copied from
        // the default 404 page, with the id replaced by the specified url.
        if (error && error.code === 'NOTFOUND' && url !== '/app/core/404') {

          // Default the home page if notfound
          if (originalUrl === '/') {
            return t._getPage('/app/core/index', callback);
          }

          // Default the 404 page if notfound
          if (originalUrl === '/404') {
            return t._getPage('/app/core/404', callback);
          }

          // Otherwise it's a new page.  Create it.
          t._getPage('/404', function(error, page404) {
            if (error) {
              console.error("Error loading the 404 page", error);
              return callback('404 page load error');
            }

            // Copy the 404 page into a new page
            var newPage = new Page(JSON.parse(JSON.stringify(page404)));

            // Build a sane starting title.  TitleCase the last url element, separate words, replace underscores
            var title = $.titleCase(url.split('/').pop(), true).replace(/([A-Z])/g," $1").replace(/^ /,'').replace(/_/g,' ');
            var title = url.split('/').pop().replace(/([A-Z])/g," $1").replace(/^ /,'').replace(/_/g,' ');
            newPage.set({id:url, title:title, is404page:true});
            callback(null, newPage);
          });
          return;
        }

        // Process other errors
        if (error) {
          return callback(error);
        }

        // Assure the page model ID is correct on disk
        if (url !== page.get('id')) {
          page.set('id', url);
        }

        // Put the page into cache and return it
        pageCache.add(page);
        return callback(null, page);
      });
    }
function ( url , callback ) { var t = this , originalUrl = url , page = null ; // Change urls that end in / to /index if ( url . substr ( - 1 ) === '/' ) { url = url + 'index' ; } // Return if it's in cache page = pageCache . get ( url ) ; if ( page ) { return callback ( null , page ) ; } // Read from storage page = new Page ( { id : url } ) ; page . fetch ( { liveSync : true , silenceErrors : true } , function ( error ) { // Process a 404.  This returns a transient page copied from // the default 404 page, with the id replaced by the specified url. if ( error && error . code === 'NOTFOUND' && url !== '/app/core/404' ) { // Default the home page if notfound if ( originalUrl === '/' ) { return t . _getPage ( '/app/core/index' , callback ) ; } // Default the 404 page if notfound if ( originalUrl === '/404' ) { return t . _getPage ( '/app/core/404' , callback ) ; } // Otherwise it's a new page.  Create it. t . _getPage ( '/404' , function ( error , page404 ) { if ( error ) { console . error ( "Error loading the 404 page" , error ) ; return callback ( '404 page load error' ) ; } // Copy the 404 page into a new page var newPage = new Page ( JSON . parse ( JSON . stringify ( page404 ) ) ) ; // Build a sane starting title.  TitleCase the last url element, separate words, replace underscores var title = $ . titleCase ( url . split ( '/' ) . pop ( ) , true ) . replace ( / ([A-Z]) / g , " $1" ) . replace ( / ^  / , '' ) . replace ( / _ / g , ' ' ) ; var title = url . split ( '/' ) . pop ( ) . replace ( / ([A-Z]) / g , " $1" ) . replace ( / ^  / , '' ) . replace ( / _ / g , ' ' ) ; newPage . set ( { id : url , title : title , is404page : true } ) ; callback ( null , newPage ) ; } ) ; return ; } // Process other errors if ( error ) { return callback ( error ) ; } // Assure the page model ID is correct on disk if ( url !== page . get ( 'id' ) ) { page . set ( 'id' , url ) ; } // Put the page into cache and return it pageCache . add ( page ) ; return callback ( null , page ) ; } ) ; }
Get the specified page from cache

This retrieves the page from cache, or puts it there.

@method _getPage
@param url {url} URL to the page
@param callback {function(error, pageModel)} Called when complete
Get the specified page from cache