@midwayjs/web 3.0.0-beta.2 → 3.0.0-beta.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.
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.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * class transformer method missing ([#1387](https://github.com/midwayjs/midway/issues/1387)) ([074e839](https://github.com/midwayjs/midway/commit/074e8393598dc95e2742f735df75a2191c5fe25d))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
18
+
19
+ **Note:** Version bump only for package @midwayjs/web
20
+
21
+
22
+
23
+
24
+
25
+ # [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * logger close before bootstrap close ([#1370](https://github.com/midwayjs/midway/issues/1370)) ([6cc2720](https://github.com/midwayjs/midway/commit/6cc2720ed3445e8ffccc96d124b80ed7e2517f08))
31
+
32
+
33
+ ### Features
34
+
35
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
36
+ * auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
37
+ * support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
38
+
39
+
40
+
41
+
42
+
43
+ # [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
44
+
45
+
46
+ ### Features
47
+
48
+ * add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
49
+
50
+
51
+
52
+
53
+
6
54
  # [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
7
55
 
8
56
  **Note:** Version bump only for package @midwayjs/web
@@ -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) {
@@ -135,9 +115,6 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
135
115
  });
136
116
  debug(`[egg]: overwrite properties to "${processType}"`);
137
117
  this.defineApplicationProperties({
138
- generateController: (controllerMapping) => {
139
- return this.generator.generateController(controllerMapping);
140
- },
141
118
  generateMiddleware: async (middlewareId) => {
142
119
  return this.generateMiddleware(middlewareId);
143
120
  },
@@ -156,7 +133,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
156
133
  logger_2.MidwayEggContextLogger);
157
134
  }
158
135
  async loadMidwayController() {
159
- await this.generator.loadMidwayController(newRouter => {
136
+ await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
160
137
  this.app.use(newRouter.middleware());
161
138
  });
162
139
  }
@@ -164,11 +141,32 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
164
141
  return decorator_1.MidwayFrameworkType.WEB;
165
142
  }
166
143
  async run() {
144
+ var _a;
167
145
  // load controller
168
146
  await this.loadMidwayController();
169
147
  // restore use method
170
148
  this.app.use = this.app.originUse;
171
149
  if (!this.isClusterMode) {
150
+ // https config
151
+ if (this.configurationOptions.key && this.configurationOptions.cert) {
152
+ this.configurationOptions.key = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.key);
153
+ this.configurationOptions.cert = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.cert);
154
+ this.configurationOptions.ca = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.ca);
155
+ if (this.configurationOptions.http2) {
156
+ this.server = require('http2').createSecureServer(this.configurationOptions, this.app.callback());
157
+ }
158
+ else {
159
+ this.server = require('https').createServer(this.configurationOptions, this.app.callback());
160
+ }
161
+ }
162
+ else {
163
+ if (this.configurationOptions.http2) {
164
+ this.server = require('http2').createServer(this.app.callback());
165
+ }
166
+ else {
167
+ this.server = require('http').createServer(this.app.callback());
168
+ }
169
+ }
172
170
  // emit egg-ready message in agent and application
173
171
  this.app.messenger.broadcast('egg-ready', undefined);
174
172
  // emit `server` event in app
@@ -176,9 +174,10 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
176
174
  // register httpServer to applicationContext
177
175
  this.getApplicationContext().registerObject(core_1.HTTP_SERVER_KEY, this.server);
178
176
  const eggConfig = this.configService.getConfiguration('egg');
179
- if (this.configService.getConfiguration('egg')) {
177
+ if (!this.isClusterMode && eggConfig) {
178
+ const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : eggConfig.port;
180
179
  new Promise(resolve => {
181
- const args = [eggConfig.port];
180
+ const args = [customPort];
182
181
  if (eggConfig.hostname) {
183
182
  args.push(eggConfig.hostname);
184
183
  }
@@ -186,6 +185,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
186
185
  resolve();
187
186
  });
188
187
  this.server.listen(...args);
188
+ process.env.MIDWAY_HTTP_PORT = String(customPort);
189
189
  });
190
190
  }
191
191
  }
@@ -1,28 +1,27 @@
1
1
  /// <reference types="node" />
2
- import { Context as EggContext, Application as EggApplication, EggLogger } 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,9 +73,26 @@ 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
  }
93
+ declare module '@midwayjs/core/dist/interface' {
94
+ interface MidwayConfig extends EggAppConfig {
95
+ egg?: IMidwayWebConfigurationOptions;
96
+ }
97
+ }
81
98
  //# sourceMappingURL=interface.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midwayjs/web",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.6",
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.2",
31
- "@midwayjs/mock": "^3.0.0-beta.2",
30
+ "@midwayjs/decorator": "^3.0.0-beta.6",
31
+ "@midwayjs/mock": "^3.0.0-beta.6",
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.2",
47
- "@midwayjs/logger": "^3.0.0-beta.2",
46
+ "@midwayjs/core": "^3.0.0-beta.6",
47
+ "@midwayjs/logger": "^3.0.0-beta.6",
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": "7f07de960da1155a9f7df554e1789c7a97bdd3fe"
61
+ "gitHead": "e4595d30b369e36bef21b36f2b3737d8bc2f802d"
62
62
  }