koa-router-decorator

    1.0.1 • Public • Published

    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')
     

    Install

    npm i koa-router-decorator

    DownloadsWeekly Downloads

    0

    Version

    1.0.1

    License

    MIT

    Last publish

    Collaborators

    • lxxyx