koa-enrouten

0.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i koa-enrouten

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • mdemo