@midwayjs/web 3.0.0-alpha.9 → 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 +54 -0
- package/agent.js +13 -6
- package/app/extend/agent.js +0 -4
- package/app/extend/application.js +0 -4
- package/app.js +13 -12
- package/config/config.default.js +13 -8
- package/config/plugin.js +6 -4
- package/dist/application.js +6 -6
- package/dist/base.js +94 -62
- package/dist/configuration.d.ts +13 -0
- package/dist/configuration.js +98 -0
- package/dist/framework/web.d.ts +27 -26
- package/dist/framework/web.js +182 -120
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/interface.d.ts +53 -12
- package/dist/logger.d.ts +35 -2
- package/dist/logger.js +84 -102
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +132 -9
- package/package.json +13 -14
- package/dist/framework/singleProcess.d.ts +0 -34
- package/dist/framework/singleProcess.js +0 -122
- package/dist/starter.d.ts +0 -12
- package/dist/starter.js +0 -23
package/dist/framework/web.d.ts
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import { IMidwayBootstrapOptions,
|
|
1
|
+
import { BaseFramework, IMidwayBootstrapOptions, RouterInfo, WebControllerGenerator } from '@midwayjs/core';
|
|
2
|
+
import { MidwayFrameworkType } from '@midwayjs/decorator';
|
|
2
3
|
import { IMidwayWebConfigurationOptions } from '../interface';
|
|
3
|
-
import {
|
|
4
|
-
import { Application, Context,
|
|
5
|
-
|
|
6
|
-
app:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
import { EggRouter } from '@eggjs/router';
|
|
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
|
+
}
|
|
14
|
+
export declare class MidwayWebFramework extends BaseFramework<Application, Context, IMidwayWebConfigurationOptions> {
|
|
12
15
|
protected loggers: {
|
|
13
16
|
[name: string]: EggLogger;
|
|
14
17
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
generator: EggControllerGenerator;
|
|
19
|
+
private server;
|
|
20
|
+
private agent;
|
|
21
|
+
private isClusterMode;
|
|
22
|
+
appDir: any;
|
|
23
|
+
configure(): any;
|
|
24
|
+
initSingleProcessEgg(): Promise<void>;
|
|
19
25
|
applicationInitialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
overwriteApplication(processType: any): void;
|
|
27
|
+
loadMidwayController(): Promise<void>;
|
|
22
28
|
getFrameworkType(): MidwayFrameworkType;
|
|
23
|
-
getLogger(name?: string): any;
|
|
24
|
-
/**
|
|
25
|
-
* 这个方法 egg-cluster 不走,只有单进程模式使用 @midwayjs/bootstrap 才会执行
|
|
26
|
-
*/
|
|
27
29
|
run(): Promise<void>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
protected createRouter(routerOptions: any): Router;
|
|
33
|
-
protected setContextLoggerClass(BaseContextLogger: any): void;
|
|
30
|
+
getLogger(name?: string): any;
|
|
31
|
+
setContextLoggerClass(BaseContextLogger: any): void;
|
|
32
|
+
generateMiddleware(middlewareId: string): Promise<any>;
|
|
33
|
+
beforeStop(): Promise<void>;
|
|
34
34
|
}
|
|
35
|
+
export {};
|
|
35
36
|
//# sourceMappingURL=web.d.ts.map
|
package/dist/framework/web.js
CHANGED
|
@@ -1,132 +1,191 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.MidwayWebFramework = void 0;
|
|
4
13
|
const core_1 = require("@midwayjs/core");
|
|
5
14
|
const decorator_1 = require("@midwayjs/decorator");
|
|
6
|
-
const koa_1 = require("@midwayjs/koa");
|
|
7
15
|
const router_1 = require("@eggjs/router");
|
|
8
16
|
const logger_1 = require("@midwayjs/logger");
|
|
9
|
-
|
|
17
|
+
const path_1 = require("path");
|
|
18
|
+
const util_1 = require("util");
|
|
19
|
+
const logger_2 = require("../logger");
|
|
20
|
+
const debug = (0, util_1.debuglog)('midway:debug');
|
|
21
|
+
class EggControllerGenerator extends core_1.WebControllerGenerator {
|
|
22
|
+
constructor(app, applicationContext, logger) {
|
|
23
|
+
super(applicationContext, decorator_1.MidwayFrameworkType.WEB, logger);
|
|
24
|
+
this.app = app;
|
|
25
|
+
this.applicationContext = applicationContext;
|
|
26
|
+
this.logger = logger;
|
|
27
|
+
}
|
|
28
|
+
createRouter(routerOptions) {
|
|
29
|
+
const router = new router_1.EggRouter(routerOptions, this.app);
|
|
30
|
+
router.prefix(routerOptions.prefix);
|
|
31
|
+
return router;
|
|
32
|
+
}
|
|
33
|
+
generateController(routeInfo) {
|
|
34
|
+
return this.generateKoaController(routeInfo);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
let MidwayWebFramework = class MidwayWebFramework extends core_1.BaseFramework {
|
|
10
38
|
constructor() {
|
|
11
39
|
super(...arguments);
|
|
12
|
-
this.
|
|
40
|
+
this.isClusterMode = false;
|
|
13
41
|
}
|
|
14
|
-
configure(
|
|
42
|
+
configure() {
|
|
43
|
+
process.env.EGG_TYPESCRIPT = 'true';
|
|
44
|
+
if (process.env['EGG_CLUSTER_MODE'] === 'true') {
|
|
45
|
+
this.isClusterMode = true;
|
|
46
|
+
}
|
|
47
|
+
return this.configService.getConfiguration('egg');
|
|
48
|
+
}
|
|
49
|
+
async initSingleProcessEgg() {
|
|
50
|
+
const opts = {
|
|
51
|
+
baseDir: this.appDir,
|
|
52
|
+
framework: (0, path_1.resolve)(__dirname, '../application'),
|
|
53
|
+
plugins: this.configurationOptions.plugins,
|
|
54
|
+
mode: 'single',
|
|
55
|
+
isTsMode: true,
|
|
56
|
+
applicationContext: this.applicationContext,
|
|
57
|
+
midwaySingleton: true,
|
|
58
|
+
};
|
|
59
|
+
debug('[egg]: init single process egg agent');
|
|
60
|
+
const Agent = require(opts.framework).Agent;
|
|
61
|
+
const Application = require(opts.framework).Application;
|
|
62
|
+
const agent = (this.agent = new Agent(Object.assign({}, opts)));
|
|
63
|
+
await agent.ready();
|
|
64
|
+
debug('[egg]: init single process egg application');
|
|
65
|
+
const application = (this.app = new Application(Object.assign({}, opts)));
|
|
66
|
+
application.agent = agent;
|
|
67
|
+
agent.application = application;
|
|
68
|
+
debug('[egg]: init single process egg end');
|
|
69
|
+
}
|
|
70
|
+
async applicationInitialize(options) {
|
|
71
|
+
if (!this.isClusterMode) {
|
|
72
|
+
await this.initSingleProcessEgg();
|
|
73
|
+
}
|
|
74
|
+
// insert error handler
|
|
75
|
+
this.app.use(async (ctx, next) => {
|
|
76
|
+
// this.app.createAnonymousContext(ctx);
|
|
77
|
+
const { result, error } = await (await this.getMiddleware())(ctx, next);
|
|
78
|
+
if (error) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
if (result) {
|
|
82
|
+
ctx.body = result;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
this.generator = new EggControllerGenerator(this.app, this.applicationContext, this.appLogger);
|
|
86
|
+
this.overwriteApplication('app');
|
|
87
|
+
await new Promise(resolve => {
|
|
88
|
+
this.app.once('application-ready', () => {
|
|
89
|
+
debug('[egg]: web framework: init egg end');
|
|
90
|
+
resolve();
|
|
91
|
+
});
|
|
92
|
+
this.app.loader.loadOrigin();
|
|
93
|
+
// hack use method
|
|
94
|
+
this.app.originUse = this.app.use;
|
|
95
|
+
this.app.use = this.app.useMiddleware;
|
|
96
|
+
this.app.ready();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
overwriteApplication(processType) {
|
|
15
100
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
16
101
|
const self = this;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
102
|
+
// 单进程下,先把egg的配置覆盖进来,有可能业务测没写 importConfigs
|
|
103
|
+
debug(`[egg]: overwrite egg config to configService in "${processType}"`);
|
|
104
|
+
this.configService.addObject(this.app.config);
|
|
105
|
+
Object.defineProperty(this.app, 'config', {
|
|
106
|
+
get() {
|
|
107
|
+
return self.getConfiguration();
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
debug(`[egg]: overwrite applicationContext config to "${processType}"`);
|
|
111
|
+
Object.defineProperty(this.app, 'applicationContext', {
|
|
112
|
+
get() {
|
|
113
|
+
return self.applicationContext;
|
|
25
114
|
},
|
|
115
|
+
});
|
|
116
|
+
debug(`[egg]: overwrite properties to "${processType}"`);
|
|
117
|
+
this.defineApplicationProperties({
|
|
26
118
|
generateMiddleware: async (middlewareId) => {
|
|
27
119
|
return this.generateMiddleware(middlewareId);
|
|
28
120
|
},
|
|
29
121
|
getProcessType: () => {
|
|
30
|
-
if (
|
|
122
|
+
if (processType === 'app') {
|
|
31
123
|
return core_1.MidwayProcessTypeEnum.APPLICATION;
|
|
32
124
|
}
|
|
33
|
-
if (
|
|
125
|
+
if (processType === 'agent') {
|
|
34
126
|
return core_1.MidwayProcessTypeEnum.AGENT;
|
|
35
127
|
}
|
|
36
|
-
// TODO 单进程模式下区分进程类型??
|
|
37
|
-
return core_1.MidwayProcessTypeEnum.APPLICATION;
|
|
38
128
|
},
|
|
39
129
|
}, ['createAnonymousContext']);
|
|
40
|
-
if
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
Object.defineProperty(this.app, 'applicationContext', {
|
|
47
|
-
get() {
|
|
48
|
-
return self.getApplicationContext();
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
async initialize(options) {
|
|
54
|
-
this.isMainFramework = options.isMainFramework;
|
|
55
|
-
/**
|
|
56
|
-
* before create MidwayContainer instance,can change init parameters
|
|
57
|
-
*/
|
|
58
|
-
await this.beforeContainerInitialize(options);
|
|
59
|
-
/**
|
|
60
|
-
* initialize MidwayContainer instance
|
|
61
|
-
*/
|
|
62
|
-
await this.containerInitialize(options);
|
|
63
|
-
/**
|
|
64
|
-
* before container load directory and bind
|
|
65
|
-
*/
|
|
66
|
-
await this.afterContainerInitialize(options);
|
|
67
|
-
/**
|
|
68
|
-
* run container loadDirectoryLoad method to create object definition
|
|
69
|
-
*/
|
|
70
|
-
await this.containerDirectoryLoad(options);
|
|
71
|
-
/**
|
|
72
|
-
* after container load directory and bind
|
|
73
|
-
*/
|
|
74
|
-
await this.afterContainerDirectoryLoad(options);
|
|
75
|
-
/**
|
|
76
|
-
* Third party application initialization
|
|
77
|
-
*/
|
|
78
|
-
await this.applicationInitialize(options);
|
|
79
|
-
/**
|
|
80
|
-
* EggJS 比较特殊,生命周期触发需要等到插件加载完才能加载
|
|
81
|
-
*/
|
|
82
|
-
await this.applicationContext.ready();
|
|
83
|
-
/**
|
|
84
|
-
* after container refresh
|
|
85
|
-
*/
|
|
86
|
-
await this.afterContainerReady(options);
|
|
87
|
-
}
|
|
88
|
-
async beforeContainerInitialize(options) {
|
|
89
|
-
options.ignore = options.ignore || [];
|
|
90
|
-
options.ignore.push('**/app/extend/**');
|
|
91
|
-
}
|
|
92
|
-
async initializeLogger() {
|
|
93
|
-
// 不需要在这里创建框架日志,从 egg 代理过来
|
|
94
|
-
this.logger = this.app.coreLogger;
|
|
95
|
-
this.appLogger = this.app.logger;
|
|
130
|
+
// if use midway logger will be use midway custom context logger
|
|
131
|
+
debug(`[egg]: overwrite BaseContextLoggerClass to "${processType}"`);
|
|
132
|
+
this.setContextLoggerClass(this.configService.getConfiguration('egg.ContextLoggerClass') ||
|
|
133
|
+
logger_2.MidwayEggContextLogger);
|
|
96
134
|
}
|
|
97
|
-
async
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
process.env.EGG_TYPESCRIPT = 'true';
|
|
101
|
-
if (this.configurationOptions.globalConfig) {
|
|
102
|
-
this.getApplicationContext()
|
|
103
|
-
.getConfigService()
|
|
104
|
-
.addObject(this.configurationOptions.globalConfig);
|
|
105
|
-
Object.defineProperty(this.app, 'config', {
|
|
106
|
-
get() {
|
|
107
|
-
return self.getConfiguration();
|
|
108
|
-
},
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
// register plugin
|
|
112
|
-
this.getApplicationContext().registerDataHandler(decorator_1.PLUGIN_KEY, (key, target) => {
|
|
113
|
-
return this.app[key];
|
|
114
|
-
});
|
|
115
|
-
// register config
|
|
116
|
-
this.getApplicationContext().registerDataHandler(decorator_1.CONFIG_KEY, key => {
|
|
117
|
-
return key ? core_1.safelyGet(key, this.app.config) : this.app.config;
|
|
118
|
-
});
|
|
119
|
-
// register logger
|
|
120
|
-
this.getApplicationContext().registerDataHandler(decorator_1.LOGGER_KEY, key => {
|
|
121
|
-
return this.getLogger(key);
|
|
135
|
+
async loadMidwayController() {
|
|
136
|
+
await this.generator.loadMidwayController(this.configurationOptions.globalPrefix, newRouter => {
|
|
137
|
+
this.app.use(newRouter.middleware());
|
|
122
138
|
});
|
|
123
139
|
}
|
|
124
|
-
async afterContainerReady(options) { }
|
|
125
|
-
getApplication() {
|
|
126
|
-
return this.app;
|
|
127
|
-
}
|
|
128
140
|
getFrameworkType() {
|
|
129
|
-
return
|
|
141
|
+
return decorator_1.MidwayFrameworkType.WEB;
|
|
142
|
+
}
|
|
143
|
+
async run() {
|
|
144
|
+
// load controller
|
|
145
|
+
await this.loadMidwayController();
|
|
146
|
+
// restore use method
|
|
147
|
+
this.app.use = this.app.originUse;
|
|
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
|
+
}
|
|
169
|
+
// emit egg-ready message in agent and application
|
|
170
|
+
this.app.messenger.broadcast('egg-ready', undefined);
|
|
171
|
+
// emit `server` event in app
|
|
172
|
+
this.app.emit('server', this.server);
|
|
173
|
+
// register httpServer to applicationContext
|
|
174
|
+
this.getApplicationContext().registerObject(core_1.HTTP_SERVER_KEY, this.server);
|
|
175
|
+
const eggConfig = this.configService.getConfiguration('egg');
|
|
176
|
+
if (this.configService.getConfiguration('egg')) {
|
|
177
|
+
new Promise(resolve => {
|
|
178
|
+
const args = [eggConfig.port];
|
|
179
|
+
if (eggConfig.hostname) {
|
|
180
|
+
args.push(eggConfig.hostname);
|
|
181
|
+
}
|
|
182
|
+
args.push(() => {
|
|
183
|
+
resolve();
|
|
184
|
+
});
|
|
185
|
+
this.server.listen(...args);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
130
189
|
}
|
|
131
190
|
getLogger(name) {
|
|
132
191
|
if (name) {
|
|
@@ -134,27 +193,30 @@ class MidwayWebFramework extends koa_1.MidwayKoaBaseFramework {
|
|
|
134
193
|
}
|
|
135
194
|
return this.appLogger;
|
|
136
195
|
}
|
|
137
|
-
/**
|
|
138
|
-
* 这个方法 egg-cluster 不走,只有单进程模式使用 @midwayjs/bootstrap 才会执行
|
|
139
|
-
*/
|
|
140
|
-
async run() { }
|
|
141
|
-
/**
|
|
142
|
-
* 这个方法 egg-cluster 不走,只有单进程模式使用 @midwayjs/bootstrap 才会执行
|
|
143
|
-
*/
|
|
144
|
-
async beforeStop() { }
|
|
145
|
-
createRouter(routerOptions) {
|
|
146
|
-
const router = new router_1.EggRouter(routerOptions, this.app);
|
|
147
|
-
router.prefix(routerOptions.prefix);
|
|
148
|
-
this.prioritySortRouters.push({
|
|
149
|
-
priority: 0,
|
|
150
|
-
router,
|
|
151
|
-
});
|
|
152
|
-
return router;
|
|
153
|
-
}
|
|
154
196
|
setContextLoggerClass(BaseContextLogger) {
|
|
155
197
|
this.BaseContextLoggerClass = BaseContextLogger;
|
|
156
198
|
this.app.ContextLogger = BaseContextLogger;
|
|
157
199
|
}
|
|
158
|
-
|
|
200
|
+
async generateMiddleware(middlewareId) {
|
|
201
|
+
const mwIns = await this.getApplicationContext().getAsync(middlewareId);
|
|
202
|
+
return mwIns.resolve();
|
|
203
|
+
}
|
|
204
|
+
async beforeStop() {
|
|
205
|
+
if (!this.isClusterMode) {
|
|
206
|
+
await new Promise(resolve => {
|
|
207
|
+
this.server.close(resolve);
|
|
208
|
+
});
|
|
209
|
+
await this.app.close();
|
|
210
|
+
await this.agent.close();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
__decorate([
|
|
215
|
+
(0, decorator_1.Inject)(),
|
|
216
|
+
__metadata("design:type", Object)
|
|
217
|
+
], MidwayWebFramework.prototype, "appDir", void 0);
|
|
218
|
+
MidwayWebFramework = __decorate([
|
|
219
|
+
(0, decorator_1.Framework)()
|
|
220
|
+
], MidwayWebFramework);
|
|
159
221
|
exports.MidwayWebFramework = MidwayWebFramework;
|
|
160
222
|
//# sourceMappingURL=web.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from './interface';
|
|
2
|
-
export {
|
|
3
|
-
export { MidwayWebFramework } from './framework/web';
|
|
2
|
+
export { MidwayWebFramework as Framework } from './framework/web';
|
|
4
3
|
export { createEggApplication, createEggAgent, createAppWorkerLoader, createAgentWorkerLoader, } from './base';
|
|
5
4
|
export { Application, Agent } from './application';
|
|
6
5
|
export { startCluster } from 'egg';
|
|
6
|
+
export { EggConfiguration as Configuration } from './configuration';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -10,12 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.startCluster = exports.Agent = exports.Application = exports.createAgentWorkerLoader = exports.createAppWorkerLoader = exports.createEggAgent = exports.createEggApplication = exports.
|
|
13
|
+
exports.Configuration = exports.startCluster = exports.Agent = exports.Application = exports.createAgentWorkerLoader = exports.createAppWorkerLoader = exports.createEggAgent = exports.createEggApplication = exports.Framework = void 0;
|
|
14
14
|
__exportStar(require("./interface"), exports);
|
|
15
|
-
var singleProcess_1 = require("./framework/singleProcess");
|
|
16
|
-
Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return singleProcess_1.MidwayWebSingleProcessFramework; } });
|
|
17
15
|
var web_1 = require("./framework/web");
|
|
18
|
-
Object.defineProperty(exports, "
|
|
16
|
+
Object.defineProperty(exports, "Framework", { enumerable: true, get: function () { return web_1.MidwayWebFramework; } });
|
|
19
17
|
var base_1 = require("./base");
|
|
20
18
|
Object.defineProperty(exports, "createEggApplication", { enumerable: true, get: function () { return base_1.createEggApplication; } });
|
|
21
19
|
Object.defineProperty(exports, "createEggAgent", { enumerable: true, get: function () { return base_1.createEggAgent; } });
|
|
@@ -26,4 +24,6 @@ Object.defineProperty(exports, "Application", { enumerable: true, get: function
|
|
|
26
24
|
Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return application_1.Agent; } });
|
|
27
25
|
var egg_1 = require("egg");
|
|
28
26
|
Object.defineProperty(exports, "startCluster", { enumerable: true, get: function () { return egg_1.startCluster; } });
|
|
27
|
+
var configuration_1 = require("./configuration");
|
|
28
|
+
Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return configuration_1.EggConfiguration; } });
|
|
29
29
|
//# sourceMappingURL=index.js.map
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
/// <reference types="node" />
|
|
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
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: string): 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,8 +35,9 @@ 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 =
|
|
40
|
-
export
|
|
38
|
+
export declare type IMidwayWebNext = BaseNextFunction;
|
|
39
|
+
export declare type NextFunction = BaseNextFunction;
|
|
40
|
+
export interface IMidwayWebConfigurationOptions extends IConfigurationOptions {
|
|
41
41
|
app?: IMidwayWebApplication;
|
|
42
42
|
plugins?: {
|
|
43
43
|
[plugin: string]: {
|
|
@@ -49,9 +49,50 @@ export interface IMidwayWebConfigurationOptions extends IMidwayKoaConfigurationO
|
|
|
49
49
|
typescript?: boolean;
|
|
50
50
|
processType?: 'application' | 'agent';
|
|
51
51
|
globalConfig?: any;
|
|
52
|
+
/**
|
|
53
|
+
* application http port
|
|
54
|
+
*/
|
|
55
|
+
port?: number;
|
|
56
|
+
/**
|
|
57
|
+
* application hostname, 127.0.0.1 as default
|
|
58
|
+
*/
|
|
59
|
+
hostname?: string;
|
|
60
|
+
/**
|
|
61
|
+
* https key
|
|
62
|
+
*/
|
|
63
|
+
key?: string | Buffer | Array<Buffer | Object>;
|
|
64
|
+
/**
|
|
65
|
+
* https cert
|
|
66
|
+
*/
|
|
67
|
+
cert?: string | Buffer | Array<string | Buffer>;
|
|
68
|
+
/**
|
|
69
|
+
* https ca
|
|
70
|
+
*/
|
|
71
|
+
ca?: string | Buffer | Array<string | Buffer>;
|
|
72
|
+
/**
|
|
73
|
+
* http2 support
|
|
74
|
+
*/
|
|
75
|
+
http2?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* http global prefix
|
|
78
|
+
*/
|
|
79
|
+
globalPrefix?: string;
|
|
52
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated since version 3.0.0
|
|
83
|
+
* Please use IMiddleware from @midwayjs/core
|
|
84
|
+
*/
|
|
53
85
|
export declare type MidwayWebMiddleware = Middleware<DefaultState, Context>;
|
|
86
|
+
/**
|
|
87
|
+
* @deprecated since version 3.0.0
|
|
88
|
+
* Please use IMiddleware from @midwayjs/core
|
|
89
|
+
*/
|
|
54
90
|
export interface IWebMiddleware {
|
|
55
91
|
resolve(): MidwayWebMiddleware;
|
|
56
92
|
}
|
|
93
|
+
declare module '@midwayjs/core/dist/interface' {
|
|
94
|
+
interface MidwayConfig extends EggAppConfig {
|
|
95
|
+
egg?: IMidwayWebConfigurationOptions;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
57
98
|
//# sourceMappingURL=interface.d.ts.map
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { ILogger, MidwayContextLogger } from '@midwayjs/logger';
|
|
2
|
+
import { Application, Context } from 'egg';
|
|
3
|
+
declare class MidwayLoggers extends Map<string, ILogger> {
|
|
4
|
+
app: Application;
|
|
5
|
+
/**
|
|
6
|
+
* @constructor
|
|
7
|
+
* - logger
|
|
8
|
+
* - {String} env - egg app runtime env string, detail please see `app.config.env`
|
|
9
|
+
* - {String} type - current process type, `application` or `agent`
|
|
10
|
+
* - {String} dir - log file dir
|
|
11
|
+
* - {String} [encoding = utf8] - log string encoding
|
|
12
|
+
* - {String} [level = INFO] - file log level
|
|
13
|
+
* - {String} [consoleLevel = NONE] - console log level
|
|
14
|
+
* - {Boolean} [outputJSON = false] - send JSON log or not
|
|
15
|
+
* - {Boolean} [buffer = true] - use {@link FileBufferTransport} or not
|
|
16
|
+
* - {String} appLogName - egg app file logger name
|
|
17
|
+
* - {String} coreLogName - egg core file logger name
|
|
18
|
+
* - {String} agentLogName - egg agent file logger name
|
|
19
|
+
* - {String} errorLogName - err common error logger name
|
|
20
|
+
* - {String} eol - end of line char
|
|
21
|
+
* - {String} [concentrateError = duplicate] - whether write error logger to common-error.log, `duplicate` / `redirect` / `ignore`
|
|
22
|
+
* - customLogger
|
|
23
|
+
* @param options
|
|
24
|
+
* @param app
|
|
25
|
+
*/
|
|
26
|
+
constructor(options: any, app: Application, processType: 'agent' | 'app');
|
|
27
|
+
createLogger(options: any, loggerKey: string): ILogger;
|
|
28
|
+
disableConsole(): void;
|
|
29
|
+
reload(): void;
|
|
30
|
+
}
|
|
31
|
+
export declare const createLoggers: (app: Application, processType: 'agent' | 'app') => MidwayLoggers;
|
|
32
|
+
export declare class MidwayEggContextLogger extends MidwayContextLogger<Context> {
|
|
33
|
+
formatContextLabel(): string;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
3
36
|
//# sourceMappingURL=logger.d.ts.map
|