koa-dispatch

2.0.2 • Public • Published

Simple router for Koa but with some nice features such as params and multiple route handlers.

var app = require('koa')();
var dispatch = require('koa-dispatch');
 
dispatch.param('name', function* (name) {
  if (name == 'walter') this.noAccess = true;
  this.pet = { name: name };
});
 
function* hasPermission () {
  if (this.noAccess) this.throw(403);
}
 
function* getPet () {
  this.body = this.pet;
}
 
app.use(dispatch.get('/pets/:name', hasPermission, getPet));
app.listen(3000);
 

Installation

$ npm install koa-dispatch

Test

$ make test

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.2
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.2
    1
  • 2.0.1
    2
  • 2.0.0
    2

Package Sidebar

Install

npm i koa-dispatch

Weekly Downloads

5

Version

2.0.2

License

MIT

Last publish

Collaborators

  • hallas