1.0.6 • Published 3 years ago
koa-router-transfer-class-to-router v1.0.6
transferClassToRouter
npm i koa-router-transfer-class-to-router
Methods that are prefixed with HTTP requests will be added to the route
class News {
get(ctx){
ctx.body = 'getIndex'
}
getName(ctx){
ctx.body = 'my name is ok
}
}
module.exports = transferClassToRouter(News)
equivalent to
const router = new require('koa-router)
router.get('/', ctx=> {
ctx.bidy = 'getIndex
})
router.get('/name', ctx=> {
ctx.body = 'my name is ok'
})
module.exports = router