Useage
install
npm install koa-router-ts
yarn add koa-router-ts
Usage
1. Load all controller
import { loadControllers } from 'koa-router-ts'
import Koa from 'koa'
const app = new Koa()
const router = loadControllers('./controllers', { recurse: true })
app.use(router.routes())
app.use(router.allowedMethods())
2. decorate controller
Usage 2.x version
import { Controller, Get } from 'koa-router-ts'
@Controller('/admin')
export default class {
@Get('/hello-admin', passport.authenticate('jwt'))
async hi(ctx: any) {
ctx.body = 'hi, i am admin.'
}
}
Usage 1.x version
import { controller, route, HttpMethod } from 'koa-router-ts'
@controller('/users')
export default class UserController {
@router('/:id', HttpMethod.GET, passport.authenticate('jwt'))
async userInfo(ctx: any) {}
}