Skip to content

Commit e7c1694

Browse files
author
吴浩麟
committed
pub: 1.1.1
1 parent a819029 commit e7c1694

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ import {HttpMethod, route} from 'koa-decorator';
1414
export default class MonitorCtrl{
1515

1616
@route('/alive', HttpMethod.GET)
17-
async alive() {
18-
// this === ctx
19-
this.body = {
17+
async alive(ctx) {
18+
ctx.body = {
2019
data: true,
2120
};
2221
}
@@ -32,7 +31,6 @@ app.use(apiRouter.routes()).use(apiRouter.allowedMethods());
3231
## Use auth middleware
3332
```js
3433
import {HttpMethod, route} from 'koa-decorator';
35-
import {Context} from 'koa';
3634

3735
function auth(ctx) {
3836
if(!ctx.auth){
@@ -44,8 +42,8 @@ function auth(ctx) {
4442
export default class MonitorCtrl {
4543

4644
@route('/alive', HttpMethod.GET,auth)
47-
async alive() {
48-
this.body = {
45+
async alive(ctx) {
46+
ctx.body = {
4947
data: true,
5048
};
5149
}
@@ -64,11 +62,5 @@ export default class MonitorCtrl {
6462
data: true,
6563
};
6664
}
67-
68-
@route('/echoParams', HttpMethod.GET,auth)
69-
echoParams(param) {
70-
// param的值就是请求的url中的query和body中解析出的参数的合并结果
71-
return param;
72-
}
7365
}
7466
```

index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function getFiles(dir: string, files_?: string[]): string[] {
3030
* 格式化返回数据的格式
3131
*/
3232
async function formatResponse(descriptor: any, ctx: Context) {
33-
const ret = descriptor.value.call(ctx, Object.assign({}, (ctx.request as any).body, ctx.query));
33+
const ret = descriptor.value(ctx);
3434
if (ret != null) {
3535
try {
3636
const data = await Promise.resolve(ret);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"decorator",
88
"@route"
99
],
10-
"version": "1.1.0",
10+
"version": "1.1.1",
1111
"scripts": {
1212
"npm": "tsc"
1313
},

0 commit comments

Comments
 (0)