You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var kr = require('kr');
app.use(kr.get('/pets', authenticate, pets.list));
app.use(kr.get('/pets/:name', authenticate, pets.show));
Features
This repo is essentially a fork of koa-route, with two API differences:
support for route middleware
populates this.params
Installation
$npminstallkr
Example
Contrived resource-oriented example:
varkoa=require('koa');varkr=require('kr');varapp=koa();vardb={tobi: {name: 'tobi',species: 'ferret'},loki: {name: 'loki',species: 'ferret'},jane: {name: 'jane',species: 'ferret'}};function*authenticate(next){// authenticate or redirectyieldnext;}varpets={list: function*(){varnames=Object.keys(db);this.body='pets: '+names.join(', ');},show: function*(){varname=this.params.name;varpet=db[name];if(!pet)returnthis.throw('cannot find that pet',404);this.body=pet.name+' is a '+pet.species;}};app.use(kr.get('/pets',authenticate,pets.list));app.use(kr.get('/pets/:name',authenticate,pets.show));app.listen(3000);console.log('listening on port 3000');