@midwayjs/koa 3.5.3 → 3.7.0

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.
@@ -3,6 +3,7 @@
3
3
  */
4
4
  export declare const koa: {
5
5
  contextLoggerFormat: (info: any) => string;
6
+ serverTimeout: number;
6
7
  };
7
8
  /**
8
9
  * The key that signing cookies. It can contain multiple keys seperated by `,`.
@@ -24,6 +24,7 @@ exports.koa = {
24
24
  ctx.url;
25
25
  return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
26
26
  },
27
+ serverTimeout: 2 * 60 * 1000,
27
28
  };
28
29
  /**
29
30
  * The key that signing cookies. It can contain multiple keys seperated by `,`.
@@ -10,7 +10,6 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.KoaConfiguration = void 0;
13
- const decorator_1 = require("@midwayjs/decorator");
14
13
  const core_1 = require("@midwayjs/core");
15
14
  const session = require("@midwayjs/session");
16
15
  const framework_1 = require("./framework");
@@ -20,8 +19,9 @@ const fav_middleware_1 = require("./middleware/fav.middleware");
20
19
  let KoaConfiguration = class KoaConfiguration {
21
20
  init() {
22
21
  // register param decorator
23
- this.decoratorService.registerParameterHandler(decorator_1.WEB_ROUTER_PARAM_KEY, options => {
24
- return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1]);
22
+ this.decoratorService.registerParameterHandler(core_1.WEB_ROUTER_PARAM_KEY, options => {
23
+ var _a;
24
+ return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType, (_a = options.metadata) === null || _a === void 0 ? void 0 : _a.pipes)(options.originArgs[0], options.originArgs[1]);
25
25
  });
26
26
  }
27
27
  async onReady() {
@@ -29,25 +29,25 @@ let KoaConfiguration = class KoaConfiguration {
29
29
  }
30
30
  };
31
31
  __decorate([
32
- (0, decorator_1.Inject)(),
32
+ (0, core_1.Inject)(),
33
33
  __metadata("design:type", core_1.MidwayDecoratorService)
34
34
  ], KoaConfiguration.prototype, "decoratorService", void 0);
35
35
  __decorate([
36
- (0, decorator_1.Inject)(),
36
+ (0, core_1.Inject)(),
37
37
  __metadata("design:type", framework_1.MidwayKoaFramework)
38
38
  ], KoaConfiguration.prototype, "koaFramework", void 0);
39
39
  __decorate([
40
- (0, decorator_1.Inject)(),
40
+ (0, core_1.Inject)(),
41
41
  __metadata("design:type", core_1.MidwayConfigService)
42
42
  ], KoaConfiguration.prototype, "configService", void 0);
43
43
  __decorate([
44
- (0, decorator_1.Init)(),
44
+ (0, core_1.Init)(),
45
45
  __metadata("design:type", Function),
46
46
  __metadata("design:paramtypes", []),
47
47
  __metadata("design:returntype", void 0)
48
48
  ], KoaConfiguration.prototype, "init", null);
49
49
  KoaConfiguration = __decorate([
50
- (0, decorator_1.Configuration)({
50
+ (0, core_1.Configuration)({
51
51
  namespace: 'koa',
52
52
  imports: [session],
53
53
  importConfigs: [
@@ -2,7 +2,7 @@
2
2
  import { BaseFramework, CommonFilterUnion, CommonMiddlewareUnion, IMidwayBootstrapOptions, MidwayFrameworkType, RouterInfo } from '@midwayjs/core';
3
3
  import { IMidwayKoaApplication, IMidwayKoaConfigurationOptions, IMidwayKoaContext } from './interface';
4
4
  import type { DefaultState, Middleware, Next } from 'koa';
5
- import { Server } from 'net';
5
+ import { Server } from 'http';
6
6
  export declare class MidwayKoaFramework extends BaseFramework<IMidwayKoaApplication, IMidwayKoaContext, IMidwayKoaConfigurationOptions, Next> {
7
7
  private server;
8
8
  private generator;
@@ -23,7 +23,7 @@ export declare class MidwayKoaFramework extends BaseFramework<IMidwayKoaApplicat
23
23
  beforeStop(): Promise<void>;
24
24
  getFrameworkType(): MidwayFrameworkType;
25
25
  getFrameworkName(): string;
26
- getServer(): Server;
26
+ getServer(): Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
27
27
  getPort(): string;
28
28
  useMiddleware(Middleware: CommonMiddlewareUnion<IMidwayKoaContext, Next, unknown>): void;
29
29
  useFilter(Filter: CommonFilterUnion<IMidwayKoaContext, Next, unknown>): void;
package/dist/framework.js CHANGED
@@ -9,7 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.MidwayKoaFramework = void 0;
10
10
  const core_1 = require("@midwayjs/core");
11
11
  const cookies_1 = require("@midwayjs/cookies");
12
- const decorator_1 = require("@midwayjs/decorator");
13
12
  const Router = require("@koa/router");
14
13
  const koa = require("koa");
15
14
  const onerror_1 = require("./onerror");
@@ -146,6 +145,10 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
146
145
  }
147
146
  // register httpServer to applicationContext
148
147
  this.applicationContext.registerObject(core_1.HTTP_SERVER_KEY, this.server);
148
+ // server timeout
149
+ if (core_1.Types.isNumber(this.configurationOptions.serverTimeout)) {
150
+ this.server.setTimeout(this.configurationOptions.serverTimeout);
151
+ }
149
152
  // set port and listen server
150
153
  const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : this.configurationOptions.port;
151
154
  if (customPort) {
@@ -189,7 +192,7 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
189
192
  }
190
193
  };
191
194
  MidwayKoaFramework = __decorate([
192
- (0, decorator_1.Framework)()
195
+ (0, core_1.Framework)()
193
196
  ], MidwayKoaFramework);
194
197
  exports.MidwayKoaFramework = MidwayKoaFramework;
195
198
  //# sourceMappingURL=framework.js.map
@@ -2,7 +2,7 @@
2
2
  import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
3
3
  import * as koa from 'koa';
4
4
  import { Context as KoaContext, DefaultState, Middleware, Next } from 'koa';
5
- import { RouterParamValue } from '@midwayjs/decorator';
5
+ import { RouterParamValue } from '@midwayjs/core';
6
6
  export declare type IMidwayKoaContext = IMidwayContext<KoaContext>;
7
7
  export declare type IMidwayKoaApplication = IMidwayApplication<IMidwayKoaContext, koa<DefaultState, IMidwayKoaContext> & {
8
8
  generateController(controllerMapping: string, routeArgsInfo?: RouterParamValue[], routerResponseData?: any[]): Middleware<DefaultState, IMidwayKoaContext>;
@@ -66,6 +66,14 @@ export interface IMidwayKoaConfigurationOptions extends IConfigurationOptions {
66
66
  * Max IPs read from proxy IP header, default to 0 (means infinity)
67
67
  */
