@midwayjs/express 3.19.2 → 4.0.0-alpha.1

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,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.bodyParser = exports.cookieParser = exports.express = void 0;
4
4
  exports.express = {
5
5
  contextLoggerFormat: info => {
6
- var _a, _b;
7
6
  const req = info.ctx;
8
7
  // format: '[$userId/$ip/$traceId/$use_ms $method $url]'
9
- const userId = ((_a = req === null || req === void 0 ? void 0 : req['session']) === null || _a === void 0 ? void 0 : _a['userId']) || '-';
10
- const traceId = (_b = req.traceId) !== null && _b !== void 0 ? _b : '-';
8
+ const userId = req?.['session']?.['userId'] || '-';
9
+ const traceId = req.traceId ?? '-';
11
10
  const use = Date.now() - info.ctx.startTime;
12
11
  const label = userId +
13
12
  '/' +
@@ -23,14 +23,14 @@ let ExpressConfiguration = class ExpressConfiguration {
23
23
  });
24
24
  }
25
25
  async onReady() {
26
- var _a, _b;
27
- const keys = (_a = this.configService.getConfiguration('express.keys')) !== null && _a !== void 0 ? _a : this.configService.getConfiguration('keys');
26
+ const keys = this.configService.getConfiguration('express.keys') ??
27
+ this.configService.getConfiguration('keys');
28
28
  const cookieParserConfig = this.configService.getConfiguration('cookieParser');
29
29
  if (cookieParserConfig.enable) {
30
30
  // add cookie parser middleware
31
31
  this.expressFramework
32
32
  .getMiddleware()
33
- .insertFirst(cookieParser((_b = cookieParserConfig.secret) !== null && _b !== void 0 ? _b : keys, cookieParserConfig.options));
33
+ .insertFirst(cookieParser(cookieParserConfig.secret ?? keys, cookieParserConfig.options));
34
34
  }
35
35
  // add body parser
36
36
  const bodyparserConfig = this.configService.getConfiguration('bodyParser');
@@ -52,6 +52,7 @@ let ExpressConfiguration = class ExpressConfiguration {
52
52
  }
53
53
  }
54
54
  };
