@midwayjs/web 3.3.9 → 3.4.0-beta.11

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.
@@ -1,22 +1,16 @@
1
- import { BaseFramework, IMidwayBootstrapOptions, RouterInfo, WebControllerGenerator } from '@midwayjs/core';
1
+ import { BaseFramework, IMidwayBootstrapOptions } from '@midwayjs/core';
2
2
  import { MidwayFrameworkType } from '@midwayjs/decorator';
3
3
  import { IMidwayWebConfigurationOptions, Application, Context } from '../interface';
4
- import { EggRouter } from '@eggjs/router';
5
4
  import { EggLogger } from 'egg';
6
- declare class EggControllerGenerator extends WebControllerGenerator<EggRouter> {
7
- readonly app: any;
8
- constructor(app: any);
9
- createRouter(routerOptions: any): EggRouter;
10
- generateController(routeInfo: RouterInfo): (ctx: any, next: any) => Promise<void>;
11
- }
12
5
  export declare class MidwayWebFramework extends BaseFramework<Application, Context, IMidwayWebConfigurationOptions> {
13
6
  protected loggers: {
14
7
  [name: string]: EggLogger;
15
8
  };
16
- generator: EggControllerGenerator;
9
+ private generator;
17
10
  private server;
18
11
  private agent;
19
12
  private isClusterMode;
13
+ private webRouterService;
20
14
  appDir: any;
21
15
  configure(): any;
22
16
  initSingleProcessEgg(): Promise<void>;
@@ -31,5 +25,4 @@ export declare class MidwayWebFramework extends BaseFramework<Application, Conte
31
25
  beforeStop(): Promise<void>;
32
26
  setServer(server: any): void;
33
27
  }
34
- export {};
35
28
  //# sourceMappingURL=web.d.ts.map
@@ -18,9 +18,10 @@ const path_1 = require("path");
18
18
  const util_1 = require("util");
19
19
  const debug = (0, util_1.debuglog)('midway:debug');
20
20
  class EggControllerGenerator extends core_1.WebControllerGenerator {
21
- constructor(app) {
22
- super(app);
21
+ constructor(app, webRouterService) {
22
+ super(app, webRouterService);
23
23
  this.app = app;
24
+ this.webRouterService = webRouterService;
24
25
  }
25
26
  createRouter(routerOptions) {
26
27
  const router = new router_1.EggRouter(routerOptions, this.app);
@@ -73,19 +74,39 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
73
74
  this.app = options['application'];
74
75
  }
75
76
  // not found middleware
76
- const notFound = async (ctx, next) => {
77
+ const midwayRouterNotFound = async (ctx, next) => {
77
78
  await next();
78
79
  if (!ctx._matchedRoute && ctx.body === undefined) {
79
80
  throw new core_1.httpError.NotFoundError(`${ctx.path} Not Found`);
80
81
  }
81
82
  };
83
+ const bodyPatch = async (ctx, next) => {
84
+ await next();
85
+ if (ctx.body === undefined &&
86
+ !ctx.response._explicitStatus &&
87
+ ctx._matchedRoute) {
88
+ // 如果进了路由,重新赋值,防止 404
89
+ ctx.body = undefined;
90
+ }
91
+ if (ctx.response._midwayControllerNullBody &&
92
+ ctx.body &&
93
+ ctx.status === 204) {
94
+ ctx.status = 200;
95
+ }
96
+ };
82
97
  // insert error handler
83
98
  const midwayRootMiddleware = async (ctx, next) => {
84
99
  // this.app.createAnonymousContext(ctx);
85
- await (await this.applyMiddleware(notFound))(ctx, next);
100
+ this.middlewareManager.insertAfter(bodyPatch, 'notfound');
101
+ await (await this.applyMiddleware(midwayRouterNotFound))(ctx, next);
86
102
  };
87
103
  this.app.use(midwayRootMiddleware);
88
- this.generator = new EggControllerGenerator(this.app);
104
+ this.webRouterService = await this.applicationContext.getAsync(core_1.MidwayWebRouterService, [
105
+ {
106
+ globalPrefix: this.configurationOptions.globalPrefix,
107
+ },
108
+ ]);
109
+ this.generator = new EggControllerGenerator(this.app, this.webRouterService);
89
110
  this.overwriteApplication('app');
90
111
  this.app.loader.loadOrigin();
91
112
  // 这里拦截 app.use 方法,让他可以加到 midway 的 middlewareManager 中
@@ -149,7 +170,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
149
170
  async loadMidwayController() {
150
171
  // move egg router to last
151
172
  this.app.getMiddleware().findAndInsertLast('eggRouterMiddleware');
152
- await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
173
+ await this.generator.loadMidwayController(newRouter => {
153
174
  var _a;
154
175
  const dispatchFn = newRouter.middleware();
155
176
  dispatchFn._name = `midwayController(${((_a = newRouter === null || newRouter === void 0 ? void 0 : newRouter.opts) === null || _a === void 0 ? void 0 : _a.prefix) || '/'})`;
package/dist/logger.js CHANGED
@@ -14,8 +14,9 @@ function isEmptyFile(p) {
14
14
  return (0, fs_1.statSync)(p).size === 0;
15
15
  }
16
16
  const levelTransform = level => {
17
+ // egg 自定义日志,不设置 level,默认是 info
17
18
  if (!level) {
18
- return undefined;
19
+ return 'info';
19
20
  }
20
21
  switch (level) {
21
22
  case 'NONE':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/web",
3
- "version": "3.3.9",
3
+ "version": "3.4.0-beta.11",
4
4
  "description": "Midway Web Framework for Egg.js",
5
5
  "main": "dist/index",
6
6
  "typings": "index.d.ts",
@@ -28,14 +28,14 @@
28
28
  ],
29
29
  "license": "MIT",
30
30
  "devDependencies": {
31
- "@midwayjs/decorator": "^3.3.4",
31
+ "@midwayjs/decorator": "^3.4.0-beta.11",
32
32
  "@midwayjs/logger": "^2.15.0",
33
- "@midwayjs/mock": "^3.3.5",
34
- "axios": "0.26.1",
35
- "dayjs": "1.10.8",
36
- "egg-logger": "2.7.1",
33
+ "@midwayjs/mock": "^3.4.0-beta.11",
34
+ "axios": "0.27.2",
35
+ "dayjs": "1.11.3",
36
+ "egg-logger": "2.8.0",
37
37
  "egg-mock": "4.2.1",
38
- "egg-scripts": "2.15.3",
38
+ "egg-scripts": "2.17.0",
39
39
  "egg-socket.io": "4.1.6",
40
40
  "egg-view-nunjucks": "2.3.0",
41
41
  "fake-egg": "1.0.0",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "dependencies": {
49
49
  "@eggjs/router": "^2.0.0",
50
- "@midwayjs/core": "^3.3.5",
50
+ "@midwayjs/core": "^3.4.0-beta.11",
51
51
  "egg": "^2.28.0",
52
52
  "egg-cluster": "^1.27.1",
53
53
  "find-up": "5.0.0",
@@ -61,5 +61,5 @@
61
61
  "engines": {
62
62
  "node": ">=12"
63
63
  },
64
- "gitHead": "6fb04e62985a6ed0adc76f74d3c17350f37f9fe7"
64
+ "gitHead": "b1c7a439b0df37d3e381cd182ea3b9e74323107b"
65
65
  }