@midwayjs/web 3.0.0-beta.1 → 3.0.0-beta.13
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 +129 -0
- package/README.md +1 -1
- package/app.js +3 -4
- package/config/plugin.js +4 -3
- package/dist/configuration.d.ts +1 -3
- package/dist/configuration.js +6 -8
- package/dist/framework/web.d.ts +11 -3
- package/dist/framework/web.js +65 -50
- package/dist/interface.d.ts +28 -11
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,135 @@
|
|
|
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.13](https://github.com/midwayjs/midway/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-12-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* 404 error ([#1465](https://github.com/midwayjs/midway/issues/1465)) ([e7e8a9d](https://github.com/midwayjs/midway/commit/e7e8a9dedfa7198ac05b161b41024c2871f93965))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* custom error code & add @Files/@Fields ([#1438](https://github.com/midwayjs/midway/issues/1438)) ([b0032af](https://github.com/midwayjs/midway/commit/b0032afd2fa9ea0416fe69f4bd0c1a58bea5314e))
|
|
23
|
+
* support throw err status ([#1440](https://github.com/midwayjs/midway/issues/1440)) ([7b98110](https://github.com/midwayjs/midway/commit/7b98110d65c5287a8fcb3eb5356dea2d7a32cee9))
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
|
|
30
|
+
|
|
31
|
+
**Note:** Version bump only for package @midwayjs/web
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
# [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Features
|
|
41
|
+
|
|
42
|
+
* default add session & bodyparser support for koa/express/faas ([#1420](https://github.com/midwayjs/midway/issues/1420)) ([cdaff31](https://github.com/midwayjs/midway/commit/cdaff317c3e862a95494a167995a28280af639bf))
|
|
43
|
+
* implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
|
|
50
|
+
|
|
51
|
+
**Note:** Version bump only for package @midwayjs/web
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Bug Fixes
|
|
61
|
+
|
|
62
|
+
* express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([b9272e0](https://github.com/midwayjs/midway/commit/b9272e0971003443304b0c53815be31a0061b4bd))
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
# [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### Bug Fixes
|
|
72
|
+
|
|
73
|
+
* middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### Bug Fixes
|
|
83
|
+
|
|
84
|
+
* class transformer method missing ([#1387](https://github.com/midwayjs/midway/issues/1387)) ([074e839](https://github.com/midwayjs/midway/commit/074e8393598dc95e2742f735df75a2191c5fe25d))
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
# [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
|
|
91
|
+
|
|
92
|
+
**Note:** Version bump only for package @midwayjs/web
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
### Bug Fixes
|
|
102
|
+
|
|
103
|
+
* logger close before bootstrap close ([#1370](https://github.com/midwayjs/midway/issues/1370)) ([6cc2720](https://github.com/midwayjs/midway/commit/6cc2720ed3445e8ffccc96d124b80ed7e2517f08))
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
### Features
|
|
107
|
+
|
|
108
|
+
* add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
|
|
109
|
+
* auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
|
|
110
|
+
* support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
# [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
### Features
|
|
120
|
+
|
|
121
|
+
* add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
# [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
|
|
128
|
+
|
|
129
|
+
**Note:** Version bump only for package @midwayjs/web
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
6
135
|
# [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
|
|
7
136
|
|
|
8
137
|
|
package/README.md
CHANGED
package/app.js
CHANGED
|
@@ -24,10 +24,9 @@ class AppBootHook {
|
|
|
24
24
|
async didLoad() {
|
|
25
25
|
debug('[egg lifecycle]: app didLoad');
|
|
26
26
|
if (this.app.loader['useEggSocketIO']) {
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
27
|
+
// egg socket.io 需要这个中间件
|
|
28
|
+
// const session = this.app.getMiddleware().findItem('session');
|
|
29
|
+
// this.app.middleware.push(session);
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
|
package/config/plugin.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
|
+
onerror: true,
|
|
5
|
+
security: true,
|
|
4
6
|
static: false,
|
|
5
7
|
development: false,
|
|
6
8
|
watcher: false,
|
|
7
|
-
|
|
8
|
-
multipart: true,
|
|
9
|
-
security: true,
|
|
9
|
+
multipart: false,
|
|
10
10
|
logrotator: false,
|
|
11
11
|
view: false,
|
|
12
12
|
schedule: false,
|
|
13
|
+
i18n: false,
|
|
13
14
|
};
|
package/dist/configuration.d.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
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
|
-
onReady(
|
|
9
|
+
onReady(): Promise<void>;
|
|
12
10
|
onServerReady(): Promise<void>;
|
|
13
11
|
onStop(): Promise<void>;
|
|
14
12
|
}
|
package/dist/configuration.js
CHANGED
|
@@ -11,18 +11,20 @@ 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
|
-
async onReady(
|
|
21
|
+
async onReady() {
|
|
22
|
+
// ps: 本想在这里清理掉egg添加的中间件,但是这里的数组已经只有一个 midway root middleware,其他的 getter 都是 egg 加进去的,但是不会被中间件执行,所以不需要清理
|
|
23
|
+
// 去掉为了 egg-socket.io 报错扫进去的 session
|
|
24
|
+
this.app.middleware = this.app.middleware.slice(0);
|
|
25
|
+
}
|
|
23
26
|
async onServerReady() {
|
|
24
27
|
// trigger server didReady
|
|
25
|
-
await this.webFramework.run();
|
|
26
28
|
this.app.messenger.emit('egg-ready');
|
|
27
29
|
}
|
|
28
30
|
async onStop() {
|
|
@@ -41,10 +43,6 @@ __decorate([
|
|
|
41
43
|
(0, decorator_1.App)(),
|
|
42
44
|
__metadata("design:type", Object)
|
|
43
45
|
], 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
46
|
__decorate([
|
|
49
47
|
(0, decorator_1.Inject)(),
|
|
50
48
|
__metadata("design:type", core_1.MidwayDecoratorService)
|
package/dist/framework/web.d.ts
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
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
|
+
constructor(app: any);
|
|
9
|
+
createRouter(routerOptions: any): EggRouter;
|
|
10
|
+
generateController(routeInfo: RouterInfo): (ctx: any, next: any) => Promise<void>;
|
|
11
|
+
}
|
|
5
12
|
export declare class MidwayWebFramework extends BaseFramework<Application, Context, IMidwayWebConfigurationOptions> {
|
|
6
13
|
protected loggers: {
|
|
7
14
|
[name: string]: EggLogger;
|
|
8
15
|
};
|
|
9
|
-
generator:
|
|
16
|
+
generator: EggControllerGenerator;
|
|
10
17
|
private server;
|
|
11
18
|
private agent;
|
|
12
19
|
private isClusterMode;
|
|
@@ -20,7 +27,8 @@ export declare class MidwayWebFramework extends BaseFramework<Application, Conte
|
|
|
20
27
|
run(): Promise<void>;
|
|
21
28
|
getLogger(name?: string): any;
|
|
22
29
|
setContextLoggerClass(BaseContextLogger: any): void;
|
|
23
|
-
generateMiddleware(middlewareId:
|
|
30
|
+
generateMiddleware(middlewareId: any): Promise<any>;
|
|
24
31
|
beforeStop(): Promise<void>;
|
|
25
32
|
}
|
|
33
|
+
export {};
|
|
26
34
|
//# sourceMappingURL=web.d.ts.map
|
package/dist/framework/web.js
CHANGED
|
@@ -19,19 +19,17 @@ const util_1 = require("util");
|
|
|
19
19
|
const logger_2 = require("../logger");
|
|
20
20
|
const debug = (0, util_1.debuglog)('midway:debug');
|
|
21
21
|
class EggControllerGenerator extends core_1.WebControllerGenerator {
|
|
22
|
-
constructor(app
|
|
23
|
-
super(
|
|
22
|
+
constructor(app) {
|
|
23
|
+
super(app);
|
|
24
24
|
this.app = app;
|
|
25
|
-
this.applicationContext = applicationContext;
|
|
26
|
-
this.logger = logger;
|
|
27
25
|
}
|
|
28
26
|
createRouter(routerOptions) {
|
|
29
27
|
const router = new router_1.EggRouter(routerOptions, this.app);
|
|
30
28
|
router.prefix(routerOptions.prefix);
|
|
31
29
|
return router;
|
|
32
30
|
}
|
|
33
|
-
generateController(
|
|
34
|
-
return this.generateKoaController(
|
|
31
|
+
generateController(routeInfo) {
|
|
32
|
+
return this.generateKoaController(routeInfo);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
35
|
let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
@@ -66,43 +64,25 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
66
64
|
application.agent = agent;
|
|
67
65
|
agent.application = application;
|
|
68
66
|
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
67
|
}
|
|
90
68
|
async applicationInitialize(options) {
|
|
91
69
|
if (!this.isClusterMode) {
|
|
92
70
|
await this.initSingleProcessEgg();
|
|
93
71
|
}
|
|
72
|
+
// not found middleware
|
|
73
|
+
const notFound = async (ctx, next) => {
|
|
74
|
+
await next();
|
|
75
|
+
if (!ctx._matchedRoute) {
|
|
76
|
+
throw new core_1.httpError.NotFoundError();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
94
79
|
// insert error handler
|
|
95
|
-
|
|
80
|
+
const midwayRootMiddleware = async (ctx, next) => {
|
|
96
81
|
// this.app.createAnonymousContext(ctx);
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (result) {
|
|
102
|
-
ctx.body = result;
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
this.generator = new EggControllerGenerator(this.app, this.applicationContext, this.appLogger);
|
|
82
|
+
await (await this.applyMiddleware(notFound))(ctx, next);
|
|
83
|
+
};
|
|
84
|
+
this.app.use(midwayRootMiddleware);
|
|
85
|
+
this.generator = new EggControllerGenerator(this.app);
|
|
106
86
|
this.overwriteApplication('app');
|
|
107
87
|
await new Promise(resolve => {
|
|
108
88
|
this.app.once('application-ready', () => {
|
|
@@ -110,7 +90,7 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
110
90
|
resolve();
|
|
111
91
|
});
|
|
112
92
|
this.app.loader.loadOrigin();
|
|
113
|
-
//
|
|
93
|
+
// 这里拦截 app.use 方法,让他可以加到 midway 的 middlewareManager 中
|
|
114
94
|
this.app.originUse = this.app.use;
|
|
115
95
|
this.app.use = this.app.useMiddleware;
|
|
116
96
|
this.app.ready();
|
|
@@ -136,7 +116,11 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
136
116
|
debug(`[egg]: overwrite properties to "${processType}"`);
|
|
137
117
|
this.defineApplicationProperties({
|
|
138
118
|
generateController: (controllerMapping) => {
|
|
139
|
-
|
|
119
|
+
const [controllerId, methodName] = controllerMapping.split('.');
|
|
120
|
+
return this.generator.generateController({
|
|
121
|
+
id: controllerId,
|
|
122
|
+
method: methodName,
|
|
123
|
+
});
|
|
140
124
|
},
|
|
141
125
|
generateMiddleware: async (middlewareId) => {
|
|
142
126
|
return this.generateMiddleware(middlewareId);
|
|
@@ -156,19 +140,46 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
156
140
|
logger_2.MidwayEggContextLogger);
|
|
157
141
|
}
|
|
158
142
|
async loadMidwayController() {
|
|
159
|
-
await this.generator.loadMidwayController(newRouter => {
|
|
160
|
-
|
|
143
|
+
await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
|
|
144
|
+
var _a;
|
|
145
|
+
const dispatchFn = newRouter.middleware();
|
|
146
|
+
dispatchFn._name = `midwayController(${((_a = newRouter === null || newRouter === void 0 ? void 0 : newRouter.opts) === null || _a === void 0 ? void 0 : _a.prefix) || '/'})`;
|
|
147
|
+
this.app.useMiddleware(dispatchFn);
|
|
161
148
|
});
|
|
162
149
|
}
|
|
163
150
|
getFrameworkType() {
|
|
164
151
|
return decorator_1.MidwayFrameworkType.WEB;
|
|
165
152
|
}
|
|
166
153
|
async run() {
|
|
154
|
+
var _a;
|
|
155
|
+
// move egg router to last
|
|
156
|
+
this.app.getMiddleware().findAndInsertLast('eggRouterMiddleware');
|
|
167
157
|
// load controller
|
|
168
158
|
await this.loadMidwayController();
|
|
169
159
|
// restore use method
|
|
170
160
|
this.app.use = this.app.originUse;
|
|
161
|
+
debug(`[egg]: current middleware = ${this.middlewareManager.getNames()}`);
|
|
171
162
|
if (!this.isClusterMode) {
|
|
163
|
+
// https config
|
|
164
|
+
if (this.configurationOptions.key && this.configurationOptions.cert) {
|
|
165
|
+
this.configurationOptions.key = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.key);
|
|
166
|
+
this.configurationOptions.cert = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.cert);
|
|
167
|
+
this.configurationOptions.ca = core_1.PathFileUtil.getFileContentSync(this.configurationOptions.ca);
|
|
168
|
+
if (this.configurationOptions.http2) {
|
|
169
|
+
this.server = require('http2').createSecureServer(this.configurationOptions, this.app.callback());
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
this.server = require('https').createServer(this.configurationOptions, this.app.callback());
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (this.configurationOptions.http2) {
|
|
177
|
+
this.server = require('http2').createServer(this.app.callback());
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
this.server = require('http').createServer(this.app.callback());
|
|
181
|
+
}
|
|
182
|
+
}
|
|
172
183
|
// emit egg-ready message in agent and application
|
|
173
184
|
this.app.messenger.broadcast('egg-ready', undefined);
|
|
174
185
|
// emit `server` event in app
|
|
@@ -176,17 +187,21 @@ let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
|
176
187
|
// register httpServer to applicationContext
|
|
177
188
|
this.getApplicationContext().registerObject(core_1.HTTP_SERVER_KEY, this.server);
|
|
178
189
|
const eggConfig = this.configService.getConfiguration('egg');
|
|
179
|
-
if (this.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
args
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
190
|
+
if (!this.isClusterMode && eggConfig) {
|
|
191
|
+
const customPort = (_a = process.env.MIDWAY_HTTP_PORT) !== null && _a !== void 0 ? _a : eggConfig.port;
|
|
192
|
+
if (customPort) {
|
|
193
|
+
new Promise(resolve => {
|
|
194
|
+
const args = [customPort];
|
|
195
|
+
if (eggConfig.hostname) {
|
|
196
|
+
args.push(eggConfig.hostname);
|
|
197
|
+
}
|
|
198
|
+
args.push(() => {
|
|
199
|
+
resolve();
|
|
200
|
+
});
|
|
201
|
+
this.server.listen(...args);
|
|
202
|
+
process.env.MIDWAY_HTTP_PORT = String(customPort);
|
|
187
203
|
});
|
|
188
|
-
|
|
189
|
-
});
|
|
204
|
+
}
|
|
190
205
|
}
|
|
191
206
|
}
|
|
192
207
|
}
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Context as EggContext, Application as EggApplication,
|
|
3
|
-
import { IMidwayContainer, IMidwayContext, Context as IMidwayBaseContext, IMidwayApplication, IMidwayBaseApplication, IConfigurationOptions } from '@midwayjs/core';
|
|
4
|
-
import { DefaultState, Middleware
|
|
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):
|
|
9
|
-
getCoreLogger():
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
createLogger(name: string, options: LoggerOptions): EggLogger & ILogger;
|
|
8
|
+
getLogger(name?: string): ILogger;
|
|
9
|
+
getCoreLogger(): ILogger;
|
|
10
|
+
generateMiddleware?(middlewareId: any): Promise<Middleware<DefaultState, EggContext>>;
|
|
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
|
|
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):
|
|
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 =
|
|
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.
|
|
3
|
+
"version": "3.0.0-beta.13",
|
|
4
4
|
"description": "Midway Web Framework for Egg.js",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@midwayjs/decorator": "^3.0.0-beta.
|
|
31
|
-
"@midwayjs/
|
|
30
|
+
"@midwayjs/decorator": "^3.0.0-beta.13",
|
|
31
|
+
"@midwayjs/logger": "^3.0.0-beta.13",
|
|
32
|
+
"@midwayjs/mock": "^3.0.0-beta.13",
|
|
32
33
|
"dayjs": "^1.10.7",
|
|
33
34
|
"egg-logger": "^2.4.2",
|
|
34
35
|
"egg-mock": "^3.26.0",
|
|
@@ -43,8 +44,7 @@
|
|
|
43
44
|
},
|
|
44
45
|
"dependencies": {
|
|
45
46
|
"@eggjs/router": "^2.0.0",
|
|
46
|
-
"@midwayjs/core": "^3.0.0-beta.
|
|
47
|
-
"@midwayjs/logger": "^3.0.0-beta.1",
|
|
47
|
+
"@midwayjs/core": "^3.0.0-beta.13",
|
|
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": "
|
|
61
|
+
"gitHead": "d3c47770fee9dce33a8d148882173fd7782864ad"
|
|
62
62
|
}
|