0.1.0 • Published 9 years ago

koa-enrouten v0.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
9 years ago

koa-enrouten

Route configuration middleware for koajs.

NPM version build status

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