likegun-controller

下了些node的controller的包,不是特别能满足我的要求,还是自己写一个吧.


Keywords
node, controller
License
MIT
Install
npm install likegun-controller@1.0.7

Documentation

likegun-controller

自己写controller模块,应该挺有趣的.好,那就写!

Install

npm install likegun-controller --save

Usage

app.js:

var fs = require('fs');
var app = require('express')();

fs.readDir('./controllers', function(err, files){
    if(err)
        throw err;
    files.forEach(function(file) {
        var ctrl = require('./controllers/'+file);
        app.use(ctrl.router);
    });
});

controllers/ExampleController.js:

var ExampleController = require('likegun-controller');

//Add a handle
ExampleController.addHandle('GET', '/example/show', function(req, res, next) {
    res.end('Just a example');
});

//Add a filter
ExampleController.addFilter('ExampleFilter', [
{url: '/example/show', method: 'GET'}
], function(req, res, next) {
    //code filter
});

module.exports = ExampleController;