koa-router-ts
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

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) {}

}

Readme

Keywords

none

Package Sidebar

Install

npm i koa-router-ts

Weekly Downloads

54

Version

3.0.0

License

MIT

Unpacked Size

13.6 kB

Total Files

6

Last publish

Collaborators

  • liuguili