@midwayjs/web 3.0.0-beta.3 → 3.0.0-beta.7

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/CHANGELOG.md CHANGED
@@ -3,6 +3,54 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * class transformer method missing ([#1387](https://github.com/midwayjs/midway/issues/1387)) ([074e839](https://github.com/midwayjs/midway/commit/074e8393598dc95e2742f735df75a2191c5fe25d))
23
+
24
+
25
+
26
+
27
+
28
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
29
+
30
+ **Note:** Version bump only for package @midwayjs/web
31
+
32
+
33
+
34
+
35
+
36
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * logger close before bootstrap close ([#1370](https://github.com/midwayjs/midway/issues/1370)) ([6cc2720](https://github.com/midwayjs/midway/commit/6cc2720ed3445e8ffccc96d124b80ed7e2517f08))
42
+
43
+
44
+ ### Features
45
+
46
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
47
+ * auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
48
+ * support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
49
+
50
+
51
+
52
+
53
+
6
54
  # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
7
55
 
8
56
 
@@ -1,11 +1,9 @@
1
1
  import { IMidwayWebApplication } from './interface';
2
- import { MidwayWebFramework } from './framework/web';
3
2
  import { MidwayDecoratorService } from '@midwayjs/core';
4
3
  export declare class EggConfiguration {
5
4
  baseDir: any;
6
5
  appDir: any;
7
6
  app: IMidwayWebApplication;
8
- webFramework: MidwayWebFramework;
9
7
  decoratorService: MidwayDecoratorService;
10
8
  init(): void;
11
9
  onReady(container: any): Promise<void>;
@@ -11,18 +11,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EggConfiguration = void 0;
13
13
  const decorator_1 = require("@midwayjs/decorator");
14
- const web_1 = require("./framework/web");
15
14
  const core_1 = require("@midwayjs/core");
16
15
  let EggConfiguration = class EggConfiguration {
17
16
  init() {
18
17
  this.decoratorService.registerParameterHandler(decorator_1.WEB_ROUTER_PARAM_KEY, options => {
19
- return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData)(options.originArgs[0], options.originArgs[1]);
18
+ return (0, core_1.extractKoaLikeValue)(options.metadata.type, options.metadata.propertyData, options.originParamType)(options.originArgs[0], options.originArgs[1]);
20
19
  });
21
20
  }
22
21
  async onReady(container) { }
23
22
  async onServerReady() {
24
23
  // trigger server didReady
25
- await this.webFramework.run();
26
24
  this.app.messenger.emit('egg-ready');
27
25
  }
28
26
  async onStop() {
@@ -41,10 +39,6 @@ __decorate([
41
39
  (0, decorator_1.App)(),
42
40
  __metadata("design:type", Object)
43
41
  ], EggConfiguration.prototype, "app", void 0);
44
- __decorate([
45
- (0, decorator_1.Inject)(),
46
- __metadata("design:type", web_1.MidwayWebFramework)
47
- ], EggConfiguration.prototype, "webFramework", void 0);
48
42
  __decorate([
49
43
  (0, decorator_1.Inject)(),
50
44
  __metadata("design:type", core_1.MidwayDecoratorService)
@@ -1,12 +1,21 @@
1
- import { BaseFramework, IMidwayBootstrapOptions } from '@midwayjs/core';
1
+ import { BaseFramework, IMidwayBootstrapOptions, RouterInfo, WebControllerGenerator } from '@midwayjs/core';
2
2
  import { MidwayFrameworkType } from '@midwayjs/decorator';
3
3
  import { IMidwayWebConfigurationOptions } from '../interface';
4
+ import { EggRouter } from '@eggjs/router';
4
5
  import { Application, Context, EggLogger } from 'egg';
6
+ declare class EggControllerGenerator extends WebControllerGenerator<EggRouter> {
7
+ readonly app: any;
8
+ readonly applicationContext: any;
9
+ readonly logger: any;
10
+ constructor(app: any, applicationContext: any, logger: any);
11
+ createRouter(routerOptions: any): EggRouter;
12
+ generateController(routeInfo: RouterInfo): (ctx: any, next: any) => Promise<void>;
13
+ }
5
14
  export declare class MidwayWebFramework extends BaseFramework<Application, Context, IMidwayWebConfigurationOptions> {
6
15
  protected loggers: {
7
16
  [name: string]: EggLogger;
8
17
  };
9
- generator: any;
18
+ generator: EggControllerGenerator;
10
19
  private server;
11
20
  private agent;
12
21
  private isClusterMode;
@@ -23,4 +32,5 @@ export declare class MidwayWebFramework extends BaseFramework<Application, Conte
23
32
  generateMiddleware(middlewareId: string): Promise<any>;
24
33
  beforeStop(): Promise<void>;
25
34
  }
35
+ export {};
26
36
  //# sourceMappingURL=web.d.ts.map
@@ -30,8 +30,8 @@ class EggControllerGenerator extends core_1.WebControllerGenerator {
30
30
  router.prefix(routerOptions.prefix);
31
31
  return router;
32
32
  }
33
- generateController(controllerMapping, routeArgsInfo, routerResponseData) {
34
- return this.generateKoaController(controllerMapping, routeArgsInfo, routerResponseData);
33
+ generateController(routeInfo) {
34
+ return this.generateKoaController(routeInfo);
35
35
  }
36
36
  }
37
37
  let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
@@ -66,26 +66,6 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
66
66
  application.agent = agent;
67
67
  agent.application = application;
68
68
  debug('[egg]: init single process egg end');
69
- // https config
70
- if (this.configurationOptions.key && this.configurationOptions.cert) {
71
- this.configurationOptions.key = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.key);
72
- this.configurationOptions.cert = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.cert);
73
- this.configurationOptions.ca = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.ca);
74
- if (this.configurationOptions.http2) {
75
- this.server = require('http2').createSecureServer(this.configurationOptions, this.app.callback());
76
- }
77
- else {
78
- this.server = require('https').createServer(this.configurationOptions, this.app.callback());
79
- }
80
- }
81
- else {
82
- if (this.configurationOptions.http2) {
83
- this.server = require('http2').createServer(this.app.callback());
84
- }
85
- else {
86
- this.server = require('http').createServer(this.app.callback());
87
- }
88
- }
89
69
  }
90
70
  async applicationInitialize(options) {
91
71
  if (!this.isClusterMode) {
@@ -94,13 +74,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
94
74
  // insert error handler
95
75
  this.app.use(async (ctx, next) => {
96
76
  // this.app.createAnonymousContext(ctx);
97
- const { result, error } = await (await this.getMiddleware())(ctx, next);
98
- if (error) {
99
- throw error;
100
- }
101
- if (result) {
102
- ctx.body = result;
103
- }
77
+ await (await this.getMiddleware())(ctx, next);
104
78
  });
105
79
  this.generator = new EggControllerGenerator(this.app, this.applicationContext, this.appLogger);
106
80
  this.overwriteApplication('app');
@@ -135,9 +109,6 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
135
109
  });
136
110
  debug(`[egg]: overwrite properties to "${processType}"`);
137
111
  this.defineApplicationProperties({
138
- generateController: (controllerMapping) => {
139
- return this.generator.generateController(controllerMapping);
140
- },
141
112
  generateMiddleware: async (middlewareId) => {
142
113
  return this.generateMiddleware(middlewareId);
143
114
  },
@@ -156,7 +127,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
156
127
  logger_2.MidwayEggContextLogger);
157
128
  }
158
129
  async loadMidwayController() {
159
- await this.generator.loadMidwayController(newRouter => {
130
+ await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
160
131
  this.app.use(newRouter.middleware());
161
132
  });
162
133
  }
@@ -164,11 +135,32 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
164
135
  return decorator_1.MidwayFrameworkType.WEB;
165
136
  }
166
137
  async run() {
138
+ var _a;
167
139
  // load controller
168
140
  await this.loadMidwayController();
169
141
  // restore use method
170
142
  this.app.use = this.app.originUse;
171
143
  if (!this.isClusterMode) {
144
+ // https config
145
+ if (this.configurationOptions.key && this.configurationOptions.cert) {
146
+ this.configurationOptions.key = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.key);
147
+ this.configurationOptions.cert = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.cert);
148
+ this.configurationOptions.ca = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.ca);
149
+ if (this.configurationOptions.http2) {
150
+ this.server = require('http2').createSecureServer(this.configurationOptions, this.app.callback());
151
+ }
152
+ else {
153
+ this.server = require('https').createServer(this.configurationOptions, this.app.callback());
154
+ }
155
+ }
156
+ else {
157
+ if (this.configurationOptions.http2) {
158
+ this.server = require('http2').createServer(this.app.callback());
159
+ }
160
+ else {
161
+ this.server = require('http').createServer(this.app.callback());
162
+ }
163
+ }
172
164
  // emit egg-ready message in agent and application
173
165
  this.app.messenger.broadcast('egg-ready', undefined);
174
166
  // emit `server` event in app
@@ -176,9 +168,10 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
176
168
  // register httpServer to applicationContext
177
169
  this.getApplicationContext().registerObject(core_1.HTTP_SERVER_KEY, this.server);
178
170
  const eggConfig = this.configService.getConfiguration('egg');
179
- if (this.configService.getConfiguration('egg')) {
171
+ if (!this.isClusterMode && eggConfig) {
172
+ const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : eggConfig.port;
180
173
  new Promise(resolve => {
181
- const args = [eggConfig.port];
174
+ const args = [customPort];
182
175
  if (eggConfig.hostname) {
183
176
  args.push(eggConfig.hostname);
184
177
  }
@@ -186,6 +179,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
186
179
  resolve();
187
180
  });
188
181
  this.server.listen(...args);
182
+ process.env.MIDWAY_HTTP_PORT = String(customPort);
189
183
  });
190
184
  }
191
185
  }
