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

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,24 @@
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.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * logger close before bootstrap close ([#1370](https://github.com/midwayjs/midway/issues/1370)) ([6cc2720](https://github.com/midwayjs/midway/commit/6cc2720ed3445e8ffccc96d124b80ed7e2517f08))
12
+
13
+
14
+ ### Features
15
+
16
+ * add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
17
+ * auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
18
+ * support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
19
+
20
+
21
+
22
+
23
+
6
24
  # [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
25
 
8
26
 
@@ -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
  }
@@ -169,6 +146,26 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
169
146
  // restore use method
170
147
  this.app.use = this.app.originUse;
171
148
  if (!this.isClusterMode) {
149
+ // https config
150
+ if (this.configurationOptions.key && this.configurationOptions.cert) {
151
+ this.configurationOptions.key = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.key);
152
+ this.configurationOptions.cert = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.cert);
153
+ this.configurationOptions.ca = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.ca);
154
+ if (this.configurationOptions.http2) {
155
+ this.server = require('http2').createSecureServer(this.configurationOptions, this.app.callback());
156
+ }
157
+ else {
158
+ this.server = require('https').createServer(this.configurationOptions, this.app.callback());
159
+ }
160
+ }
161
+ else {
162
+ if (this.configurationOptions.http2) {
163
+ this.server = require('http2').createServer(this.app.callback());
164
+ }
165
+ else {
166
+ this.server = require('http').createServer(this.app.callback());
167
+ }
168
+ }
172
169
  // emit egg-ready message in agent and application
173
170
  this.app.messenger.broadcast('egg-ready', undefined);
174
171
  // emit `server` event in app
@@ -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.4",
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.4",
31
+ "@midwayjs/mock": "^3.0.0-beta.4",
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.4",
47
+ "@midwayjs/logger": "^3.0.0-beta.4",
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": "02e2144e302f807770b512b0d89da3145b1cbf2e"
62
62
  }