1.0.1 • Published 7 years ago

koa-router-decorator v1.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

build status

Intro

Use decorator for koa.

Support typescript with experimentalDecorators, but not test on javascript.

Usage

First, in your tsconfig.json, set experimentalDecorators to true.

import Route from 'koa-router-decorator'
import Koa from 'koa'

@Route.init()
class TestRoute {
  @Route.get('/')
  async index (ctx: Koa.Context) {
    const result = await Promise.resolve(1)
    ctx.body = result
  }
}
const testRoute = new TestRoute()

const app = new Koa()
app.use((testRoute as any).routes())

const res = await supertest(app.listen())
  .get('/')
  .expect(200)

t.true(res.text === '1')