@@ -1,28 +1,27 @@
1
1
  /// <reference types="node" />
2
- import { Context as EggContext, Application as EggApplication, EggLogger, EggAppConfig } from 'egg';
3
- import { IMidwayContainer, IMidwayContext, Context as IMidwayBaseContext, IMidwayApplication, IMidwayBaseApplication, IConfigurationOptions } from '@midwayjs/core';
4
- import { DefaultState, Middleware, Next } from 'koa';
2
+ import { Context as EggContext, Application as EggApplication, EggAppConfig } from 'egg';
3
+ import { IMidwayContainer, IMidwayContext, Context as IMidwayBaseContext, IMidwayApplication, IMidwayBaseApplication, IConfigurationOptions, NextFunction as BaseNextFunction } from '@midwayjs/core';
4
+ import { DefaultState, Middleware } from 'koa';
5
5
  import { ILogger, LoggerOptions } from '@midwayjs/logger';
6
6
  export interface IMidwayWebBaseApplication {
7
7
  applicationContext: IMidwayContainer;
8
- getLogger(name?: string): EggLogger & ILogger;
9
- getCoreLogger(): EggLogger & ILogger;
10
- generateController?(controllerMapping: string): any;
8
+ getLogger(name?: string): ILogger;
9
+ getCoreLogger(): ILogger;
11
10
  generateMiddleware?(middlewareId: string): Promise<Middleware<DefaultState, EggContext>>;
12
- createLogger(name: string, options: LoggerOptions): EggLogger & ILogger;
11
+ createLogger(name: string, options: LoggerOptions): ILogger;
13
12
  }
