@midwayjs/web 3.0.2 → 3.0.6

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.
@@ -9,7 +9,6 @@ module.exports = appInfo => {
9
9
  const exports = {};
10
10
 
11
11
  exports.rundir = path.join(appInfo.appDir, 'run');
12
-
13
12
  // 修改默认的日志名
14
13
  exports.midwayLogger = {
15
14
  clients: {
package/dist/base.js CHANGED
@@ -114,7 +114,8 @@ const createAppWorkerLoader = () => {
114
114
  appDir: this.appDir,
115
115
  baseDir: this.baseDir,
116
116
  ignore: ['**/app/extend/**'],
117
- }).then(r => {
117
+ application: this.app,
118
+ }).then(_ => {
118
119
  debug('[egg]: global context: init complete');
119
120
  });
120
121
  }
@@ -21,7 +21,10 @@ let EggConfiguration = class EggConfiguration {
21
21
  async onReady() {
22
22
  // ps: 本想在这里清理掉egg添加的中间件,但是这里的数组已经只有一个 midway root middleware,其他的 getter 都是 egg 加进去的,但是不会被中间件执行,所以不需要清理
23
23
  // 去掉为了 egg-socket.io 报错扫进去的 session
24
- this.app.middleware = this.app.middleware.slice(0);
24
+ this.app.middleware =
25
+ Array.isArray(this.app.middleware) && this.app.middleware.length
26
+ ? this.app.middleware.slice()
27
+ : [];
25
28
  }
26
29
  async onServerReady() {
27
30
  // trigger server didReady
@@ -72,6 +75,25 @@ EggConfiguration = __decorate([
72
75
  },
73
76
  egg: {
74
77
  dumpConfig: true,
78
+ contextLoggerFormat: info => {
79
+ const ctx = info.ctx;
80
+ // format: '[$userId/$ip/$traceId/$use_ms $method $url]'
81
+ const userId = ctx.userId || '-';
82
+ const traceId = (ctx.tracer && ctx.tracer.traceId) || '-';
83
+ const use = Date.now() - ctx.startTime;
84
+ const label = userId +
85
+ '/' +
86
+ ctx.ip +
87
+ '/' +
88
+ traceId +
89
+ '/' +
90
+ use +
91
+ 'ms ' +
92
+ ctx.method +
93
+ ' ' +
94
+ ctx.url;
95
+ return `${info.timestamp} ${info.LEVEL} ${info.pid} [${label}] ${info.message}`;
96
+ },
75
97
  },
76
98
  },
77
99
  test: {
@@ -26,7 +26,7 @@ export declare class MidwayWebFramework extends BaseFramework<Application, Conte
26
26
  getFrameworkType(): MidwayFrameworkType;
27
27
  run(): Promise<void>;
28
28
  getLogger(name?: string): any;
29
- setContextLoggerClass(BaseContextLogger: any): void;
29
+ setContextLoggerClass(): void;
30
30
  generateMiddleware(middlewareId: any): Promise<any>;
31
31
  beforeStop(): Promise<void>;
32
32
  }
@@ -16,7 +16,6 @@ const router_1 = require("@eggjs/router");
16
16
  const logger_1 = require("@midwayjs/logger");
17
17
  const path_1 = require("path");
18
18
  const util_1 = require("util");
19
- const logger_2 = require("../logger");
20
19
  const debug = (0, util_1.debuglog)('midway:debug');
21
20
  class EggControllerGenerator extends core_1.WebControllerGenerator {
22
21
  constructor(app) {
@@ -69,11 +68,15 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
69
68
  if (!this.isClusterMode) {
70
69
  await this.initSingleProcessEgg();
71
70
  }
71
+ else {
72
+ // get app in cluster mode
73
+ this.app = options['application'];
74
+ }
72
75
  // not found middleware
73
76
  const notFound = async (ctx, next) => {
74
77
  await next();
75
- if (!ctx._matchedRoute) {
76
- throw new core_1.httpError.NotFoundError();
78
+ if (!ctx._matchedRoute && ctx.body === undefined) {
79
+ throw new core_1.httpError.NotFoundError(`${ctx.path} Not Found`);
77
80
  }
78
81
  };
79
82
  // insert error handler
@@ -136,8 +139,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
136
139
  }, ['createAnonymousContext']);
137
140
  // if use midway logger will be use midway custom context logger
138
141
  debug(`[egg]: overwrite BaseContextLoggerClass to "${processType}"`);
139
- this.setContextLoggerClass(this.configService.getConfiguration('egg.ContextLoggerClass') ||
140
- logger_2.MidwayEggContextLogger);
142
+ this.setContextLoggerClass();
141
143
  }
142
144
  async loadMidwayController() {
143
145
  await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
@@ -211,9 +213,17 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
211
213
  }
212
214
  return this.appLogger;
213
215
  }
214
- setContextLoggerClass(BaseContextLogger) {
215
- this.BaseContextLoggerClass = BaseContextLogger;
216
- this.app.ContextLogger = BaseContextLogger;
216
+ setContextLoggerClass() {
217
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
218
+ const self = this;
219
+ class MidwayEggContextLogger extends logger_1.MidwayContextLogger {
220
+ constructor(ctx, appLogger) {
221
+ super(ctx, appLogger, {
222
+ contextFormat: self.contextLoggerFormat,
223
+ });
224
+ }
225
+ }
226
+ this.app.ContextLogger = MidwayEggContextLogger;
217
227
  }
218
228
  async generateMiddleware(middlewareId) {
219
229
  const mwIns = await this.getApplicationContext().getAsync(middlewareId);
package/dist/logger.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ILogger, MidwayContextLogger } from '@midwayjs/logger';
2
- import { Application, Context } from 'egg';
1
+ import { ILogger } from '@midwayjs/logger';
2
+ import { Application } from 'egg';
3
3
  declare class MidwayLoggers extends Map<string, ILogger> {
4
4
  app: Application;
5
5
  /**
@@ -29,8 +29,5 @@ declare class MidwayLoggers extends Map<string, ILogger> {
29
29
  reload(): void;
30
30
  }
31
31
  export declare const createLoggers: (app: Application, processType: 'agent' | 'app') => MidwayLoggers;
32
- export declare class MidwayEggContextLogger extends MidwayContextLogger<Context> {
33
- formatContextLabel(): string;
34
- }
35
32
  export {};
36
33
  //# sourceMappingURL=logger.d.ts.map
package/dist/logger.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayEggContextLogger = exports.createLoggers = void 0;
3
+ exports.createLoggers = void 0;
4
4
  const logger_1 = require("@midwayjs/logger");
5
5
  const path_1 = require("path");
6
6
  const fs_1 = require("fs");
@@ -171,25 +171,4 @@ const createLoggers = (app, processType) => {
171
171
  return loggers;
172
172
  };
173
173
  exports.createLoggers = createLoggers;
174
- class MidwayEggContextLogger extends logger_1.MidwayContextLogger {
175
- formatContextLabel() {
176
- const ctx = this.ctx;
177
- // format: '[$userId/$ip/$traceId/$use_ms $method $url]'
178
- const userId = ctx.userId || '-';
179
- const traceId = (ctx.tracer && ctx.tracer.traceId) || '-';
180
- const use = Date.now() - ctx.startTime;
181
- return (userId +
182
- '/' +
183
- ctx.ip +
184
- '/' +
185
- traceId +
186
- '/' +
187
- use +
188
- 'ms ' +
189
- ctx.method +
190
- ' ' +
191
- ctx.url);
192
- }
193
- }
194
- exports.MidwayEggContextLogger = MidwayEggContextLogger;
195
174
  //# sourceMappingURL=logger.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/web",
3
- "version": "3.0.2",
3
+ "version": "3.0.6",
4
4
  "description": "Midway Web Framework for Egg.js",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -27,12 +27,14 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@midwayjs/decorator": "^3.0.2",
31
- "@midwayjs/logger": "^2.14.0",
32
- "@midwayjs/mock": "^3.0.2",
30
+ "@midwayjs/decorator": "^3.0.6",
31
+ "@midwayjs/logger": "^2.15.0",
32
+ "@midwayjs/mock": "^3.0.6",
33
+ "axios": "^0.25.0",
33
34
  "dayjs": "1.10.7",
34
35
  "egg-logger": "2.7.1",
35
36
  "egg-mock": "4.2.0",
37
+ "egg-scripts": "2.15.2",
36
38
  "egg-socket.io": "4.1.6",
37
39
  "egg-view-nunjucks": "2.3.0",
38
40
  "fake-egg": "1.0.0",
@@ -44,7 +46,7 @@
44
46
  },
45
47
  "dependencies": {
46
48
  "@eggjs/router": "^2.0.0",
47
- "@midwayjs/core": "^3.0.2",
49
+ "@midwayjs/core": "^3.0.6",
48
50
  "egg": "^2.28.0",
49
51
  "find-up": "5.0.0",
50
52
  "mkdirp": "^1.0.4"
@@ -57,5 +59,5 @@
57
59
  "engines": {
58
60
  "node": ">=12"
59
61
  },
60
- "gitHead": "ca77247d229978a736e79bb208579c014ed226fc"
62
+ "gitHead": "afaa5b59a2be85e915233a9268c0e05965dd5c61"
61
63
  }