Nifty Procrastination Machine
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    express-dispatcherpublic

    express-dispatcher Build Status

    Dispatcher for expressjs : Under development !

    Installation

    $ npm install -g express-dispatcher

    Usage exemple

    // controllers/routes.js 
    exports.routes = {
        app: {
            'index' : {
                path: '/',
                controller: 'index',
                action: 'index',
                view: 'index',
                method: 'GET',
                isSecure: false
            },
            'about' : {
                path: '/about',
                controller: 'about',
                action: 'index',
                method: 'POST',
                isSecure: false
            }
        },
        routes: {
            'blog' : 'blog/routes',
            'user' : 'user/routes'
        }
    };
     
    // for "/" VERB, load "controller/index" from "./controllers/main/index" 
    // and execute "index" action 
     
    // code of "controllers/index.js" 
    var main = exports._controller = {
        index : function(req, res, next) {
            console.log('view is => ' + main.getView(req));
            res.render(main.getView(req), { title: 'My title' });
        }
        //... 
    };

    Let's starting with a simple configuration of nodejs

    var express = require('express')
      , http = require('http')
      , path = require('path')
      , dispatcher = require('express-dispatcher').dispatcher;
      
    var app = express();
     
    app.configure(function(){
      app.engine('.hjs', require('hogan-express'));
      app.set('port', process.env.PORT || 3000);
      app.set('views', __dirname + '/views');
      app.set('view engine', 'hjs');
      app.use(express.logger('dev'));
      app.use(express.bodyParser());
      app.use(express.methodOverride());
      app.use(express.cookieParser('a45Er#f5J'));
      app.use(express.session());
      app.use(app.router);
     
      app.use(express.static(path.join(__dirname, 'public')));
    });
     
    app.configure('development', function(){
      app.use(express.errorHandler());
    });
     
    // This dispatcher 
    dispatcher.init({app: app, path: __dirname + '/controllers/'});
     
    var server = http.createServer(app);
     
    server.listen(app.get('port'), function(){
      console.log("Express server listening on port " + app.get('port'));
    });

    Our MVC architecture

    app.js
    controllers
    controllers/routes.js
    controllers/main/index.js
    models
    views
    views/index.js
    public

    Keywords

    none

    install

    npm i express-dispatcher

    Downloadsweekly downloads

    2

    version

    0.0.0

    license

    none

    repository

    github.com

    last publish

    collaborators

    • avatar