koa-autoroute

0.0.3 • Public • Published

koa-autoroute

A simple wrap for koa-route that will make your life easier :)

API

autoroute(apiUrlRoot, handlerFileRoot)

Example

var koa = require('koa'),
    autoroute = require('koa-autoroute');
 
var app = koa();
 
// Setup autoroute.
// For example 'GET /api/foo/bar/test/xxx' will be route to handler.get.xxx or handler.all.xxx if any of them exists  
// where handler = require(__dirname + 'api/foo/bar/test.js')
app.use(autoroute('/api/', __dirname + '/api'));
 
// Yep, you can use it just the same way as koa-route.
app.use(autoroute.get('/test', function *() {
    this.body = 'haha';
}));
 
console.log('Test server is now listening on port 20080');
app.listen(20080);

Readme

Keywords

none

Package Sidebar

Install

npm i koa-autoroute

Weekly Downloads

4

Version

0.0.3

License

MIT

Last publish

Collaborators

  • talrasha007