68
68
  maxIpsCount?: number;
69
+ /**
70
+ * server timeout in milliseconds, default to 2 minutes.
71
+ *
72
+ * for special request, just use `ctx.req.setTimeout(ms)`
73
+ *
74
+ * @see https://nodejs.org/api/http.html#http_server_timeout
75
+ */
76
+ serverTimeout?: number;
69
77
  }
70
78
  export declare type MiddlewareParamArray = Array<Middleware<DefaultState, IMidwayKoaContext>>;
71
79
  export interface IWebMiddleware {
@@ -11,7 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.BodyParserMiddleware = void 0;
13
13
  const koaBodyParser = require("koa-bodyparser");
14
- const decorator_1 = require("@midwayjs/decorator");
14
+ const core_1 = require("@midwayjs/core");
15
15
  let BodyParserMiddleware = class BodyParserMiddleware {
16
16
  resolve() {
17
17
  // use bodyparser middleware
@@ -24,11 +24,11 @@ let BodyParserMiddleware = class BodyParserMiddleware {
24
24
  }
25
25
  };
26
26
  __decorate([
27
- (0, decorator_1.Config)('bodyParser'),
27
+ (0, core_1.Config)('bodyParser'),
28
28
  __metadata("design:type", Object)
29
29
  ], BodyParserMiddleware.prototype, "bodyparserConfig", void 0);
30
30
  BodyParserMiddleware = __decorate([
31
- (0, decorator_1.Middleware)()
31
+ (0, core_1.Middleware)()
32
32
  ], BodyParserMiddleware);
33
33
  exports.BodyParserMiddleware = BodyParserMiddleware;
34
34
  //# sourceMappingURL=bodyparser.middleware.js.map
@@ -10,7 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SiteFileMiddleware = void 0;
13
- const decorator_1 = require("@midwayjs/decorator");
13
+ const core_1 = require("@midwayjs/core");
14
14
  const path = require('path');
15
15
  const MAX_AGE = 'public, max-age=2592000'; // 30 days
16
16
  let SiteFileMiddleware = class SiteFileMiddleware {
@@ -52,11 +52,11 @@ let SiteFileMiddleware = class SiteFileMiddleware {
52
52
  }
53
53
  };
54
54
  __decorate([
55
- (0, decorator_1.Config)('siteFile'),
55
+ (0, core_1.Config)('siteFile'),
56
56
  __metadata("design:type", Object)
57
57
  ], SiteFileMiddleware.prototype, "siteFileConfig", void 0);
58
58
  SiteFileMiddleware = __decorate([
59
- (0, decorator_1.Middleware)()
59
+ (0, core_1.Middleware)()
60
60
  ], SiteFileMiddleware);
61
61
  exports.SiteFileMiddleware = SiteFileMiddleware;
62
62
  //# sourceMappingURL=fav.middleware.js.map
package/dist/onerror.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupOnError = void 0;
4
4
  const http = require("http");
5
5
  const utils_1 = require("./utils");
6
- const decorator_1 = require("@midwayjs/decorator");
6
+ const core_1 = require("@midwayjs/core");
7
7
  function setupOnError(app, config, logger) {
8
8
  const errorOptions = Object.assign({
9
9
  // support customize accepts function
@@ -117,7 +117,7 @@ function setupOnError(app, config, logger) {
117
117
  let errMsg = err;
118
118
  if (typeof err === 'object') {
119
119
  try {
120
- errMsg = decorator_1.Utils.safeStringify(err);
120
+ errMsg = core_1.Utils.safeStringify(err);
121
121
  // eslint-disable-next-line no-empty
122
122
  }
123
123
  catch (e) { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/koa",
3
- "version": "3.5.3",
3
+ "version": "3.7.0",
4
4
  "description": "Midway Web Framework for KOA",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
@@ -24,9 +24,8 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@midwayjs/decorator": "^3.4.11",
28
27
  "@midwayjs/logger": "^2.15.0",
29
- "@midwayjs/mock": "^3.5.3",
28
+ "@midwayjs/mock": "^3.7.0",
30
29
  "@types/koa": "2.13.5",
31
30
  "@types/koa-router": "7.4.4",
32
31
  "fs-extra": "10.0.1"
@@ -34,8 +33,8 @@
34
33
  "dependencies": {
35
34
  "@koa/router": "^11.0.0",
36
35
  "@midwayjs/cookies": "^1.0.2",
37
- "@midwayjs/core": "^3.5.3",
38
- "@midwayjs/session": "^3.5.3",
36
+ "@midwayjs/core": "^3.7.0",
37
+ "@midwayjs/session": "^3.7.0",
39
38
  "koa": "2.13.4",
40
39
  "koa-bodyparser": "4.3.0"
41
40
  },
@@ -47,5 +46,5 @@
47
46
  "engines": {
48
47
  "node": ">=12"
49
48
  },
50
- "gitHead": "32356484664846984f6d3d65a3a75dea015e8dcc"
49
+ "gitHead": "99386083ee26b386fd508b9c892091c914e77535"
51
50
  }