index.js
function RouteManager(opts) {

    var defaultActions = {

        // Encapsulation of the next callback in express routes
        next: function(req, res, next) {
            next();
        },
        // Render view
        render: function (req, res, next, data) {
            res.render(data.render.viewPath, data.render.viewData);
        },
        // Send back json
        json: function (req, res, next, data) {
            res.send(data.json);
        },
        // Redirect to URL
        redirect: function (req, res, next, data) {
            res.redirect(data.redirect);
        }
    };

    // Default authenticated function
    var defaultAuthenticated = function (req, res, next) {

        console.warn('No authentication function setup');

        next();
    };

    // This function should return a express route function.
    var defaultCheckRole = function (role) {

        return function (req, res, next) {

            console.warn('No check role function setup');

            next();
        };
    };


    opts = opts || {};

    this._app = opts.app;
    this._customActions = defaultActions;
    this._authenticated = opts.authenticated || defaultAuthenticated;
    this._checkRole = opts.checkRole || defaultCheckRole;

    if(opts.actions) {

        _.merge(this._customActions, opts.actions);
    }
}
function RouteManager(opts) {

    var defaultActions = {

        // Encapsulation of the next callback in express routes
        next: function(req, res, next) {
            next();
        },
        // Render view
        render: function (req, res, next, data) {
            res.render(data.render.viewPath, data.render.viewData);
        },
        // Send back json
        json: function (req, res, next, data) {
            res.send(data.json);
        },
        // Redirect to URL
        redirect: function (req, res, next, data) {
            res.redirect(data.redirect);
        }
    };

    // Default authenticated function
    var defaultAuthenticated = function (req, res, next) {

        console.warn('No authentication function setup');

        next();
    };

    // This function should return a express route function.
    var defaultCheckRole = function (role) {

        return function (req, res, next) {

            console.warn('No check role function setup');

            next();
        };
    };


    opts = opts || {};

    this._app = opts.app;
    this._customActions = defaultActions;
    this._authenticated = opts.authenticated || defaultAuthenticated;
    this._checkRole = opts.checkRole || defaultCheckRole;

    if(opts.actions) {

        _.merge(this._customActions, opts.actions);
    }
}
function RouteManager ( opts ) { var defaultActions = { // Encapsulation of the next callback in express routes next : function ( req , res , next ) { next ( ) ; } , // Render view render : function ( req , res , next , data ) { res . render ( data . render . viewPath , data . render . viewData ) ; } , // Send back json json : function ( req , res , next , data ) { res . send ( data . json ) ; } , // Redirect to URL redirect : function ( req , res , next , data ) { res . redirect ( data . redirect ) ; } } ; // Default authenticated function var defaultAuthenticated = function ( req , res , next ) { console . warn ( 'No authentication function setup' ) ; next ( ) ; } ; // This function should return a express route function. var defaultCheckRole = function ( role ) { return function ( req , res , next ) { console . warn ( 'No check role function setup' ) ; next ( ) ; } ; } ; opts = opts || { } ; this . _app = opts . app ; this . _customActions = defaultActions ; this . _authenticated = opts . authenticated || defaultAuthenticated ; this . _checkRole = opts . checkRole || defaultCheckRole ; if ( opts . actions ) { _ . merge ( this . _customActions , opts . actions ) ; } }
Initialize the Route Manager
@param opts - initialization options
@param opts.app - express app
@param opts.authenticated - used to check if the user is authenticated. fn(req, res, next) {..} -> call next if authenticated.
@param opts.checkRole - used to check the role. fn(role) { return fn(req, res, next) {..}} -> call next if role is OK.
@param opts.actions - Additional actions
@constructor
Initialize the Route Manager