koa-enrouten
v0.1.0
Published
An koa route initialization and configuration module.
Downloads
1
Readme
koa-enrouten
Route configuration middleware for koajs.
Installation
$ npm install koa-enrouten
API
app.use(enrouten(options))
var koa = require('koa');
var enrouten = require('koa-enrouten');
var app = koa();
app.use(enrouten({directory:'controllers'}));
app.listen(3002);
directory
The directory
configuration option (optional) is the path to a directory.
Specify a directory to have enrouten 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
// create.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