@fastcar/koa 0.1.17 → 0.1.19

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/annotation.d.ts CHANGED
@@ -6,6 +6,8 @@ type Ret = (target: any) => void;
6
6
 
7
7
  type MRet = (target: any, name: string, descriptor: PropertyDescriptor) => void;
8
8
 
9
+ type PMRet = (target: any, propertyKey: string) => void;
10
+
9
11
  type MiddleWareType = (...args: any) => Koa.Middleware | Koa.Middleware[];
10
12
 
11
13
  //关于请求方式注解
@@ -44,3 +46,5 @@ export function EnableKoa(target: any): void;
44
46
 
45
47
  //中间件添加拓展
46
48
  export function KoaMiddleware(...args: MiddleWareType[]): Ret;
49
+
50
+ export function KoaApp(): PMRet;
package/index.d.ts CHANGED
@@ -7,7 +7,7 @@ type MiddleWareType = (...args: any) => Koa.Middleware | Koa.Middleware[];
7
7
  export class KoaApplication {
8
8
  protected app: FastCarApplication;
9
9
  protected sysLogger: Logger;
10
- protected koaApp: Koa;
10
+ public koaApp: Koa;
11
11
 
12
12
  /***
13
13
  * @version 1.0 加载中间件
@@ -61,4 +61,7 @@ export function Swagger(app: FastCarApplication): MiddleWareType;
61
61
  //增强multi文件解析
62
62
  export function KoaMulter(app: FastCarApplication): MiddleWareType;
63
63
 
64
+ //校验header 头编码是否错误
65
+ export function HeaderCoding(): MiddleWareType;
66
+
64
67
  export * from "./src/type/DesignMeta";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastcar/koa",
3
- "version": "0.1.17",
3
+ "version": "0.1.19",
4
4
  "homepage": "https://github.com/williamDazhangyu/fast-car",
5
5
  "description": "fastcar框架下对koa的包装",
6
6
  "main": "target/index.js",
@@ -30,7 +30,7 @@
30
30
  "node": ">=18"
31
31
  },
32
32
  "devDependencies": {
33
- "@fastcar/core": "0.3.1",
33
+ "@fastcar/core": "^0.3.10",
34
34
  "@fastcar/server": "^0.0.3",
35
35
  "@types/co-body": "^6.1.3",
36
36
  "@types/koa": "^2.13.5",
@@ -8,7 +8,6 @@ import { DesignMeta } from "./type/DesignMeta";
8
8
  import { TypeUtil, ValidationUtil } from "@fastcar/core/utils";
9
9
  import { KoaConfig } from "./type/KoaConfig";
10
10
  import { ServerApplication } from "@fastcar/server";
11
-
12
11
  /***
13
12
  * @version 1.0 koa基础组件启动
14
13
  *
@@ -22,7 +21,7 @@ export default class KoaApplication {
22
21
  @Log("koa")
23
22
  protected koaLogger!: Logger;
24
23
 
25
- protected koaApp: Koa;
24
+ public koaApp: Koa;
26
25
 
27
26
  @Autowired
28
27
  private serverApplication!: ServerApplication;
@@ -0,0 +1,21 @@
1
+ import { FastCarMetaData } from "@fastcar/core";
2
+ import KoaApplication from "../KoaApplication";
3
+
4
+ const koaApp = "koaApp";
5
+
6
+ /**
7
+ * @version 1.0.0 获取koa-app方法
8
+ */
9
+ export default function KoaApp(target: any, propertyKey: string) {
10
+ Reflect.defineMetadata(
11
+ FastCarMetaData.InjectionValue,
12
+ [
13
+ {
14
+ key: koaApp,
15
+ propertyKey: propertyKey,
16
+ relayTarget: KoaApplication,
17
+ },
18
+ ],
19
+ target
20
+ );
21
+ }
package/src/annotation.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import EnableKoa from "./annotation/EnableKoa";
2
+ import KoaApp from "./annotation/KoaApp";
2
3
  import KoaMiddleware from "./annotation/KoaMiddleware";
3
4
  import AddMapping from "./annotation/router/AddMapping";
4
5
  import AllMapping from "./annotation/router/AllMapping";
@@ -40,4 +41,5 @@ export {
40
41
  PATCH,
41
42
  ALL,
42
43
  REQUEST,
44
+ KoaApp,
43
45
  };
package/src/index.ts CHANGED
@@ -7,5 +7,6 @@ import KoaCors from "./middleware/KoaCors";
7
7
  import KoaStatic from "./middleware/KoaStatic";
8
8
  import { DesignMeta } from "./type/DesignMeta";
9
9
  import KoaMulter from "./middleware/KoaMulter";
10
+ import HeaderCoding from "./middleware/HeaderCoding";
10
11
 
11
- export { KoaApplication, KoaConfig, ExceptionGlobalHandler, KoaBody, KoaBodyParser, KoaCors, KoaStatic, KoaMulter, DesignMeta };
12
+ export { KoaApplication, KoaConfig, ExceptionGlobalHandler, KoaBody, KoaBodyParser, KoaCors, KoaStatic, KoaMulter, HeaderCoding, DesignMeta };
@@ -0,0 +1,14 @@
1
+ //处理由于第三方头不规范导致的问题
2
+ import * as koa from "koa";
3
+
4
+ const ValidEncoding = ["gzip", "deflate", "br", "identity"];
5
+
6
+ export default function HeaderCoding() {
7
+ return async function (ctx: koa.Context, next: Function) {
8
+ let encoding = ctx.headers["content-encoding"];
9
+ if (encoding && !ValidEncoding.includes(encoding)) {
10
+ delete ctx.headers["content-encoding"];
11
+ }
12
+ await next();
13
+ };
14
+ }
@@ -24,7 +24,7 @@ export default function KoaCors(app: FastCarApplication) {
24
24
 
25
25
  for (let o of origins) {
26
26
  if (orign.startsWith(o) || o == "*") {
27
- return o;
27
+ return orign;
28
28
  }
29
29
  }
30
30
 
@@ -1,7 +1,5 @@
1
- import { FastCarApplication } from "@fastcar/core";
2
-
3
1
  //对文件内容做解析
4
- export default function KoaMulter(app: FastCarApplication) {
2
+ export default function KoaMulter() {
5
3
  const multer = require("@koa/multer");
6
4
 
7
5
  return multer().single();
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = KoaApp;
4
+ const core_1 = require("@fastcar/core");
5
+ const KoaApplication_1 = require("../KoaApplication");
6
+ const koaApp = "koaApp";
7
+ /**
8
+ * @version 1.0.0 获取koa-app方法
9
+ */
10
+ function KoaApp(target, propertyKey) {
11
+ Reflect.defineMetadata(core_1.FastCarMetaData.InjectionValue, [
12
+ {
13
+ key: koaApp,
14
+ propertyKey: propertyKey,
15
+ relayTarget: KoaApplication_1.default,
16
+ },
17
+ ], target);
18
+ }
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
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;
3
+ exports.KoaApp = 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
4
  const EnableKoa_1 = require("./annotation/EnableKoa");
5
5
  exports.EnableKoa = EnableKoa_1.default;
6
+ const KoaApp_1 = require("./annotation/KoaApp");
7
+ exports.KoaApp = KoaApp_1.default;
6
8
  const KoaMiddleware_1 = require("./annotation/KoaMiddleware");
7
9
  exports.KoaMiddleware = KoaMiddleware_1.default;
8
10
  const AddMapping_1 = require("./annotation/router/AddMapping");
package/target/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
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;
3
+ exports.DesignMeta = exports.HeaderCoding = exports.KoaMulter = exports.KoaStatic = exports.KoaCors = exports.KoaBodyParser = exports.KoaBody = exports.ExceptionGlobalHandler = exports.KoaApplication = void 0;
4
4
  const KoaApplication_1 = require("./KoaApplication");
5
5
  exports.KoaApplication = KoaApplication_1.default;
6
6
  const ExceptionGlobalHandler_1 = require("./middleware/ExceptionGlobalHandler");
@@ -17,3 +17,5 @@ const DesignMeta_1 = require("./type/DesignMeta");
17
17
  Object.defineProperty(exports, "DesignMeta", { enumerable: true, get: function () { return DesignMeta_1.DesignMeta; } });
18
18
  const KoaMulter_1 = require("./middleware/KoaMulter");
19
19
  exports.KoaMulter = KoaMulter_1.default;
20
+ const HeaderCoding_1 = require("./middleware/HeaderCoding");
21
+ exports.HeaderCoding = HeaderCoding_1.default;
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = HeaderCoding;
4
+ const ValidEncoding = ["gzip", "deflate", "br", "identity"];
5
+ function HeaderCoding() {
6
+ return async function (ctx, next) {
7
+ let encoding = ctx.headers["content-encoding"];
8
+ if (encoding && !ValidEncoding.includes(encoding)) {
9
+ delete ctx.headers["content-encoding"];
10
+ }
11
+ await next();
12
+ };
13
+ }
@@ -20,7 +20,7 @@ function KoaCors(app) {
20
20
  }
21
21
  for (let o of origins) {
22
22
  if (orign.startsWith(o) || o == "*") {
23
- return o;
23
+ return orign;
24
24
  }
25
25
  }
26
26
  return false;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = KoaMulter;
4
4
  //对文件内容做解析
5
- function KoaMulter(app) {
5
+ function KoaMulter() {
6
6
  const multer = require("@koa/multer");
7
7
  return multer().single();
8
8
  }
package/test/logs/sys.log CHANGED
@@ -99,3 +99,51 @@
99
99
  {"timestamp":"2024-12-12 18:31:21.714","level":"INFO","label":"sys","message":"http server is running in 1234"}
100
100
  {"timestamp":"2024-12-12 18:31:21.715","level":"INFO","label":"sys","message":"start server koaSimple is run"}
101
101
  {"timestamp":"2024-12-12 18:31:21.716","level":"INFO","label":"sys","message":"version 1.0.0"}
102
+ {"timestamp":"2025-06-27 10:53:27.408","level":"INFO","label":"sys","message":"Start scanning component"}
103
+ {"timestamp":"2025-06-27 10:53:29.281","level":"INFO","label":"sys","message":"Complete component scan"}
104
+ {"timestamp":"2025-06-27 10:53:29.282","level":"INFO","label":"sys","message":"Call application initialization method"}
105
+ {"timestamp":"2025-06-27 10:53:29.294","level":"INFO","label":"sys","message":"http server is running in 1234"}
106
+ {"timestamp":"2025-06-27 10:53:29.295","level":"INFO","label":"sys","message":"start server koaSimple is run"}
107
+ {"timestamp":"2025-06-27 10:53:29.296","level":"INFO","label":"sys","message":"version 1.0.0"}
108
+ {"timestamp":"2025-07-10 12:05:03.685","level":"INFO","label":"sys","message":"Start scanning component"}
109
+ {"timestamp":"2025-07-10 12:05:04.200","level":"INFO","label":"sys","message":"Complete component scan"}
110
+ {"timestamp":"2025-07-10 12:05:04.201","level":"INFO","label":"sys","message":"Call application initialization method"}
111
+ {"timestamp":"2025-07-10 12:05:04.211","level":"ERROR","label":"sys","message":"Unhandled Rejection at:","splat":"[{}]"}
112
+ {"timestamp":"2025-07-10 12:05:04.222","level":"ERROR","label":"sys","message":"reason: Cannot find module 'koa2-cors'\nRequire stack:\n- D:\\code\\fast-car\\fastcar-koa\\target\\middleware\\KoaCors.js\n- D:\\code\\fast-car\\fastcar-koa\\target\\index.js\n- D:\\code\\fast-car\\fastcar-koa\\test\\simple\\app.ts","splat":"[{\"code\":\"MODULE_NOT_FOUND\",\"requireStack\":[\"D:\\\\code\\\\fast-car\\\\fastcar-koa\\\\target\\\\middleware\\\\KoaCors.js\",\"D:\\\\code\\\\fast-car\\\\fastcar-koa\\\\target\\\\index.js\",\"D:\\\\code\\\\fast-car\\\\fastcar-koa\\\\test\\\\simple\\\\app.ts\"]}]","stack":"Error: Cannot find module 'koa2-cors'\nRequire stack:\n- D:\\code\\fast-car\\fastcar-koa\\target\\middleware\\KoaCors.js\n- D:\\code\\fast-car\\fastcar-koa\\target\\index.js\n- D:\\code\\fast-car\\fastcar-koa\\test\\simple\\app.ts\n at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)\n at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (D:\\code\\fast-car\\node_modules\\@cspotcode\\source-map-support\\source-map-support.js:811:30)\n at Function.Module._load (node:internal/modules/cjs/loader:986:27)\n at Module.require (node:internal/modules/cjs/loader:1233:19)\n at require (node:internal/modules/helpers:179:18)\n at KoaApplication.KoaCors (D:\\code\\fast-car\\fastcar-koa\\target\\middleware\\KoaCors.js:5:22)\n at KoaApplication.start (D:\\code\\fast-car\\fastcar-koa\\src\\KoaApplication.ts:119:63)\n at FastCarApplication.automaticRun (D:\\code\\fast-car\\fastcar-koa\\node_modules\\@fastcar\\core\\target\\FastCarApplication.js:632:25)\n at FastCarApplication.startServer (D:\\code\\fast-car\\fastcar-koa\\node_modules\\@fastcar\\core\\target\\FastCarApplication.js:658:20)\n at FastCarApplication.init (D:\\code\\fast-car\\fastcar-koa\\node_modules\\@fastcar\\core\\target\\FastCarApplication.js:565:14)"}
113
+ {"timestamp":"2025-07-10 12:05:04.232","level":"INFO","label":"sys","message":"application stop"}
114
+ {"timestamp":"2025-07-10 12:05:35.465","level":"INFO","label":"sys","message":"Start scanning component"}
115
+ {"timestamp":"2025-07-10 12:05:35.946","level":"INFO","label":"sys","message":"Complete component scan"}
116
+ {"timestamp":"2025-07-10 12:05:35.948","level":"INFO","label":"sys","message":"Call application initialization method"}
117
+ {"timestamp":"2025-07-10 12:05:35.955","level":"ERROR","label":"sys","message":"Unhandled Rejection at:","splat":"[{}]"}
118
+ {"timestamp":"2025-07-10 12:05:35.962","level":"ERROR","label":"sys","message":"reason: Cannot find module 'koa2-cors'\nRequire stack:\n- D:\\code\\fast-car\\fastcar-koa\\target\\middleware\\KoaCors.js\n- D:\\code\\fast-car\\fastcar-koa\\target\\index.js\n- D:\\code\\fast-car\\fastcar-koa\\test\\simple\\app.ts","splat":"[{\"code\":\"MODULE_NOT_FOUND\",\"requireStack\":[\"D:\\\\code\\\\fast-car\\\\fastcar-koa\\\\target\\\\middleware\\\\KoaCors.js\",\"D:\\\\code\\\\fast-car\\\\fastcar-koa\\\\target\\\\index.js\",\"D:\\\\code\\\\fast-car\\\\fastcar-koa\\\\test\\\\simple\\\\app.ts\"]}]","stack":"Error: Cannot find module 'koa2-cors'\nRequire stack:\n- D:\\code\\fast-car\\fastcar-koa\\target\\middleware\\KoaCors.js\n- D:\\code\\fast-car\\fastcar-koa\\target\\index.js\n- D:\\code\\fast-car\\fastcar-koa\\test\\simple\\app.ts\n at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)\n at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (D:\\code\\fast-car\\node_modules\\@cspotcode\\source-map-support\\source-map-support.js:811:30)\n at Function.Module._load (node:internal/modules/cjs/loader:986:27)\n at Module.require (node:internal/modules/cjs/loader:1233:19)\n at require (node:internal/modules/helpers:179:18)\n at KoaApplication.KoaCors (D:\\code\\fast-car\\fastcar-koa\\target\\middleware\\KoaCors.js:5:22)\n at KoaApplication.start (D:\\code\\fast-car\\fastcar-koa\\src\\KoaApplication.ts:119:63)\n at FastCarApplication.automaticRun (D:\\code\\fast-car\\fastcar-koa\\node_modules\\@fastcar\\core\\target\\FastCarApplication.js:632:25)\n at FastCarApplication.startServer (D:\\code\\fast-car\\fastcar-koa\\node_modules\\@fastcar\\core\\target\\FastCarApplication.js:658:20)\n at FastCarApplication.init (D:\\code\\fast-car\\fastcar-koa\\node_modules\\@fastcar\\core\\target\\FastCarApplication.js:565:14)"}
119
+ {"timestamp":"2025-07-10 12:05:35.968","level":"INFO","label":"sys","message":"application stop"}
120
+ {"timestamp":"2025-07-10 12:06:06.534","level":"INFO","label":"sys","message":"Start scanning component"}
121
+ {"timestamp":"2025-07-10 12:06:07.09","level":"INFO","label":"sys","message":"Complete component scan"}
122
+ {"timestamp":"2025-07-10 12:06:07.10","level":"INFO","label":"sys","message":"Call application initialization method"}
123
+ {"timestamp":"2025-07-10 12:06:07.71","level":"INFO","label":"sys","message":"http server is running in 1234"}
124
+ {"timestamp":"2025-07-10 12:06:07.72","level":"INFO","label":"sys","message":"start server koaSimple is run"}
125
+ {"timestamp":"2025-07-10 12:06:07.74","level":"INFO","label":"sys","message":"version 1.0.0"}
126
+ {"timestamp":"2025-07-10 12:07:46.25","level":"INFO","label":"sys","message":"Start scanning component"}
127
+ {"timestamp":"2025-07-10 12:07:46.605","level":"INFO","label":"sys","message":"Complete component scan"}
128
+ {"timestamp":"2025-07-10 12:07:46.606","level":"INFO","label":"sys","message":"Call application initialization method"}
129
+ {"timestamp":"2025-07-10 12:07:58.52","level":"INFO","label":"sys","message":"http server is running in 1234"}
130
+ {"timestamp":"2025-07-10 12:07:58.53","level":"INFO","label":"sys","message":"start server koaSimple is run"}
131
+ {"timestamp":"2025-07-10 12:07:58.54","level":"INFO","label":"sys","message":"version 1.0.0"}
132
+ {"timestamp":"2025-07-10 12:10:15.710","level":"INFO","label":"sys","message":"Start scanning component"}
133
+ {"timestamp":"2025-07-10 12:10:16.267","level":"INFO","label":"sys","message":"Complete component scan"}
134
+ {"timestamp":"2025-07-10 12:10:16.268","level":"INFO","label":"sys","message":"Call application initialization method"}
135
+ {"timestamp":"2025-07-10 12:10:16.282","level":"INFO","label":"sys","message":"http server is running in 1234"}
136
+ {"timestamp":"2025-07-10 12:10:16.283","level":"INFO","label":"sys","message":"start server koaSimple is run"}
137
+ {"timestamp":"2025-07-10 12:10:16.284","level":"INFO","label":"sys","message":"version 1.0.0"}
138
+ {"timestamp":"2025-07-10 13:33:03.144","level":"INFO","label":"sys","message":"Start scanning component"}
139
+ {"timestamp":"2025-07-10 13:33:04.649","level":"INFO","label":"sys","message":"Complete component scan"}
140
+ {"timestamp":"2025-07-10 13:33:04.650","level":"INFO","label":"sys","message":"Call application initialization method"}
141
+ {"timestamp":"2025-07-10 13:33:04.671","level":"INFO","label":"sys","message":"http server is running in 1234"}
142
+ {"timestamp":"2025-07-10 13:33:04.672","level":"INFO","label":"sys","message":"start server koaSimple is run"}
143
+ {"timestamp":"2025-07-10 13:33:04.673","level":"INFO","label":"sys","message":"version 1.0.0"}
144
+ {"timestamp":"2025-07-29 16:31:09.811","level":"INFO","label":"sys","message":"Start scanning component"}
145
+ {"timestamp":"2025-07-29 16:31:11.641","level":"INFO","label":"sys","message":"Complete component scan"}
146
+ {"timestamp":"2025-07-29 16:31:11.641","level":"INFO","label":"sys","message":"Call application initialization method"}
147
+ {"timestamp":"2025-07-29 16:31:11.648","level":"INFO","label":"sys","message":"http server is running in 1234"}
148
+ {"timestamp":"2025-07-29 16:31:11.648","level":"INFO","label":"sys","message":"start server koaSimple is run"}
149
+ {"timestamp":"2025-07-29 16:31:11.649","level":"INFO","label":"sys","message":"version 1.0.0"}