55
+ exports.ExpressConfiguration = ExpressConfiguration;
55
56
  __decorate([
56
57
  (0, core_1.Inject)(),
57
58
  __metadata("design:type", core_1.MidwayDecoratorService)
@@ -70,7 +71,7 @@ __decorate([
70
71
  __metadata("design:paramtypes", []),
71
72
  __metadata("design:returntype", void 0)
72
73
  ], ExpressConfiguration.prototype, "init", null);
73
- ExpressConfiguration = __decorate([
74
+ exports.ExpressConfiguration = ExpressConfiguration = __decorate([
74
75
  (0, core_1.Configuration)({
75
76
  namespace: 'express',
76
77
  imports: [session],
@@ -81,5 +82,4 @@ ExpressConfiguration = __decorate([
81
82
  ],
82
83
  })
83
84
  ], ExpressConfiguration);
84
- exports.ExpressConfiguration = ExpressConfiguration;
85
85
  //# sourceMappingURL=configuration.js.map
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { BaseFramework, IMidwayBootstrapOptions, MiddlewareRespond, MidwayFrameworkType, RouterInfo } from '@midwayjs/core';
2
+ import { BaseFramework, IMidwayBootstrapOptions, MiddlewareRespond, RouterInfo } from '@midwayjs/core';
3
3
  import { IMidwayExpressApplication, IMidwayExpressConfigurationOptions, Context } from './interface';
4
4
  import type { IRouter, IRouterHandler, Response, NextFunction } from 'express';
5
5
  import { Server } from 'net';
@@ -11,7 +11,6 @@ export declare class MidwayExpressFramework extends BaseFramework<IMidwayExpress
11
11
  configure(): IMidwayExpressConfigurationOptions;
12
12
  applicationInitialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
13
13
  run(): Promise<void>;
14
- getFrameworkType(): MidwayFrameworkType;
15
14
  /**
16
15
  * wrap controller string to middleware function
17
16
  */
package/dist/framework.js CHANGED
@@ -46,7 +46,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
46
46
  this.app.use = this.app.useMiddleware;
47
47
  }
48
48
  async run() {
49
- var _a;
50
49
  debug(`[express]: use middlewares = "${this.getMiddleware().getNames()}"`);
51
50
  // restore use method
52
51
  this.app.use = this.app.originUse;
@@ -80,10 +79,9 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
80
79
  this.filterManager
81
80
  .runErrorFilter(err, req, res, next)
82
81
  .then(data => {
83
- var _a, _b;
84
82
  const { result, error } = data;
85
83
  if (error) {
86
- const status = (_b = (_a = error.status) !== null && _a !== void 0 ? _a : res.statusCode) !== null && _b !== void 0 ? _b : 500;
84
+ const status = error.status ?? res.statusCode ?? 500;
87
85
  // 5xx
88
86
  if (status >= 500) {
89
87
  try {
@@ -141,7 +139,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
141
139
  }
142
140
  // register httpServer to applicationContext
143
141
  this.applicationContext.registerObject(core_1.HTTP_SERVER_KEY, this.server);
144
- const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : this.configurationOptions.port;
142
+ const customPort = process.env.MIDWAY_HTTP_PORT ?? this.configurationOptions.port;
145
143
  if (customPort) {
146
144
  new Promise(resolve => {
147
145
  const args = [customPort];
@@ -156,9 +154,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
156
154
  });
157
155
  }
158
156
  }
159
- getFrameworkType() {
160
- return core_1.MidwayFrameworkType.WEB_EXPRESS;
161
- }
162
157
  /**
163
158
  * wrap controller string to middleware function
164
159
  */
@@ -215,7 +210,6 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
215
210
  });
216
211
  }
217
212
  async loadMidwayController() {
218
- var _a, _b;
219
213
  this.webRouterService = await this.applicationContext.getAsync(core_1.MidwayWebRouterService, [
220
214
  {
221
215
  globalPrefix: this.configurationOptions.globalPrefix,
@@ -230,7 +224,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
230
224
  this.logger.debug(`Load Controller "${routerInfo.controllerId}", prefix=${routerInfo.prefix}`);
231
225
  // new router
232
226
  const newRouter = this.createRouter(routerInfo.routerOptions);
233
- routerInfo.middleware = (_a = routerInfo.middleware) !== null && _a !== void 0 ? _a : [];
227
+ routerInfo.middleware = routerInfo.middleware ?? [];
234
228
  // add router middleware
235
229
  if (routerInfo.middleware.length) {
236
230
  const routerMiddlewareFn = await this.expressMiddlewareService.compose(routerInfo.middleware, this.app);
@@ -241,7 +235,7 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
241
235
  for (const routeInfo of routes) {
242
236
  const routeMiddlewareList = [];
243
237
  // routeInfo middleware
244
- routeInfo.middleware = (_b = routeInfo.middleware) !== null && _b !== void 0 ? _b : [];
238
+ routeInfo.middleware = routeInfo.middleware ?? [];
245
239
  if (routeInfo.middleware.length) {
246
240
  const routeMiddlewareFn = await this.expressMiddlewareService.compose(routeInfo.middleware, this.app);
247
241
  routeMiddlewareList.push(routeMiddlewareFn);
@@ -287,11 +281,11 @@ let MidwayExpressFramework = class MidwayExpressFramework extends core_1.BaseFra
287
281
  return process.env.MIDWAY_HTTP_PORT;
288
282
  }
289
283
  getFrameworkName() {
290
- return 'midway:express';
284
+ return 'express';
291
285
  }
292
286
  };
293
- MidwayExpressFramework = __decorate([
287
+ exports.MidwayExpressFramework = MidwayExpressFramework;
288
+ exports.MidwayExpressFramework = MidwayExpressFramework = __decorate([
294
289
  (0, core_1.Framework)()
295
290
  ], MidwayExpressFramework);
296
- exports.MidwayExpressFramework = MidwayExpressFramework;
297
291
  //# sourceMappingURL=framework.js.map
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { CommonMiddlewareUnion, ContextMiddlewareManager, FunctionMiddleware, IConfigurationOptions, IMiddleware, IMidwayApplication, IMidwayContext } from '@midwayjs/core';
3
4
  import { Application as ExpressApplication, NextFunction as ExpressNextFunction, Request as ExpressRequest, Response as ExpressResponse } from 'express';
4
5
  type Request = IMidwayContext<ExpressRequest>;
@@ -117,12 +117,12 @@ let MidwayExpressMiddlewareService = class MidwayExpressMiddlewareService {
117
117
  return composeFn;
118
118
  }
119
119
  };
120
- MidwayExpressMiddlewareService = __decorate([
120
+ exports.MidwayExpressMiddlewareService = MidwayExpressMiddlewareService;
121
+ exports.MidwayExpressMiddlewareService = MidwayExpressMiddlewareService = __decorate([
121
122
  (0, core_1.Provide)(),
122
123
  (0, core_1.Scope)(core_1.ScopeEnum.Singleton),
123
124
  __metadata("design:paramtypes", [Object])
124
125
  ], MidwayExpressMiddlewareService);
125
- exports.MidwayExpressMiddlewareService = MidwayExpressMiddlewareService;
126
126
  function wrapMiddleware(mw, options) {
127
127
  // support options.enable
128
128
  if (options.enable === false)
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@midwayjs/express",
3
- "version": "3.19.2",
3
+ "version": "4.0.0-alpha.1",
4
4
  "description": "Midway Web Framework for Express",
5
5
  "main": "dist/index.js",
6
6
  "typings": "index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand",
10
- "cov": "node --require=ts-node/register ../../node_modules/.bin/jest --runInBand --coverage --forceExit",
9
+ "test": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand",
10
+ "cov": "node -r ts-node/register ../../node_modules/jest/bin/jest.js --runInBand --coverage --forceExit",
11
11
  "ci": "npm run test"
12
12
  },
13
13
  "keywords": [
@@ -24,14 +24,14 @@
24
24
  ],
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@midwayjs/mock": "^3.19.2",
27
+ "@midwayjs/core": "^4.0.0-alpha.1",
28
+ "@midwayjs/mock": "^4.0.0-alpha.1",
28
29
  "@types/body-parser": "1.19.5",
29
30
  "@types/express": "4.17.21",
30
31
  "fs-extra": "11.2.0"
31
32
  },
32
33
  "dependencies": {
33
- "@midwayjs/core": "^3.19.0",
34
- "@midwayjs/express-session": "^3.19.2",
34
+ "@midwayjs/express-session": "^4.0.0-alpha.1",
35
35
  "body-parser": "1.20.3",
36
36
  "cookie-parser": "^1.4.6",
37
37
  "express": "4.21.2"
@@ -44,5 +44,5 @@
44
44
  "engines": {
45
45
  "node": ">=12"
46
46
  },
47
- "gitHead": "57fd034be94897fb819b0d9ef776de0b9923ab0f"
47
+ "gitHead": "14bb4da91805a1cf52f190c0d37a74b395dd6372"
48
48
  }