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