@tadashi/koa-router
v1.1.0
Published
The simple and tiny route middleware for koa.
Downloads
22
Maintainers
Readme
koa-router
The simple and tiny route middleware for koa.
Install
$ npm i @tadashi/koa-router
Usage
Contrived example:
import Koa from 'koa'
import router from '@tadashi/koa-router'
const fakeAuth = (ctx, next) => {
ctx.state.auth = true
return next()
}
const productMiddleware = ctx => {
ctx.body = {
auth: ctx.state.auth,
id: ctx.params.id
}
}
const app = new Koa()
app
.use(router.get('/product/:id', fakeAuth, productMiddleware))
.use(router.all('/', ctx => {
ctx.body = 'nothing to see here!'
}))
//...
[!TIP]
It's possible to use koa-compose to group routes.
See an example in router.spec.js.
[!IMPORTANT]
Buy me a coffee!
BTC:bc1q7famhuj5f25n6qvlm3sssnymk2qpxrfwpyq7g4
License
MIT © Thiago Lagden