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

Package Sidebar

Install

npm i koa-dispatch

Weekly Downloads

2

Version

2.0.2

License

MIT

Last publish

Collaborators

  • hallas