Router middleware for koa v2. Inspired by koa-router
feedbacks are welcome
- Express like http verbs methods
- Express like use function
- Express like param function
- Automatic OPTIONS response
- Automatic HEAD when GET is present
- 501 and 405 status
- Mount instance on specific path
- Multiple middleware as arguments
- Multiple middleware as array
# npm install koa-66
const Koa = require('koa');
const Router = require('koa-66');
const app = new Koa();
const router = new Router();
const mainRouter = new Router();
router.param('id', (ctx, next, id) => {
ctx.yolo = id;
return next();
});
router.use(async (ctx, next) => {
ctx.a = " ";
await next();
});
router.get('/:id', (ctx, next) => {
return next().then(() => {
ctx.body += ctx.a + ctx.yolo;
})
});
router.get('/:id', async ctx => {
ctx.body = await Promise.resolve('hello');
});
mainRouter.mount('/pouet', router);
app.use(mainRouter.routes());
app.listen(1664);
// GET http://localhost:1664/pouet/world
// => hello world
# npm test
Why not use koa-route?
- Is a little minimalistic
Why not use koa-router?
- For now koa-router is broken with the new koa release #186