Namespace: Page

Page

Page module file description
Source:

Example

function myPage(config)
 {

    this.code = function(req, res)
    {
        res.end('Hello, world !');
    }

 }
 module.exports = myPage;

page.view is an object of view files stored in a view folder. For example :
page :
  - home :
    - home.page.js
    - view :
      - home.html

you can then do :

  res.end(page.view.home);

You can also use a html engine, like Pug (ex-jade), on your view :

var pug = require('pug');

function myPage(page)
{
   this.constuct = function()
    {
        for(var v in page.view)
        {
          // we compile and create html here for efficiency. You can just compile here and call page.view.home(locals) in this.code(){}
          page.view[v] = pug.compile(page.view[v].toString())();
        }
     }

    this.code = function(req, res)
    {
        // if http://url/?page=something
        if(req.get.page && page.view[req.get.page])
        {
          // we send the view 'something'
          res.end(page.view[req.get.page]);
        }
        // else, we send home by default, you could replace that by 404 or what you want
        else res.end(page.view.home);
    };

    this.constuct();
}
 module.exports = myPage;

Methods

(static) code(req, res)

method that is called at each request loop
Parameters:
Name Type Description
req object http request object
res object http response object
Source: