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;