concept page in category sails

appears as: pages, pages, page, The page, page, A page
Sails.js in Action

This is an excerpt from Manning's book Sails.js in Action.

Using this approach, Sails provides the initial server-rendered view for some or all of the pages on a website. Client-side JavaScript might also update the DOM by making calls to the Sails app, but most or all navigation between pages in a hybrid web application is handled by allowing users to navigate between different URLs in the browser, fetching freshly personalized HTML from the server each time.

Although the pages look similar, there are three subtle but important differences. The first difference isn’t apparent from viewing each page. When your browser made a GET request to the root route, Sails tried to match it to an explicit route that contains the route address 'GET /'. Since that explicit route no longer exists, Sails used another type of route, an asset route, to deliver the homepage located at brushfire/assets/index.html. Moving the contents of the homepage view to brushfire/assets/index.html automatically created an asset route. Therefore, a GET request to / now responds with the contents of brushfire/assets/index.html, a.k.a. the homepage.

Figure 3.20. The videos page has two requests, one for new video submissions and the other for the initial videos of the page.

Each request requires a visual mechanism for a loading state and a means for adding a new video to the page after a submission.

Example 9.15. Creating a showVideosPage action
module.exports = {
...

  showVideosPage: function (req, res) {

    if (!req.session.userId) {
      return res.view('videos', {
        me: null
      });
    }

    User.findOne(req.session.userId, function (err, user){
      if (err) {
        return res.negotiate(err);
      }

      if (!user) {
        sails.log.verbose('Session refers to a user who no longer exists- did
         you delete a user, then try to refresh the page with an open tab
         logged-in as that user?');
        return res.view('videos', {
          me: null
        });
      }

      return res.view('videos', {
        me: {
          id: user.id,
          email: user.email,
          gravatarURL: user.gravatarURL,
          admin: user.admin
        }
      });
    });
  }
};