@fastcar/koa 0.1.10 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/package.json +1 -1
- package/src/KoaApplication.ts +10 -5
- package/target/KoaApplication.js +8 -4
- package/test/logs/sys.log +6 -0
- package/test/simple/app.ts +1 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## 快速安装
|
|
4
4
|
|
|
5
|
-
npm install fastcar
|
|
5
|
+
npm install @fastcar/koa
|
|
6
6
|
|
|
7
7
|
## 基本原理
|
|
8
8
|
|
|
@@ -31,12 +31,17 @@ export const app = new APP();
|
|
|
31
31
|
```ts
|
|
32
32
|
import { Controller } from "@fastcar/core/annotation";
|
|
33
33
|
import { GET } from "@fastcar/koa/annotation";
|
|
34
|
+
import { Context } from "koa";
|
|
35
|
+
|
|
34
36
|
|
|
35
37
|
@Controller
|
|
36
38
|
export default class HelloController {
|
|
37
39
|
|
|
38
40
|
@GET("/")
|
|
39
|
-
home() {
|
|
41
|
+
home(params: string, ctx: Context) {
|
|
42
|
+
console.log("这边请注意 params是params和body二合一的参数 重名的值会优先取body的");
|
|
43
|
+
console.log('body取 ctx.request.body');
|
|
44
|
+
console.log('路径后参数取ctx.params');
|
|
40
45
|
return "hello world";
|
|
41
46
|
}
|
|
42
47
|
}
|
package/package.json
CHANGED
package/src/KoaApplication.ts
CHANGED
|
@@ -5,7 +5,7 @@ import * as Koa from "koa";
|
|
|
5
5
|
import * as KoaRouter from "koa-router";
|
|
6
6
|
import { MethodType } from "./type/MethodType";
|
|
7
7
|
import { DesignMeta } from "./type/DesignMeta";
|
|
8
|
-
import { TypeUtil } from "@fastcar/core/utils";
|
|
8
|
+
import { TypeUtil, ValidationUtil } from "@fastcar/core/utils";
|
|
9
9
|
import { KoaConfig } from "./type/KoaConfig";
|
|
10
10
|
import { ServerApplication } from "@fastcar/server";
|
|
11
11
|
|
|
@@ -69,10 +69,15 @@ export default class KoaApplication {
|
|
|
69
69
|
//去除ctx的影响
|
|
70
70
|
let callBack = async (ctx: any, next?: Function) => {
|
|
71
71
|
//进行参数的取值
|
|
72
|
-
let body =
|
|
72
|
+
let body = {};
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
//自动合并传参 如果有重合的部分 需要再次单独取就好了
|
|
75
|
+
if (Object.keys(ctx.query).length > 0) {
|
|
76
|
+
Object.assign(body, ctx.query);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (!!ctx.request.body) {
|
|
80
|
+
Object.assign(body, ctx.request.body);
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
if (!!ctx.params) {
|
|
@@ -80,7 +85,7 @@ export default class KoaApplication {
|
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
let res = await instance[item.method](body, ctx);
|
|
83
|
-
if (
|
|
88
|
+
if (ValidationUtil.isNotNull(res)) {
|
|
84
89
|
ctx.body = res;
|
|
85
90
|
}
|
|
86
91
|
|
package/target/KoaApplication.js
CHANGED
|
@@ -61,15 +61,19 @@ let KoaApplication = class KoaApplication {
|
|
|
61
61
|
//去除ctx的影响
|
|
62
62
|
let callBack = async (ctx, next) => {
|
|
63
63
|
//进行参数的取值
|
|
64
|
-
let body =
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
let body = {};
|
|
65
|
+
//自动合并传参 如果有重合的部分 需要再次单独取就好了
|
|
66
|
+
if (Object.keys(ctx.query).length > 0) {
|
|
67
|
+
Object.assign(body, ctx.query);
|
|
68
|
+
}
|
|
69
|
+
if (!!ctx.request.body) {
|
|
70
|
+
Object.assign(body, ctx.request.body);
|
|
67
71
|
}
|
|
68
72
|
if (!!ctx.params) {
|
|
69
73
|
Object.assign(body, ctx.params);
|
|
70
74
|
}
|
|
71
75
|
let res = await instance[item.method](body, ctx);
|
|
72
|
-
if (
|
|
76
|
+
if (utils_1.ValidationUtil.isNotNull(res)) {
|
|
73
77
|
ctx.body = res;
|
|
74
78
|
}
|
|
75
79
|
if (next) {
|
package/test/logs/sys.log
CHANGED
|
@@ -68,3 +68,9 @@
|
|
|
68
68
|
{"timestamp":"2022-04-23 10:22:04.326","level":"INFO","label":"sys","message":"http server is running in 12234"}
|
|
69
69
|
{"timestamp":"2022-04-23 10:22:04.327","level":"INFO","label":"sys","message":"start server koaSimple is run"}
|
|
70
70
|
{"timestamp":"2022-04-23 10:22:04.328","level":"INFO","label":"sys","message":"version 1.0.0"}
|
|
71
|
+
{"timestamp":"2023-02-18 15:57:04.345","level":"INFO","label":"sys","message":"Start scanning component"}
|
|
72
|
+
{"timestamp":"2023-02-18 15:57:05.478","level":"INFO","label":"sys","message":"Complete component scan"}
|
|
73
|
+
{"timestamp":"2023-02-18 15:57:05.479","level":"INFO","label":"sys","message":"Call application initialization method"}
|
|
74
|
+
{"timestamp":"2023-02-18 15:57:06.254","level":"INFO","label":"sys","message":"http server is running in 1234"}
|
|
75
|
+
{"timestamp":"2023-02-18 15:57:06.256","level":"INFO","label":"sys","message":"start server koaSimple is run"}
|
|
76
|
+
{"timestamp":"2023-02-18 15:57:06.258","level":"INFO","label":"sys","message":"version 1.0.0"}
|
package/test/simple/app.ts
CHANGED
|
@@ -27,8 +27,7 @@ const m2 = (): Koa.Middleware => {
|
|
|
27
27
|
|
|
28
28
|
@Application
|
|
29
29
|
@EnableKoa //开启koa
|
|
30
|
-
@KoaMiddleware(ExceptionGlobalHandler, KoaStatic, KoaBodyParser)
|
|
31
|
-
@KoaMiddleware(KoaCors)
|
|
30
|
+
@KoaMiddleware(ExceptionGlobalHandler, KoaStatic, KoaBodyParser as any)
|
|
32
31
|
@KoaMiddleware(Swagger)
|
|
33
32
|
@KoaMiddleware(m1, m2)
|
|
34
33
|
class APP {
|