lark-router
Route configuration middleware for koajs.
Installation
$ npm install lark-router
API
app.use(router(options))
var koa = require('koa');
var router = require('lark-router');
var app = koa();
app.use(router({directory:'controllers'}));
app.listen(3002);
directory
The directory
configuration option (optional) is the path to a directory.
Specify a directory to have lark-router scan all files recursively to find files
that match the controller-spec API. With this API, the directory structure
dictates the paths at which handlers will be mounted.
controllers
|-user
|-create.js
|-list.js
|-product
|-index.js
module.exports = function(router){
router.get('/', function *(next){
this.body = 'Hello koa';
yield next;
});
return router;
};
app.use(bootstrap({
directory: 'controllers'
}));
Routes are now:
/user/create
/user/list
/product
Tests
npm test