Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lxxyx/koa-router-decorator
Use koa-router with decorator
https://github.com/lxxyx/koa-router-decorator
Last synced: about 1 month ago
JSON representation
Use koa-router with decorator
- Host: GitHub
- URL: https://github.com/lxxyx/koa-router-decorator
- Owner: Lxxyx
- License: mit
- Created: 2017-04-17T03:38:32.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-14T04:09:49.000Z (over 7 years ago)
- Last Synced: 2024-12-15T09:37:39.731Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 34.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![build status](https://travis-ci.org/Lxxyx/koa-router-decorator.svg?branch=master)
# Intro
Use decorator for koa.Support typescript with experimentalDecorators, but not test on javascript.
## Usage
First, in your `tsconfig.json`, set `experimentalDecorators` to `true`.
```js
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')
```