stackers

Motivations: Build a battletested controller library that allows middleware reuse, small controllers files to build complex applications.

Motivations: Build a battletested controller library that allows middleware reuse, small controllers files to build complex applications.

Applications using it on production: Dashboard at Geniusly.co, TheWorldPhoto.co and ChelaJs.com.

To create controller create a file with:

var controller = require('stackers');
 
var homeController = controller({
    path : '/'
});
 
homeController.get('', function(req, res){
    res.send('');
});
 
module.exports = homeController;

To add this controller to you appliction do:

var express  = require('express');
 
var app = express();
 
var homeController  = require('./controllers/home');
 
dashboardController(homeController);
 
app.listen(3000);
console.log('=> App running app', new Date());
var controller = require('stackers');
 
var homeController = controller({
    path : '/'
});
 
homeController.beforeEach(function(req, res, next){
    res.data.hello = 'world'
    next();
});
 
homeController.get('', function(req, res){
    res.send(res.data.hello);
});
 
module.exports = homeController;

The subcontroller should look like this:

var controller = require('stackers');
 
var subController = controller({
    path : '/sub'
});
 
subController.beforeEach(function(req, res, next){
    res.data.subcontroller = 'yep'
    next();
});
 
subController.get('/test', function(req, res){
    res.send(res.data);
});
 
module.exports = userController;

The main controller should look like this:

var mainController = require('stackers');
 
var mainController = controller({
    path : '/main'
});
 
mainController.beforeEach(function(req, res, next){
    res.data.controller = 'yep'
    next();
});
 
var subController = require('./sub');
 
mainController.attach(subController);
 
module.exports = mainController;

If you curl http://localhost:3000/main/sub/test

you would get

{controller:'yep', subcontroller:'yep'}