@fastcar/koa 0.1.13 → 0.1.14
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/package.json +9 -9
- package/src/index.ts +2 -2
- package/src/middleware/ExceptionGlobalHandler.ts +1 -1
- package/src/middleware/KoaBody.ts +3 -2
- package/src/middleware/KoaBodyParser.ts +2 -1
- package/src/middleware/KoaCors.ts +3 -2
- package/src/middleware/KoaMulter.ts +2 -1
- package/src/middleware/KoaStatic.ts +5 -3
- package/src/type/KoaConfig.ts +2 -5
- package/target/KoaApplication.js +147 -143
- package/target/annotation/EnableKoa.js +11 -11
- package/target/annotation/KoaMiddleware.js +19 -19
- package/target/annotation/router/AddMapping.js +29 -29
- package/target/annotation/router/AllMapping.js +14 -14
- package/target/annotation/router/DeleteMapping.js +14 -14
- package/target/annotation/router/GetMapping.js +14 -14
- package/target/annotation/router/PatchMapping.js +14 -14
- package/target/annotation/router/PostMapping.js +14 -14
- package/target/annotation/router/PutMapping.js +14 -14
- package/target/annotation/router/RequestMapping.js +22 -22
- package/target/annotation.js +38 -40
- package/target/index.js +19 -19
- package/target/middleware/ExceptionGlobalHandler.js +32 -32
- package/target/middleware/KoaBody.js +10 -10
- package/target/middleware/KoaBodyParser.js +10 -10
- package/target/middleware/KoaCors.js +33 -33
- package/target/middleware/KoaMulter.js +8 -8
- package/target/middleware/KoaStatic.js +38 -38
- package/target/type/DesignMeta.js +7 -7
- package/target/type/KoaConfig.js +2 -2
- package/target/type/MethodType.js +2 -2
- package/target/type/RouteMethods.js +12 -12
- package/test/logs/sys.log +78 -118
- package/test/simple/app.ts +4 -5
- package/src/middleware/Swagger.ts +0 -63
- package/target/middleware/Swagger.js +0 -53
- package/target/npmlist.json +0 -1
- package/test/logs/koa.log +0 -0
- package/test/logs/serverlogger.log +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastcar/koa",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.14",
|
|
4
4
|
"homepage": "https://github.com/williamDazhangyu/fast-car",
|
|
5
5
|
"description": "fastcar框架下对koa的包装",
|
|
6
6
|
"main": "target/index.js",
|
|
@@ -30,17 +30,18 @@
|
|
|
30
30
|
"node": ">=16"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@fastcar/core": "
|
|
33
|
+
"@fastcar/core": "0.3.1",
|
|
34
34
|
"@fastcar/server": "^0.0.3",
|
|
35
35
|
"@types/koa": "^2.13.5",
|
|
36
|
-
"reflect-metadata": "^0.1.13",
|
|
37
36
|
"@types/koa-bodyparser": "^4.3.11",
|
|
38
|
-
"@types/koa-router": "^7.4.6"
|
|
37
|
+
"@types/koa-router": "^7.4.6",
|
|
38
|
+
"@types/koa__multer": "*",
|
|
39
|
+
"reflect-metadata": "*"
|
|
39
40
|
},
|
|
40
41
|
"dependencies": {
|
|
41
|
-
"koa": "^2.
|
|
42
|
+
"koa": "^2.15.3",
|
|
42
43
|
"koa-bodyparser": "^4.4.1",
|
|
43
|
-
"koa-router": "^
|
|
44
|
+
"koa-router": "^13.0.1"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
47
|
"@fastcar/core": "*",
|
|
@@ -58,9 +59,8 @@
|
|
|
58
59
|
"koa-range": "^0.3.0",
|
|
59
60
|
"koa-static": "^5.0.0",
|
|
60
61
|
"koa2-cors": "^2.0.6",
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"multer": "*"
|
|
62
|
+
"multer": "*",
|
|
63
|
+
"swagger-ui-dist": "4.5.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependenciesMeta": {
|
|
66
66
|
"@types/koa-bodyparser": {
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@ import KoaBody from "./middleware/KoaBody";
|
|
|
5
5
|
import KoaBodyParser from "./middleware/KoaBodyParser";
|
|
6
6
|
import KoaCors from "./middleware/KoaCors";
|
|
7
7
|
import KoaStatic from "./middleware/KoaStatic";
|
|
8
|
-
import Swagger from "./middleware/Swagger";
|
|
9
8
|
import { DesignMeta } from "./type/DesignMeta";
|
|
9
|
+
import KoaMulter from "./middleware/KoaMulter";
|
|
10
10
|
|
|
11
|
-
export { KoaApplication, KoaConfig, ExceptionGlobalHandler, KoaBody, KoaBodyParser, KoaCors, KoaStatic,
|
|
11
|
+
export { KoaApplication, KoaConfig, ExceptionGlobalHandler, KoaBody, KoaBodyParser, KoaCors, KoaStatic, KoaMulter, DesignMeta };
|
|
@@ -2,7 +2,7 @@ import { FastCarApplication, ValidError } from "@fastcar/core";
|
|
|
2
2
|
|
|
3
3
|
//默认错误捕捉
|
|
4
4
|
export default function ExceptionGlobalHandler(app: FastCarApplication) {
|
|
5
|
-
|
|
5
|
+
const logger = app.getSysLogger();
|
|
6
6
|
return async (ctx: any, next: Function) => {
|
|
7
7
|
try {
|
|
8
8
|
await next();
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import * as koaBody from "koa-body";
|
|
2
1
|
import { FastCarApplication } from "@fastcar/core";
|
|
3
2
|
import { KoaConfig } from "../type/KoaConfig";
|
|
4
3
|
|
|
5
4
|
//对于文件上传做限定
|
|
6
5
|
export default function KoaBody(app: FastCarApplication) {
|
|
6
|
+
const koaBodyfn = require("koa-body").default;
|
|
7
|
+
|
|
7
8
|
let koaConfig: KoaConfig = app.getSetting("koa");
|
|
8
9
|
let bodyConfig = koaConfig?.koaBodyOptions;
|
|
9
10
|
|
|
10
|
-
return
|
|
11
|
+
return koaBodyfn(bodyConfig);
|
|
11
12
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import * as bodyParser from "koa-bodyparser";
|
|
2
1
|
import { FastCarApplication } from "@fastcar/core";
|
|
3
2
|
import { KoaConfig } from "../type/KoaConfig";
|
|
4
3
|
|
|
5
4
|
//对文件内容做解析
|
|
6
5
|
export default function KoaBodyParser(app: FastCarApplication) {
|
|
6
|
+
const bodyParser = require("koa-bodyparser");
|
|
7
|
+
|
|
7
8
|
let koaConfig: KoaConfig = app.getSetting("koa");
|
|
8
9
|
let bodyConfig = koaConfig?.koaBodyParser;
|
|
9
10
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { FastCarApplication } from "@fastcar/core";
|
|
2
|
-
import * as koa2Cors from "koa2-cors";
|
|
3
2
|
import { KoaConfig } from "../type/KoaConfig";
|
|
4
3
|
import { Context } from "koa";
|
|
5
4
|
|
|
6
5
|
export default function KoaCors(app: FastCarApplication) {
|
|
6
|
+
const koa2Cors = require("koa2-cors");
|
|
7
|
+
|
|
7
8
|
let koaConfig: KoaConfig = app.getSetting("koa");
|
|
8
9
|
if (koaConfig?.extra) {
|
|
9
|
-
let corsConfig
|
|
10
|
+
let corsConfig = Reflect.get(koaConfig.extra, "cors");
|
|
10
11
|
if (!!corsConfig) {
|
|
11
12
|
//兼容支持多个跨域
|
|
12
13
|
if (typeof corsConfig.origin == "string") {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import * as koaStatic from "koa-static";
|
|
2
|
-
import * as KoaRange from "koa-range";
|
|
3
|
-
import * as KoaMount from "koa-mount";
|
|
4
1
|
import { FastCarApplication } from "@fastcar/core";
|
|
5
2
|
import { KoaConfig } from "../type/KoaConfig";
|
|
6
3
|
import * as fs from "fs";
|
|
@@ -9,6 +6,8 @@ import * as Koa from "koa";
|
|
|
9
6
|
|
|
10
7
|
//支持静态文件访问
|
|
11
8
|
export default function KoaStatic(app: FastCarApplication): Koa.Middleware[] {
|
|
9
|
+
const KoaRange = require("koa-range");
|
|
10
|
+
|
|
12
11
|
let mlist: Koa.Middleware[] = [];
|
|
13
12
|
|
|
14
13
|
//采用koa-range使文件可以流式传播
|
|
@@ -17,6 +16,9 @@ export default function KoaStatic(app: FastCarApplication): Koa.Middleware[] {
|
|
|
17
16
|
let koaConfig: KoaConfig = app.getSetting("koa");
|
|
18
17
|
|
|
19
18
|
if (!!koaConfig?.koaStatic) {
|
|
19
|
+
const KoaMount = require("koa-mount").default;
|
|
20
|
+
const koaStatic = require("koa-static").default;
|
|
21
|
+
|
|
20
22
|
let keys = Object.keys(koaConfig?.koaStatic);
|
|
21
23
|
if (keys.length > 0) {
|
|
22
24
|
for (let key of keys) {
|
package/src/type/KoaConfig.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import * as koaBody from "koa-body";
|
|
2
|
-
import * as bodyParser from "koa-bodyparser";
|
|
3
1
|
import { ServerConfig } from "@fastcar/server";
|
|
4
2
|
|
|
5
3
|
//和koa的约定配置
|
|
6
4
|
export type KoaConfig = {
|
|
7
5
|
server: ServerConfig[] | ServerConfig; //监听的端口号
|
|
8
6
|
koaStatic?: { [key: string]: string }; //相对路径为resource下的 或者绝对文件路径
|
|
9
|
-
koaBodyOptions?:
|
|
10
|
-
koaBodyParser?: bodyParser.Options; //解析请求
|
|
7
|
+
koaBodyOptions?: { [key: string]: any }; //文件上传的解析
|
|
8
|
+
koaBodyParser?: { [key: string]: any }; //bodyParser.Options; //解析请求
|
|
11
9
|
extra?: { [key: string]: any }; //拓展设置
|
|
12
|
-
swagger?: { enable: boolean; api: { [alias: string]: string } }; //别名:路径
|
|
13
10
|
};
|
package/target/KoaApplication.js
CHANGED
|
@@ -1,143 +1,147 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
require("reflect-metadata");
|
|
13
|
-
const annotation_1 = require("@fastcar/core/annotation");
|
|
14
|
-
const core_1 = require("@fastcar/core");
|
|
15
|
-
const Koa = require("koa");
|
|
16
|
-
const KoaRouter = require("koa-router");
|
|
17
|
-
const DesignMeta_1 = require("./type/DesignMeta");
|
|
18
|
-
const utils_1 = require("@fastcar/core/utils");
|
|
19
|
-
const server_1 = require("@fastcar/server");
|
|
20
|
-
/***
|
|
21
|
-
* @version 1.0 koa基础组件启动
|
|
22
|
-
*
|
|
23
|
-
*/
|
|
24
|
-
let KoaApplication = class KoaApplication {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
__decorate([
|
|
131
|
-
|
|
132
|
-
__metadata("design:type", core_1.
|
|
133
|
-
], KoaApplication.prototype, "
|
|
134
|
-
__decorate([
|
|
135
|
-
annotation_1.
|
|
136
|
-
__metadata("design:type",
|
|
137
|
-
], KoaApplication.prototype, "
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
require("reflect-metadata");
|
|
13
|
+
const annotation_1 = require("@fastcar/core/annotation");
|
|
14
|
+
const core_1 = require("@fastcar/core");
|
|
15
|
+
const Koa = require("koa");
|
|
16
|
+
const KoaRouter = require("koa-router");
|
|
17
|
+
const DesignMeta_1 = require("./type/DesignMeta");
|
|
18
|
+
const utils_1 = require("@fastcar/core/utils");
|
|
19
|
+
const server_1 = require("@fastcar/server");
|
|
20
|
+
/***
|
|
21
|
+
* @version 1.0 koa基础组件启动
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
let KoaApplication = class KoaApplication {
|
|
25
|
+
app;
|
|
26
|
+
koaLogger;
|
|
27
|
+
koaApp;
|
|
28
|
+
serverApplication;
|
|
29
|
+
constructor() {
|
|
30
|
+
this.koaApp = new Koa();
|
|
31
|
+
}
|
|
32
|
+
/***
|
|
33
|
+
* @version 1.0 加载中间件
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
loadMiddleWare(list) {
|
|
37
|
+
if (Array.isArray(list)) {
|
|
38
|
+
list.forEach((item) => {
|
|
39
|
+
if (utils_1.TypeUtil.isFunction(item)) {
|
|
40
|
+
this.koaApp.use(item);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (utils_1.TypeUtil.isFunction(list)) {
|
|
46
|
+
this.koaApp.use(list);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/***
|
|
51
|
+
* @version 1.0 加载路由
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
loadRoute() {
|
|
55
|
+
let router = new KoaRouter();
|
|
56
|
+
let instanceList = this.app.getComponentByType(core_1.ComponentKind.Controller);
|
|
57
|
+
//查找绑定的url
|
|
58
|
+
instanceList.forEach((instance) => {
|
|
59
|
+
let routerMap = Reflect.getMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, instance);
|
|
60
|
+
//移除空的map结构
|
|
61
|
+
if (!routerMap || routerMap.size == 0) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
routerMap.forEach((item) => {
|
|
65
|
+
//去除ctx的影响
|
|
66
|
+
let callBack = async (ctx, next) => {
|
|
67
|
+
//进行参数的取值
|
|
68
|
+
let body = {};
|
|
69
|
+
//自动合并传参 如果有重合的部分 需要再次单独取就好了
|
|
70
|
+
if (Object.keys(ctx.query).length > 0) {
|
|
71
|
+
Object.assign(body, ctx.query);
|
|
72
|
+
}
|
|
73
|
+
if (!!ctx.request.body) {
|
|
74
|
+
Object.assign(body, ctx.request.body);
|
|
75
|
+
}
|
|
76
|
+
if (!!ctx.params) {
|
|
77
|
+
Object.assign(body, ctx.params);
|
|
78
|
+
}
|
|
79
|
+
let res = await instance[item.method](body, ctx);
|
|
80
|
+
if (utils_1.ValidationUtil.isNotNull(res)) {
|
|
81
|
+
ctx.body = res;
|
|
82
|
+
}
|
|
83
|
+
if (next) {
|
|
84
|
+
await next();
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
for (let r of item.request) {
|
|
88
|
+
//进行绑定 加载router路由的执行方法
|
|
89
|
+
Reflect.apply(router[`${r}`], router, [item.url, callBack]);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
return router.routes();
|
|
94
|
+
}
|
|
95
|
+
start() {
|
|
96
|
+
const koaApp = this.koaApp;
|
|
97
|
+
//加载中间件
|
|
98
|
+
let middlewareList = this.app.getSetting(DesignMeta_1.DesignMeta.KoaMIDDLEWARE);
|
|
99
|
+
if (Array.isArray(middlewareList)) {
|
|
100
|
+
for (let m of middlewareList) {
|
|
101
|
+
if (utils_1.TypeUtil.isPromise(m)) {
|
|
102
|
+
Reflect.apply(m, this, [this.app, koaApp]).then((tmpList) => {
|
|
103
|
+
this.loadMiddleWare(tmpList);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
let tmpList = Reflect.apply(m, this, [this.app, koaApp]);
|
|
108
|
+
this.loadMiddleWare(tmpList);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
//加载路由
|
|
113
|
+
koaApp.use(this.loadRoute());
|
|
114
|
+
//读取配置文件 创建服务器
|
|
115
|
+
let appCallback = koaApp.callback();
|
|
116
|
+
let koaConfig = this.app.getSetting("koa");
|
|
117
|
+
if (!!koaConfig.server) {
|
|
118
|
+
if (Array.isArray(koaConfig.server)) {
|
|
119
|
+
koaConfig.server.forEach((server) => {
|
|
120
|
+
this.serverApplication.createServer(server, appCallback);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
this.serverApplication.createServer(koaConfig.server, appCallback);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async stop() { }
|
|
129
|
+
};
|
|
130
|
+
__decorate([
|
|
131
|
+
annotation_1.Autowired,
|
|
132
|
+
__metadata("design:type", core_1.FastCarApplication)
|
|
133
|
+
], KoaApplication.prototype, "app", void 0);
|
|
134
|
+
__decorate([
|
|
135
|
+
(0, annotation_1.Log)("koa"),
|
|
136
|
+
__metadata("design:type", core_1.Logger)
|
|
137
|
+
], KoaApplication.prototype, "koaLogger", void 0);
|
|
138
|
+
__decorate([
|
|
139
|
+
annotation_1.Autowired,
|
|
140
|
+
__metadata("design:type", server_1.ServerApplication)
|
|
141
|
+
], KoaApplication.prototype, "serverApplication", void 0);
|
|
142
|
+
KoaApplication = __decorate([
|
|
143
|
+
(0, annotation_1.ApplicationStart)(core_1.BootPriority.Lowest, "start"),
|
|
144
|
+
(0, annotation_1.ApplicationStop)(core_1.BootPriority.Base, "stop"),
|
|
145
|
+
__metadata("design:paramtypes", [])
|
|
146
|
+
], KoaApplication);
|
|
147
|
+
exports.default = KoaApplication;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
(0,
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = EnableKoa;
|
|
4
|
+
const annotation_1 = require("@fastcar/core/annotation");
|
|
5
|
+
const server_1 = require("@fastcar/server");
|
|
6
|
+
//开启koa应用
|
|
7
|
+
function EnableKoa(target) {
|
|
8
|
+
let fp = require.resolve("../KoaApplication");
|
|
9
|
+
(0, annotation_1.ComponentInjection)(target, fp);
|
|
10
|
+
(0, server_1.EnableServer)(target);
|
|
11
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = KoaMiddleware;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const DesignMeta_1 = require("../type/DesignMeta");
|
|
6
|
+
//加载koa中间件
|
|
7
|
+
function KoaMiddleware(...args) {
|
|
8
|
+
return function (target) {
|
|
9
|
+
let middlewareList = Reflect.get(target.prototype, DesignMeta_1.DesignMeta.KoaMIDDLEWARE);
|
|
10
|
+
if (!middlewareList) {
|
|
11
|
+
middlewareList = args;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
//由于注解方式是从下至上运行 和我们理解的书写习惯不一样,所以这边做了一个反序
|
|
15
|
+
middlewareList = [...args, ...middlewareList];
|
|
16
|
+
}
|
|
17
|
+
Reflect.set(target.prototype, DesignMeta_1.DesignMeta.KoaMIDDLEWARE, middlewareList);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = AddMapping;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const DesignMeta_1 = require("../../type/DesignMeta");
|
|
6
|
+
function AddMapping(target, info) {
|
|
7
|
+
if (!info.url) {
|
|
8
|
+
info.url = info.method;
|
|
9
|
+
}
|
|
10
|
+
//格式化url 以/开头
|
|
11
|
+
if (!info.url.startsWith("/")) {
|
|
12
|
+
info.url = "/" + info.url;
|
|
13
|
+
}
|
|
14
|
+
let routerMap = Reflect.getMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, target);
|
|
15
|
+
if (!routerMap) {
|
|
16
|
+
routerMap = new Map();
|
|
17
|
+
Reflect.defineMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, routerMap, target);
|
|
18
|
+
}
|
|
19
|
+
let curr = routerMap.get(info.url);
|
|
20
|
+
if (!curr) {
|
|
21
|
+
routerMap.set(info.url, info);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
if (info.url != curr.url) {
|
|
25
|
+
console.warn(`The two URL names are inconsisten in (${info.url},${curr.url})`);
|
|
26
|
+
}
|
|
27
|
+
curr.request = [...info.request, ...curr.request];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = AllMapping;
|
|
4
|
+
const RouteMethods_1 = require("../../type/RouteMethods");
|
|
5
|
+
const AddMapping_1 = require("./AddMapping");
|
|
6
|
+
function AllMapping(url) {
|
|
7
|
+
return function (target, name, descriptor) {
|
|
8
|
+
(0, AddMapping_1.default)(target, {
|
|
9
|
+
url,
|
|
10
|
+
method: name,
|
|
11
|
+
request: [RouteMethods_1.RouteMethods.AllMapping],
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = DeleteMapping;
|
|
4
|
+
const RouteMethods_1 = require("../../type/RouteMethods");
|
|
5
|
+
const AddMapping_1 = require("./AddMapping");
|
|
6
|
+
function DeleteMapping(url) {
|
|
7
|
+
return function (target, name, descriptor) {
|
|
8
|
+
(0, AddMapping_1.default)(target, {
|
|
9
|
+
url,
|
|
10
|
+
method: name,
|
|
11
|
+
request: [RouteMethods_1.RouteMethods.DeleteMapping],
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|