14
13
  declare module 'egg' {
15
14
  interface EggAppInfo {
16
15
  appDir: string;
17
16
  }
18
- interface Application extends IMidwayBaseApplication, IMidwayWebBaseApplication {
17
+ interface Application extends IMidwayBaseApplication<Context>, IMidwayWebBaseApplication {
19
18
  createAnonymousContext(...args: any[]): EggContext;
20
19
  getCoreLogger(): EggLogger & ILogger;
21
20
  getLogger(name?: string): EggLogger & ILogger;
22
21
  createLogger(name: string, options: LoggerOptions): EggLogger & ILogger;
23
22
  }
24
23
  interface Context<ResponseBodyT = any> extends IMidwayBaseContext {
25
- getLogger(name?: string): EggLogger & ILogger;
24
+ getLogger(name?: string): ILogger;
26
25
  }
27
26
  interface EggAppConfig {
28
27
  midwayFeature: {
@@ -36,7 +35,8 @@ export interface Application extends IMidwayWebApplication {
36
35
  export interface Context<ResponseBodyT = unknown> extends IMidwayWebContext<ResponseBodyT> {
37
36
  }
38
37
  export declare type IMidwayWebContext<ResponseBodyT = unknown> = IMidwayContext<EggContext<ResponseBodyT>>;
39
- export declare type IMidwayWebNext = Next;
38
+ export declare type IMidwayWebNext = BaseNextFunction;
39
+ export declare type NextFunction = BaseNextFunction;
40
40
  export interface IMidwayWebConfigurationOptions extends IConfigurationOptions {
41
41
  app?: IMidwayWebApplication;
42
42
  plugins?: {
@@ -73,8 +73,20 @@ export interface IMidwayWebConfigurationOptions extends IConfigurationOptions {
73
73
  * http2 support
74
74
  */
75
75
  http2?: boolean;
76
+ /**
77
+ * http global prefix
78
+ */
79
+ globalPrefix?: string;
76
80
  }
81
+ /**
82
+ * @deprecated since version 3.0.0
83
+ * Please use IMiddleware from @midwayjs/core
84
+ */
77
85
  export declare type MidwayWebMiddleware = Middleware<DefaultState, Context>;
86
+ /**
87
+ * @deprecated since version 3.0.0
88
+ * Please use IMiddleware from @midwayjs/core
89
+ */
78
90
  export interface IWebMiddleware {
79
91
  resolve(): MidwayWebMiddleware;
80
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/web",
3
- "version": "3.0.0-beta.3",
3
+ "version": "3.0.0-beta.7",
4
4
  "description": "Midway Web Framework for Egg.js",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index.d.ts",
@@ -27,8 +27,8 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@midwayjs/decorator": "^3.0.0-beta.3",
31
- "@midwayjs/mock": "^3.0.0-beta.3",
30
+ "@midwayjs/decorator": "^3.0.0-beta.7",
31
+ "@midwayjs/mock": "^3.0.0-beta.7",
32
32
  "dayjs": "^1.10.7",
33
33
  "egg-logger": "^2.4.2",
34
34
  "egg-mock": "^3.26.0",
@@ -43,8 +43,8 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@eggjs/router": "^2.0.0",
46
- "@midwayjs/core": "^3.0.0-beta.3",
47
- "@midwayjs/logger": "^3.0.0-beta.3",
46
+ "@midwayjs/core": "^3.0.0-beta.7",
47
+ "@midwayjs/logger": "^3.0.0-beta.7",
48
48
  "egg": "^2.28.0",
49
49
  "extend2": "^1.0.0",
50
50
  "find-up": "^5.0.0",
@@ -58,5 +58,5 @@
58
58
  "engines": {
59
59
  "node": ">=12"
60
60
  },
61
- "gitHead": "a46b7f83d1cb161ec312f2892a9b33ff2d290d7e"
61
+ "gitHead": "24590729121d9110e2d960db5b5e587cf55a1efc"
62
62
  }