@fastcar/koa 0.1.13 → 0.1.15
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/index.d.ts +2 -4
- package/package.json +12 -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
|
@@ -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
|
+
}
|
|
@@ -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 = GetMapping;
|
|
4
|
+
const RouteMethods_1 = require("../../type/RouteMethods");
|
|
5
|
+
const AddMapping_1 = require("./AddMapping");
|
|
6
|
+
function GetMapping(url) {
|
|
7
|
+
return function (target, name, descriptor) {
|
|
8
|
+
(0, AddMapping_1.default)(target, {
|
|
9
|
+
url,
|
|
10
|
+
method: name,
|
|
11
|
+
request: [RouteMethods_1.RouteMethods.GetMapping],
|
|
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 = PatchMapping;
|
|
4
|
+
const RouteMethods_1 = require("../../type/RouteMethods");
|
|
5
|
+
const AddMapping_1 = require("./AddMapping");
|
|
6
|
+
function PatchMapping(url) {
|
|
7
|
+
return function (target, name, descriptor) {
|
|
8
|
+
(0, AddMapping_1.default)(target, {
|
|
9
|
+
url,
|
|
10
|
+
method: name,
|
|
11
|
+
request: [RouteMethods_1.RouteMethods.PatchMapping],
|
|
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 = PostMapping;
|
|
4
|
+
const RouteMethods_1 = require("../../type/RouteMethods");
|
|
5
|
+
const AddMapping_1 = require("./AddMapping");
|
|
6
|
+
function PostMapping(url) {
|
|
7
|
+
return function (target, name, descriptor) {
|
|
8
|
+
(0, AddMapping_1.default)(target, {
|
|
9
|
+
url,
|
|
10
|
+
method: name,
|
|
11
|
+
request: [RouteMethods_1.RouteMethods.PostMapping],
|
|
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 = PutMapping;
|
|
4
|
+
const RouteMethods_1 = require("../../type/RouteMethods");
|
|
5
|
+
const AddMapping_1 = require("./AddMapping");
|
|
6
|
+
function PutMapping(url) {
|
|
7
|
+
return function (target, name, descriptor) {
|
|
8
|
+
(0, AddMapping_1.default)(target, {
|
|
9
|
+
url,
|
|
10
|
+
method: name,
|
|
11
|
+
request: [RouteMethods_1.RouteMethods.PutMapping],
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = RequestMapping;
|
|
4
|
+
require("reflect-metadata");
|
|
5
|
+
const DesignMeta_1 = require("../../type/DesignMeta");
|
|
6
|
+
const utils_1 = require("@fastcar/core/utils");
|
|
7
|
+
//加载值头部的url
|
|
8
|
+
function RequestMapping(url) {
|
|
9
|
+
return function (target) {
|
|
10
|
+
let tname = utils_1.FormatStr.formatFirstToLow(target.name);
|
|
11
|
+
let headUrl = url || tname;
|
|
12
|
+
if (!headUrl.startsWith("/")) {
|
|
13
|
+
headUrl = "/" + headUrl;
|
|
14
|
+
}
|
|
15
|
+
let routerMap = Reflect.getMetadata(DesignMeta_1.DesignMeta.ROUTER_MAP, target.prototype);
|
|
16
|
+
if (!!routerMap) {
|
|
17
|
+
routerMap.forEach((item) => {
|
|
18
|
+
item.url = headUrl + item.url;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
package/target/annotation.js
CHANGED
|
@@ -1,40 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const EnableKoa_1 = require("./annotation/EnableKoa");
|
|
5
|
-
exports.EnableKoa = EnableKoa_1.default;
|
|
6
|
-
const KoaMiddleware_1 = require("./annotation/KoaMiddleware");
|
|
7
|
-
exports.KoaMiddleware = KoaMiddleware_1.default;
|
|
8
|
-
const AddMapping_1 = require("./annotation/router/AddMapping");
|
|
9
|
-
exports.AddMapping = AddMapping_1.default;
|
|
10
|
-
const AllMapping_1 = require("./annotation/router/AllMapping");
|
|
11
|
-
exports.AllMapping = AllMapping_1.default;
|
|
12
|
-
const DeleteMapping_1 = require("./annotation/router/DeleteMapping");
|
|
13
|
-
exports.DeleteMapping = DeleteMapping_1.default;
|
|
14
|
-
const GetMapping_1 = require("./annotation/router/GetMapping");
|
|
15
|
-
exports.GetMapping = GetMapping_1.default;
|
|
16
|
-
const PatchMapping_1 = require("./annotation/router/PatchMapping");
|
|
17
|
-
exports.PatchMapping = PatchMapping_1.default;
|
|
18
|
-
const PostMapping_1 = require("./annotation/router/PostMapping");
|
|
19
|
-
exports.PostMapping = PostMapping_1.default;
|
|
20
|
-
const PutMapping_1 = require("./annotation/router/PutMapping");
|
|
21
|
-
exports.PutMapping = PutMapping_1.default;
|
|
22
|
-
const RequestMapping_1 = require("./annotation/router/RequestMapping");
|
|
23
|
-
exports.RequestMapping = RequestMapping_1.default;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
exports.
|
|
29
|
-
const
|
|
30
|
-
exports.
|
|
31
|
-
const
|
|
32
|
-
exports.
|
|
33
|
-
const
|
|
34
|
-
exports.
|
|
35
|
-
const
|
|
36
|
-
exports.
|
|
37
|
-
const
|
|
38
|
-
exports.
|
|
39
|
-
const REQUEST = RequestMapping_1.default;
|
|
40
|
-
exports.REQUEST = REQUEST;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REQUEST = exports.ALL = exports.PATCH = exports.PUT = exports.DELETE = exports.POST = exports.GET = exports.KoaMiddleware = exports.EnableKoa = exports.RequestMapping = exports.PutMapping = exports.PostMapping = exports.PatchMapping = exports.GetMapping = exports.DeleteMapping = exports.AllMapping = exports.AddMapping = void 0;
|
|
4
|
+
const EnableKoa_1 = require("./annotation/EnableKoa");
|
|
5
|
+
exports.EnableKoa = EnableKoa_1.default;
|
|
6
|
+
const KoaMiddleware_1 = require("./annotation/KoaMiddleware");
|
|
7
|
+
exports.KoaMiddleware = KoaMiddleware_1.default;
|
|
8
|
+
const AddMapping_1 = require("./annotation/router/AddMapping");
|
|
9
|
+
exports.AddMapping = AddMapping_1.default;
|
|
10
|
+
const AllMapping_1 = require("./annotation/router/AllMapping");
|
|
11
|
+
exports.AllMapping = AllMapping_1.default;
|
|
12
|
+
const DeleteMapping_1 = require("./annotation/router/DeleteMapping");
|
|
13
|
+
exports.DeleteMapping = DeleteMapping_1.default;
|
|
14
|
+
const GetMapping_1 = require("./annotation/router/GetMapping");
|
|
15
|
+
exports.GetMapping = GetMapping_1.default;
|
|
16
|
+
const PatchMapping_1 = require("./annotation/router/PatchMapping");
|
|
17
|
+
exports.PatchMapping = PatchMapping_1.default;
|
|
18
|
+
const PostMapping_1 = require("./annotation/router/PostMapping");
|
|
19
|
+
exports.PostMapping = PostMapping_1.default;
|
|
20
|
+
const PutMapping_1 = require("./annotation/router/PutMapping");
|
|
21
|
+
exports.PutMapping = PutMapping_1.default;
|
|
22
|
+
const RequestMapping_1 = require("./annotation/router/RequestMapping");
|
|
23
|
+
exports.RequestMapping = RequestMapping_1.default;
|
|
24
|
+
//声明简化的方式
|
|
25
|
+
const GET = GetMapping_1.default;
|
|
26
|
+
exports.GET = GET;
|
|
27
|
+
const POST = PostMapping_1.default;
|
|
28
|
+
exports.POST = POST;
|
|
29
|
+
const DELETE = DeleteMapping_1.default;
|
|
30
|
+
exports.DELETE = DELETE;
|
|
31
|
+
const PUT = PutMapping_1.default;
|
|
32
|
+
exports.PUT = PUT;
|
|
33
|
+
const PATCH = PatchMapping_1.default;
|
|
34
|
+
exports.PATCH = PATCH;
|
|
35
|
+
const ALL = AllMapping_1.default;
|
|
36
|
+
exports.ALL = ALL;
|
|
37
|
+
const REQUEST = RequestMapping_1.default;
|
|
38
|
+
exports.REQUEST = REQUEST;
|
package/target/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DesignMeta = exports.
|
|
4
|
-
const KoaApplication_1 = require("./KoaApplication");
|
|
5
|
-
exports.KoaApplication = KoaApplication_1.default;
|
|
6
|
-
const ExceptionGlobalHandler_1 = require("./middleware/ExceptionGlobalHandler");
|
|
7
|
-
exports.ExceptionGlobalHandler = ExceptionGlobalHandler_1.default;
|
|
8
|
-
const KoaBody_1 = require("./middleware/KoaBody");
|
|
9
|
-
exports.KoaBody = KoaBody_1.default;
|
|
10
|
-
const KoaBodyParser_1 = require("./middleware/KoaBodyParser");
|
|
11
|
-
exports.KoaBodyParser = KoaBodyParser_1.default;
|
|
12
|
-
const KoaCors_1 = require("./middleware/KoaCors");
|
|
13
|
-
exports.KoaCors = KoaCors_1.default;
|
|
14
|
-
const KoaStatic_1 = require("./middleware/KoaStatic");
|
|
15
|
-
exports.KoaStatic = KoaStatic_1.default;
|
|
16
|
-
const
|
|
17
|
-
exports
|
|
18
|
-
const
|
|
19
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DesignMeta = exports.KoaMulter = exports.KoaStatic = exports.KoaCors = exports.KoaBodyParser = exports.KoaBody = exports.ExceptionGlobalHandler = exports.KoaApplication = void 0;
|
|
4
|
+
const KoaApplication_1 = require("./KoaApplication");
|
|
5
|
+
exports.KoaApplication = KoaApplication_1.default;
|
|
6
|
+
const ExceptionGlobalHandler_1 = require("./middleware/ExceptionGlobalHandler");
|
|
7
|
+
exports.ExceptionGlobalHandler = ExceptionGlobalHandler_1.default;
|
|
8
|
+
const KoaBody_1 = require("./middleware/KoaBody");
|
|
9
|
+
exports.KoaBody = KoaBody_1.default;
|
|
10
|
+
const KoaBodyParser_1 = require("./middleware/KoaBodyParser");
|
|
11
|
+
exports.KoaBodyParser = KoaBodyParser_1.default;
|
|
12
|
+
const KoaCors_1 = require("./middleware/KoaCors");
|
|
13
|
+
exports.KoaCors = KoaCors_1.default;
|
|
14
|
+
const KoaStatic_1 = require("./middleware/KoaStatic");
|
|
15
|
+
exports.KoaStatic = KoaStatic_1.default;
|
|
16
|
+
const DesignMeta_1 = require("./type/DesignMeta");
|
|
17
|
+
Object.defineProperty(exports, "DesignMeta", { enumerable: true, get: function () { return DesignMeta_1.DesignMeta; } });
|
|
18
|
+
const KoaMulter_1 = require("./middleware/KoaMulter");
|
|
19
|
+
exports.KoaMulter = KoaMulter_1.default;
|
|
@@ -1,32 +1,32 @@
|
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = ExceptionGlobalHandler;
|
|
4
|
+
const core_1 = require("@fastcar/core");
|
|
5
|
+
//默认错误捕捉
|
|
6
|
+
function ExceptionGlobalHandler(app) {
|
|
7
|
+
const logger = app.getSysLogger();
|
|
8
|
+
return async (ctx, next) => {
|
|
9
|
+
try {
|
|
10
|
+
await next();
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
//新增如果是校验的错误则进行输出
|
|
14
|
+
if (e instanceof core_1.ValidError) {
|
|
15
|
+
ctx.body = {
|
|
16
|
+
code: 400,
|
|
17
|
+
msg: e.message || "parameter error",
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
logger.error(`${ctx.url} is error`);
|
|
22
|
+
if (e) {
|
|
23
|
+
logger.error(e);
|
|
24
|
+
}
|
|
25
|
+
ctx.body = {
|
|
26
|
+
code: 500,
|
|
27
|
+
msg: "Service internal error",
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
//对于文件上传做限定
|
|
5
|
-
function KoaBody(app) {
|
|
6
|
-
|
|
7
|
-
let
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = KoaBody;
|
|
4
|
+
//对于文件上传做限定
|
|
5
|
+
function KoaBody(app) {
|
|
6
|
+
const koaBodyfn = require("koa-body").default;
|
|
7
|
+
let koaConfig = app.getSetting("koa");
|
|
8
|
+
let bodyConfig = koaConfig?.koaBodyOptions;
|
|
9
|
+
return koaBodyfn(bodyConfig);
|
|
10
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
//对文件内容做解析
|
|
5
|
-
function KoaBodyParser(app) {
|
|
6
|
-
|
|
7
|
-
let
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = KoaBodyParser;
|
|
4
|
+
//对文件内容做解析
|
|
5
|
+
function KoaBodyParser(app) {
|
|
6
|
+
const bodyParser = require("koa-bodyparser");
|
|
7
|
+
let koaConfig = app.getSetting("koa");
|
|
8
|
+
let bodyConfig = koaConfig?.koaBodyParser;
|
|
9
|
+
return bodyParser(bodyConfig);
|
|
10
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
function KoaCors(app) {
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = KoaCors;
|
|
4
|
+
function KoaCors(app) {
|
|
5
|
+
const koa2Cors = require("koa2-cors");
|
|
6
|
+
let koaConfig = app.getSetting("koa");
|
|
7
|
+
if (koaConfig?.extra) {
|
|
8
|
+
let corsConfig = Reflect.get(koaConfig.extra, "cors");
|
|
9
|
+
if (!!corsConfig) {
|
|
10
|
+
//兼容支持多个跨域
|
|
11
|
+
if (typeof corsConfig.origin == "string") {
|
|
12
|
+
let origins = corsConfig.origin.split(";");
|
|
13
|
+
Reflect.set(corsConfig, "origin", (ctx) => {
|
|
14
|
+
let orign = ctx?.request?.header?.origin;
|
|
15
|
+
if (!orign) {
|
|
16
|
+
if (!origins.includes("*")) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return "*";
|
|
20
|
+
}
|
|
21
|
+
for (let o of origins) {
|
|
22
|
+
if (orign.startsWith(o) || o == "*") {
|
|
23
|
+
return o;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return koa2Cors(corsConfig);
|
|
31
|
+
}
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
//对文件内容做解析
|
|
5
|
-
function KoaMulter(app) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = KoaMulter;
|
|
4
|
+
//对文件内容做解析
|
|
5
|
+
function KoaMulter(app) {
|
|
6
|
+
const multer = require("@koa/multer");
|
|
7
|
+
return multer().single();
|
|
8
|
+
}
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = KoaStatic;
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
//支持静态文件访问
|
|
7
|
+
function KoaStatic(app) {
|
|
8
|
+
const KoaRange = require("koa-range");
|
|
9
|
+
let mlist = [];
|
|
10
|
+
//采用koa-range使文件可以流式传播
|
|
11
|
+
mlist.push(KoaRange);
|
|
12
|
+
let koaConfig = app.getSetting("koa");
|
|
13
|
+
if (!!koaConfig?.koaStatic) {
|
|
14
|
+
const KoaMount = require("koa-mount").default;
|
|
15
|
+
const koaStatic = require("koa-static").default;
|
|
16
|
+
let keys = Object.keys(koaConfig?.koaStatic);
|
|
17
|
+
if (keys.length > 0) {
|
|
18
|
+
for (let key of keys) {
|
|
19
|
+
let fp = koaConfig.koaStatic[key];
|
|
20
|
+
let rp = path.join(app.getResourcePath(), fp);
|
|
21
|
+
if (!fs.existsSync(fp)) {
|
|
22
|
+
if (!fs.existsSync(rp)) {
|
|
23
|
+
console.error(`${fp} is not found`);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
fp = rp;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!key.startsWith("/")) {
|
|
31
|
+
key = `/${key}`;
|
|
32
|
+
}
|
|
33
|
+
mlist.push(KoaMount(key, koaStatic(fp)));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return mlist;
|
|
38
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DesignMeta = void 0;
|
|
4
|
-
exports.DesignMeta = {
|
|
5
|
-
ROUTER_MAP: Symbol("ROUTER_MAP"),
|
|
6
|
-
KoaMIDDLEWARE: Symbol("KoaMIDDLEWARE"), //中间件
|
|
7
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DesignMeta = void 0;
|
|
4
|
+
exports.DesignMeta = {
|
|
5
|
+
ROUTER_MAP: Symbol("ROUTER_MAP"), //map路由
|
|
6
|
+
KoaMIDDLEWARE: Symbol("KoaMIDDLEWARE"), //中间件
|
|
7
|
+
};
|
package/target/type/KoaConfig.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|