egg 3.26.1 → 4.0.0-beta.0
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/README.md +1 -1
- package/README.zh-CN.md +6 -5
- package/dist/commonjs/agent.d.ts +4 -0
- package/dist/commonjs/agent.js +10 -0
- package/dist/commonjs/app/middleware/body_parser.d.ts +2 -0
- package/dist/commonjs/app/middleware/body_parser.js +8 -0
- package/dist/commonjs/app/middleware/meta.d.ts +11 -0
- package/dist/commonjs/app/middleware/meta.js +22 -0
- package/dist/commonjs/app/middleware/notfound.d.ts +8 -0
- package/dist/commonjs/app/middleware/notfound.js +31 -0
- package/dist/commonjs/app/middleware/override_method.d.ts +2 -0
- package/dist/commonjs/app/middleware/override_method.js +8 -0
- package/dist/commonjs/app/middleware/site_file.d.ts +7 -0
- package/dist/commonjs/app/middleware/site_file.js +40 -0
- package/dist/commonjs/config/config.default.d.ts +9 -0
- package/dist/commonjs/config/config.default.js +378 -0
- package/dist/commonjs/config/config.local.d.ts +8 -0
- package/dist/commonjs/config/config.local.js +12 -0
- package/dist/commonjs/config/config.unittest.d.ts +7 -0
- package/dist/commonjs/config/config.unittest.js +11 -0
- package/dist/commonjs/config/plugin.d.ts +122 -0
- package/dist/commonjs/config/plugin.js +125 -0
- package/dist/commonjs/index.d.ts +61 -0
- package/dist/commonjs/index.js +89 -0
- package/dist/commonjs/lib/agent.d.ts +19 -0
- package/dist/commonjs/lib/agent.js +58 -0
- package/dist/commonjs/lib/application.d.ts +66 -0
- package/dist/commonjs/lib/application.js +281 -0
- package/dist/commonjs/lib/core/base_context_class.d.ts +14 -0
- package/dist/commonjs/lib/core/base_context_class.js +22 -0
- package/dist/commonjs/lib/core/base_context_logger.d.ts +36 -0
- package/dist/commonjs/lib/core/base_context_logger.js +64 -0
- package/dist/commonjs/lib/core/base_hook_class.d.ts +11 -0
- package/dist/commonjs/lib/core/base_hook_class.js +30 -0
- package/dist/commonjs/lib/core/context_httpclient.d.ts +16 -0
- package/dist/commonjs/lib/core/context_httpclient.js +30 -0
- package/dist/commonjs/lib/core/httpclient.d.ts +14 -0
- package/dist/commonjs/lib/core/httpclient.js +40 -0
- package/dist/commonjs/lib/core/logger.d.ts +3 -0
- package/dist/commonjs/lib/core/logger.js +40 -0
- package/dist/commonjs/lib/core/messenger/IMessenger.d.ts +50 -0
- package/dist/commonjs/lib/core/messenger/IMessenger.js +3 -0
- package/dist/commonjs/lib/core/messenger/index.d.ts +7 -0
- package/dist/commonjs/lib/core/messenger/index.js +14 -0
- package/dist/commonjs/lib/core/messenger/ipc.d.ts +57 -0
- package/dist/commonjs/lib/core/messenger/ipc.js +126 -0
- package/dist/commonjs/lib/core/messenger/local.d.ts +61 -0
- package/dist/commonjs/lib/core/messenger/local.js +134 -0
- package/dist/commonjs/lib/core/singleton.d.ts +23 -0
- package/dist/commonjs/lib/core/singleton.js +120 -0
- package/dist/commonjs/lib/core/utils.d.ts +2 -0
- package/dist/commonjs/lib/core/utils.js +77 -0
- package/dist/commonjs/lib/egg.d.ts +267 -0
- package/dist/commonjs/lib/egg.js +595 -0
- package/dist/commonjs/lib/loader/AgentWorkerLoader.d.ts +12 -0
- package/dist/commonjs/lib/loader/AgentWorkerLoader.js +24 -0
- package/dist/commonjs/lib/loader/AppWorkerLoader.d.ts +17 -0
- package/dist/commonjs/lib/loader/AppWorkerLoader.js +43 -0
- package/dist/commonjs/lib/loader/EggApplicationLoader.d.ts +4 -0
- package/dist/commonjs/lib/loader/EggApplicationLoader.js +8 -0
- package/dist/commonjs/lib/loader/index.d.ts +3 -0
- package/dist/commonjs/lib/loader/index.js +22 -0
- package/dist/commonjs/lib/start.d.ts +15 -0
- package/dist/commonjs/lib/start.js +49 -0
- package/dist/commonjs/lib/type.d.ts +295 -0
- package/dist/commonjs/lib/type.js +3 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/esm/agent.d.ts +4 -0
- package/dist/esm/agent.js +7 -0
- package/dist/esm/app/middleware/body_parser.d.ts +2 -0
- package/dist/esm/app/middleware/body_parser.js +3 -0
- package/dist/esm/app/middleware/meta.d.ts +11 -0
- package/dist/esm/app/middleware/meta.js +20 -0
- package/dist/esm/app/middleware/notfound.d.ts +8 -0
- package/dist/esm/app/middleware/notfound.js +29 -0
- package/dist/esm/app/middleware/override_method.d.ts +2 -0
- package/dist/esm/app/middleware/override_method.js +3 -0
- package/dist/esm/app/middleware/site_file.d.ts +7 -0
- package/dist/esm/app/middleware/site_file.js +35 -0
- package/dist/esm/config/config.default.d.ts +9 -0
- package/dist/esm/config/config.default.js +373 -0
- package/dist/esm/config/config.local.d.ts +8 -0
- package/dist/esm/config/config.local.js +10 -0
- package/dist/esm/config/config.unittest.d.ts +7 -0
- package/dist/esm/config/config.unittest.js +9 -0
- package/dist/esm/config/favicon.png +0 -0
- package/dist/esm/config/plugin.d.ts +122 -0
- package/dist/esm/config/plugin.js +123 -0
- package/dist/esm/index.d.ts +61 -0
- package/dist/esm/index.js +65 -0
- package/dist/esm/lib/agent.d.ts +19 -0
- package/dist/esm/lib/agent.js +54 -0
- package/dist/esm/lib/application.d.ts +66 -0
- package/dist/esm/lib/application.js +274 -0
- package/dist/esm/lib/core/base_context_class.d.ts +14 -0
- package/dist/esm/lib/core/base_context_class.js +18 -0
- package/dist/esm/lib/core/base_context_logger.d.ts +36 -0
- package/dist/esm/lib/core/base_context_logger.js +60 -0
- package/dist/esm/lib/core/base_hook_class.d.ts +11 -0
- package/dist/esm/lib/core/base_hook_class.js +23 -0
- package/dist/esm/lib/core/context_httpclient.d.ts +16 -0
- package/dist/esm/lib/core/context_httpclient.js +26 -0
- package/dist/esm/lib/core/httpclient.d.ts +14 -0
- package/dist/esm/lib/core/httpclient.js +33 -0
- package/dist/esm/lib/core/logger.d.ts +3 -0
- package/dist/esm/lib/core/logger.js +37 -0
- package/dist/esm/lib/core/messenger/IMessenger.d.ts +50 -0
- package/dist/esm/lib/core/messenger/IMessenger.js +2 -0
- package/dist/esm/lib/core/messenger/index.d.ts +7 -0
- package/dist/esm/lib/core/messenger/index.js +11 -0
- package/dist/esm/lib/core/messenger/ipc.d.ts +57 -0
- package/dist/esm/lib/core/messenger/ipc.js +119 -0
- package/dist/esm/lib/core/messenger/local.d.ts +61 -0
- package/dist/esm/lib/core/messenger/local.js +127 -0
- package/dist/esm/lib/core/singleton.d.ts +23 -0
- package/dist/esm/lib/core/singleton.js +113 -0
- package/dist/esm/lib/core/utils.d.ts +2 -0
- package/dist/esm/lib/core/utils.js +70 -0
- package/dist/esm/lib/egg.d.ts +267 -0
- package/dist/esm/lib/egg.js +565 -0
- package/dist/esm/lib/loader/AgentWorkerLoader.d.ts +12 -0
- package/dist/esm/lib/loader/AgentWorkerLoader.js +20 -0
- package/dist/esm/lib/loader/AppWorkerLoader.d.ts +17 -0
- package/dist/esm/lib/loader/AppWorkerLoader.js +39 -0
- package/dist/esm/lib/loader/EggApplicationLoader.d.ts +4 -0
- package/dist/esm/lib/loader/EggApplicationLoader.js +4 -0
- package/dist/esm/lib/loader/index.d.ts +3 -0
- package/dist/esm/lib/loader/index.js +4 -0
- package/dist/esm/lib/start.d.ts +15 -0
- package/dist/esm/lib/start.js +43 -0
- package/dist/esm/lib/type.d.ts +295 -0
- package/dist/esm/lib/type.js +2 -0
- package/dist/esm/package.json +3 -0
- package/dist/package.json +4 -0
- package/package.json +83 -70
- package/src/agent.ts +7 -0
- package/src/app/middleware/body_parser.ts +3 -0
- package/{app/middleware/meta.js → src/app/middleware/meta.ts} +12 -4
- package/{app/middleware/notfound.js → src/app/middleware/notfound.ts} +9 -3
- package/src/app/middleware/override_method.ts +3 -0
- package/src/app/middleware/site_file.ts +49 -0
- package/{config/config.default.js → src/config/config.default.ts} +21 -42
- package/src/config/config.local.ts +11 -0
- package/src/config/config.unittest.ts +10 -0
- package/src/config/favicon.png +0 -0
- package/{config/plugin.js → src/config/plugin.ts} +1 -3
- package/src/index.ts +78 -0
- package/src/lib/agent.ts +66 -0
- package/{lib/application.js → src/lib/application.ts} +79 -120
- package/src/lib/core/base_context_class.ts +21 -0
- package/src/lib/core/base_context_logger.ts +67 -0
- package/src/lib/core/base_hook_class.ts +30 -0
- package/src/lib/core/context_httpclient.ts +33 -0
- package/src/lib/core/httpclient.ts +52 -0
- package/src/lib/core/logger.ts +42 -0
- package/src/lib/core/messenger/IMessenger.ts +58 -0
- package/src/lib/core/messenger/index.ts +15 -0
- package/{lib/core/messenger/ipc.js → src/lib/core/messenger/ipc.ts} +25 -29
- package/{lib/core/messenger/local.js → src/lib/core/messenger/local.ts} +27 -21
- package/{lib/core/singleton.js → src/lib/core/singleton.ts} +56 -33
- package/src/lib/core/utils.ts +77 -0
- package/{lib/egg.js → src/lib/egg.ts} +252 -218
- package/src/lib/loader/AgentWorkerLoader.ts +21 -0
- package/src/lib/loader/AppWorkerLoader.ts +42 -0
- package/src/lib/loader/EggApplicationLoader.ts +5 -0
- package/src/lib/loader/index.ts +3 -0
- package/src/lib/start.ts +56 -0
- package/src/lib/type.ts +329 -0
- package/agent.js +0 -11
- package/app/middleware/body_parser.js +0 -3
- package/app/middleware/override_method.js +0 -3
- package/app/middleware/site_file.js +0 -31
- package/config/config.local.js +0 -7
- package/config/config.unittest.js +0 -8
- package/index.d.ts +0 -1285
- package/index.js +0 -68
- package/lib/agent.js +0 -95
- package/lib/core/base_context_class.js +0 -20
- package/lib/core/base_context_logger.js +0 -64
- package/lib/core/base_hook_class.js +0 -31
- package/lib/core/context_httpclient.js +0 -26
- package/lib/core/dnscache_httpclient.js +0 -93
- package/lib/core/httpclient.js +0 -108
- package/lib/core/httpclient_next.js +0 -45
- package/lib/core/logger.js +0 -35
- package/lib/core/messenger/index.js +0 -14
- package/lib/core/utils.js +0 -73
- package/lib/loader/agent_worker_loader.js +0 -27
- package/lib/loader/app_worker_loader.js +0 -48
- package/lib/loader/index.js +0 -5
- package/lib/start.js +0 -39
- /package/{config → dist/commonjs/config}/favicon.png +0 -0
- /package/{app → src/app}/extend/context.js +0 -0
- /package/{app → src/app}/extend/helper.js +0 -0
- /package/{app → src/app}/extend/request.js +0 -0
- /package/{app → src/app}/extend/response.js +0 -0
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
* meta middleware, should be the first middleware
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { performance } from 'node:perf_hooks';
|
|
6
|
+
import type { EggCoreContext } from '@eggjs/core';
|
|
7
|
+
import type { Next } from '../../lib/type.js';
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
export interface MetaMiddlewareOptions {
|
|
10
|
+
enable: boolean;
|
|
11
|
+
logging: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default (options: MetaMiddlewareOptions) => {
|
|
15
|
+
return async function meta(ctx: EggCoreContext, next: Next) {
|
|
9
16
|
if (options.logging) {
|
|
10
|
-
ctx.coreLogger.info('[meta] request started, host: %s, user-agent: %s',
|
|
17
|
+
ctx.coreLogger.info('[meta] request started, host: %s, user-agent: %s',
|
|
18
|
+
ctx.host, ctx.header['user-agent']);
|
|
11
19
|
}
|
|
12
20
|
await next();
|
|
13
21
|
// total response time header
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import type { EggCoreContext } from '@eggjs/core';
|
|
2
|
+
import type { Next } from '../../lib/type.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
export interface NotFoundMiddlewareOptions {
|
|
5
|
+
enable: boolean;
|
|
6
|
+
pageUrl: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default (options: NotFoundMiddlewareOptions) => {
|
|
10
|
+
return async function notfound(ctx: EggCoreContext, next: Next) {
|
|
5
11
|
await next();
|
|
6
12
|
|
|
7
13
|
if (ctx.status !== 404 || ctx.body) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { EggCoreContext } from '@eggjs/core';
|
|
3
|
+
import type { Next } from '../../lib/type.js';
|
|
4
|
+
|
|
5
|
+
export type SiteFileContentFun = (ctx: EggCoreContext) => Promise<Buffer | string>;
|
|
6
|
+
|
|
7
|
+
export interface SiteFileMiddlewareOptions {
|
|
8
|
+
enable: boolean;
|
|
9
|
+
cacheControl: string;
|
|
10
|
+
[key: string]: string | Buffer | boolean | SiteFileContentFun;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
module.exports = (options: SiteFileMiddlewareOptions) => {
|
|
14
|
+
return async function siteFile(ctx: EggCoreContext, next: Next) {
|
|
15
|
+
if (ctx.method !== 'HEAD' && ctx.method !== 'GET') {
|
|
16
|
+
return next();
|
|
17
|
+
}
|
|
18
|
+
/* istanbul ignore if */
|
|
19
|
+
if (ctx.path[0] !== '/') {
|
|
20
|
+
return next();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let content = options[ctx.path];
|
|
24
|
+
if (!content) {
|
|
25
|
+
return next();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// '/favicon.ico': 'https://eggjs.org/favicon.ico' or '/favicon.ico': async (ctx) => 'https://eggjs.org/favicon.ico'
|
|
29
|
+
// content is function
|
|
30
|
+
if (typeof content === 'function') {
|
|
31
|
+
content = await content(ctx);
|
|
32
|
+
}
|
|
33
|
+
// content is url
|
|
34
|
+
if (typeof content === 'string') {
|
|
35
|
+
return ctx.redirect(content);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// '/robots.txt': Buffer <xx..
|
|
39
|
+
// content is buffer
|
|
40
|
+
if (Buffer.isBuffer(content)) {
|
|
41
|
+
ctx.set('cache-control', options.cacheControl);
|
|
42
|
+
ctx.body = content;
|
|
43
|
+
ctx.type = path.extname(ctx.path);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return next();
|
|
48
|
+
};
|
|
49
|
+
};
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import type { EggAppInfo } from '@eggjs/core';
|
|
4
|
+
import type { EggAppConfig } from '../lib/type.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* The configuration of egg application, can be access by `app.config`
|
|
8
8
|
* @class Config
|
|
9
9
|
* @since 1.0.0
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const config = {
|
|
15
|
-
|
|
11
|
+
export default (appInfo: EggAppInfo) => {
|
|
12
|
+
const config: Partial<EggAppConfig> = {
|
|
16
13
|
/**
|
|
17
14
|
* The environment of egg
|
|
18
15
|
* @member {String} Config#env
|
|
@@ -131,7 +128,7 @@ module.exports = appInfo => {
|
|
|
131
128
|
HOME: appInfo.HOME,
|
|
132
129
|
|
|
133
130
|
/**
|
|
134
|
-
* The directory of server running. You can find `application_config.json` under it that is
|
|
131
|
+
* The directory of server running. You can find `application_config.json` under it that is dumped from `app.config`.
|
|
135
132
|
* @member {String} Config#rundir
|
|
136
133
|
* @default
|
|
137
134
|
* @since 1.0.0
|
|
@@ -153,7 +150,7 @@ module.exports = appInfo => {
|
|
|
153
150
|
/secret/i,
|
|
154
151
|
]),
|
|
155
152
|
timing: {
|
|
156
|
-
// if boot action >= slowBootActionMinDuration, egg core will print it to
|
|
153
|
+
// if boot action >= slowBootActionMinDuration, egg core will print it to warning log
|
|
157
154
|
slowBootActionMinDuration: 5000,
|
|
158
155
|
},
|
|
159
156
|
},
|
|
@@ -176,7 +173,7 @@ module.exports = appInfo => {
|
|
|
176
173
|
};
|
|
177
174
|
|
|
178
175
|
/**
|
|
179
|
-
* The
|
|
176
|
+
* The options of `notfound` middleware
|
|
180
177
|
*
|
|
181
178
|
* It will return page or json depend on negotiation when 404,
|
|
182
179
|
* If pageUrl is set, it will redirect to the page.
|
|
@@ -185,6 +182,7 @@ module.exports = appInfo => {
|
|
|
185
182
|
* @property {String} pageUrl - the 404 page url
|
|
186
183
|
*/
|
|
187
184
|
config.notfound = {
|
|
185
|
+
enable: true,
|
|
188
186
|
pageUrl: '',
|
|
189
187
|
};
|
|
190
188
|
|
|
@@ -202,13 +200,14 @@ module.exports = appInfo => {
|
|
|
202
200
|
* };
|
|
203
201
|
*/
|
|
204
202
|
config.siteFile = {
|
|
203
|
+
enable: true,
|
|
205
204
|
'/favicon.ico': fs.readFileSync(path.join(__dirname, 'favicon.png')),
|
|
206
205
|
// default cache in 30 days
|
|
207
206
|
cacheControl: 'public, max-age=2592000',
|
|
208
207
|
};
|
|
209
208
|
|
|
210
209
|
/**
|
|
211
|
-
* The
|
|
210
|
+
* The options of `bodyParser` middleware
|
|
212
211
|
*
|
|
213
212
|
* @member Config#bodyParser
|
|
214
213
|
* @property {Boolean} enable - enable bodyParser or not, default is true
|
|
@@ -236,8 +235,9 @@ module.exports = appInfo => {
|
|
|
236
235
|
depth: 5,
|
|
237
236
|
parameterLimit: 1000,
|
|
238
237
|
},
|
|
238
|
+
onProtoPoisoning: 'error',
|
|
239
239
|
onerror(err, ctx) {
|
|
240
|
-
err.message
|
|
240
|
+
err.message = `${err.message}, check bodyParser config`;
|
|
241
241
|
if (ctx.status === 404) {
|
|
242
242
|
// set default status to 400, meaning client bad request
|
|
243
243
|
ctx.status = 400;
|
|
@@ -264,8 +264,7 @@ module.exports = appInfo => {
|
|
|
264
264
|
* @property {String} agentLogName - file name of agent worker log
|
|
265
265
|
* @property {Object} coreLogger - custom config of coreLogger
|
|
266
266
|
* @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
|
|
267
|
-
* @property {Boolean}
|
|
268
|
-
* @property {Boolean} enableFastContextLogger - using the app logger instead of EggContextLogger, defaults to false
|
|
267
|
+
* @property {Boolean} enableFastContextLogger - using the app logger instead of EggContextLogger, defaults to true
|
|
269
268
|
*/
|
|
270
269
|
config.logger = {
|
|
271
270
|
dir: path.join(appInfo.root, 'logs', appInfo.name),
|
|
@@ -282,8 +281,7 @@ module.exports = appInfo => {
|
|
|
282
281
|
errorLogName: 'common-error.log',
|
|
283
282
|
coreLogger: {},
|
|
284
283
|
allowDebugAtProd: false,
|
|
285
|
-
|
|
286
|
-
enableFastContextLogger: false,
|
|
284
|
+
enableFastContextLogger: true,
|
|
287
285
|
};
|
|
288
286
|
|
|
289
287
|
/**
|
|
@@ -304,38 +302,19 @@ module.exports = appInfo => {
|
|
|
304
302
|
* @property {Number} httpsAgent.maxSockets - https agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
|
|
305
303
|
* @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
|
|
306
304
|
* @property {Boolean} useHttpClientNext - use urllib@3 HttpClient
|
|
307
|
-
* @property {Boolean} allowH2 - Allow to use HTTP2 first, only work on `useHttpClientNext = true`
|
|
308
305
|
*/
|
|
309
306
|
config.httpclient = {
|
|
310
|
-
enableDNSCache: false,
|
|
311
|
-
dnsCacheLookupInterval: 10000,
|
|
312
|
-
dnsCacheMaxLength: 1000,
|
|
313
|
-
|
|
314
307
|
request: {
|
|
315
308
|
timeout: 5000,
|
|
316
309
|
},
|
|
317
|
-
httpAgent: {
|
|
318
|
-
keepAlive: true,
|
|
319
|
-
freeSocketTimeout: 4000,
|
|
320
|
-
maxSockets: Number.MAX_SAFE_INTEGER,
|
|
321
|
-
maxFreeSockets: 256,
|
|
322
|
-
},
|
|
323
|
-
httpsAgent: {
|
|
324
|
-
keepAlive: true,
|
|
325
|
-
freeSocketTimeout: 4000,
|
|
326
|
-
maxSockets: Number.MAX_SAFE_INTEGER,
|
|
327
|
-
maxFreeSockets: 256,
|
|
328
|
-
},
|
|
329
|
-
useHttpClientNext: false,
|
|
330
|
-
// allowH2: false,
|
|
331
310
|
};
|
|
332
311
|
|
|
333
312
|
/**
|
|
334
|
-
* The
|
|
313
|
+
* The options of `meta` middleware
|
|
335
314
|
*
|
|
336
315
|
* @member Config#meta
|
|
337
|
-
* @property {Boolean} enable - enable meta or not, default is true
|
|
338
|
-
* @property {Boolean} logging - enable logging start request, default is false
|
|
316
|
+
* @property {Boolean} enable - enable meta or not, default is `true`
|
|
317
|
+
* @property {Boolean} logging - enable logging start request, default is `false`
|
|
339
318
|
*/
|
|
340
319
|
config.meta = {
|
|
341
320
|
enable: true,
|
|
@@ -371,7 +350,7 @@ module.exports = appInfo => {
|
|
|
371
350
|
config.serverTimeout = null;
|
|
372
351
|
|
|
373
352
|
/**
|
|
374
|
-
*
|
|
353
|
+
* The options of cluster
|
|
375
354
|
* @member {Object} Config#cluster
|
|
376
355
|
* @property {Object} listen - listen options, see {@link https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback}
|
|
377
356
|
* @property {String} listen.path - set a unix sock path when server listen
|
|
@@ -418,7 +397,7 @@ module.exports = appInfo => {
|
|
|
418
397
|
* };
|
|
419
398
|
* }
|
|
420
399
|
*/
|
|
421
|
-
config.onClientError =
|
|
400
|
+
config.onClientError = undefined;
|
|
422
401
|
|
|
423
402
|
return config;
|
|
424
403
|
};
|
|
Binary file
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @namespace Egg
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { BaseContextClass } from './lib/core/base_context_class.js';
|
|
6
|
+
import { startEgg } from './lib/start.js';
|
|
7
|
+
|
|
8
|
+
// export types
|
|
9
|
+
export * from './lib/egg.js';
|
|
10
|
+
export * from './lib/type.js';
|
|
11
|
+
export * from './lib/start.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Start egg application with cluster mode
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
*/
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
export { startCluster } from 'egg-cluster';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Start egg application with single process mode
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
export const start = startEgg;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @member {Application} Egg#Application
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
*/
|
|
31
|
+
export { Application } from './lib/application.js';
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @member {Agent} Egg#Agent
|
|
35
|
+
* @since 1.0.0
|
|
36
|
+
*/
|
|
37
|
+
export { Agent } from './lib/agent.js';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @member {AppWorkerLoader} Egg#AppWorkerLoader
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @member {AgentWorkerLoader} Egg#AgentWorkerLoader
|
|
46
|
+
* @since 1.0.0
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
export { AppWorkerLoader, AgentWorkerLoader } from './lib/loader/index.js';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @member {Controller} Egg#Controller
|
|
53
|
+
* @since 1.1.0
|
|
54
|
+
*/
|
|
55
|
+
export const Controller = BaseContextClass;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @member {Service} Egg#Service
|
|
59
|
+
* @since 1.1.0
|
|
60
|
+
*/
|
|
61
|
+
export const Service = BaseContextClass;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @member {Subscription} Egg#Subscription
|
|
65
|
+
* @since 1.10.0
|
|
66
|
+
*/
|
|
67
|
+
export const Subscription = BaseContextClass;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @member {BaseContextClass} Egg#BaseContextClass
|
|
71
|
+
* @since 1.2.0
|
|
72
|
+
*/
|
|
73
|
+
export { BaseContextClass } from './lib/core/base_context_class.js';
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @member {Boot} Egg#Boot
|
|
77
|
+
*/
|
|
78
|
+
export { BaseHookClass as Boot } from './lib/core/base_hook_class.js';
|
package/src/lib/agent.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { EggLogger } from 'egg-logger';
|
|
2
|
+
import { EggApplicationCore, EggApplicationCoreOptions } from './egg.js';
|
|
3
|
+
import { AgentWorkerLoader } from './loader/index.js';
|
|
4
|
+
|
|
5
|
+
const EGG_LOADER = Symbol.for('egg#loader');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Singleton instance in Agent Worker, extend {@link EggApplicationCore}
|
|
9
|
+
* @augments EggApplicationCore
|
|
10
|
+
*/
|
|
11
|
+
export class Agent extends EggApplicationCore {
|
|
12
|
+
readonly #agentAliveHandler: NodeJS.Timeout;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @class
|
|
16
|
+
* @param {Object} options - see {@link EggApplicationCore}
|
|
17
|
+
*/
|
|
18
|
+
constructor(options?: Omit<EggApplicationCoreOptions, 'type'>) {
|
|
19
|
+
super({
|
|
20
|
+
...options,
|
|
21
|
+
type: 'agent',
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// keep agent alive even it doesn't have any io tasks
|
|
25
|
+
this.#agentAliveHandler = setInterval(() => {
|
|
26
|
+
this.coreLogger.info('[]');
|
|
27
|
+
}, 24 * 60 * 60 * 1000);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get [EGG_LOADER]() {
|
|
31
|
+
return AgentWorkerLoader;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
_wrapMessenger() {
|
|
35
|
+
for (const methodName of [
|
|
36
|
+
'broadcast',
|
|
37
|
+
'sendTo',
|
|
38
|
+
'sendToApp',
|
|
39
|
+
'sendToAgent',
|
|
40
|
+
'sendRandom',
|
|
41
|
+
]) {
|
|
42
|
+
wrapMethod(methodName, this.messenger, this.coreLogger);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function wrapMethod(methodName: string, messenger: any, logger: EggLogger) {
|
|
46
|
+
const originMethod = messenger[methodName];
|
|
47
|
+
messenger[methodName] = function(...args: any[]) {
|
|
48
|
+
const stack = new Error().stack!.split('\n').slice(1).join('\n');
|
|
49
|
+
logger.warn(
|
|
50
|
+
"agent can't call %s before server started\n%s",
|
|
51
|
+
methodName,
|
|
52
|
+
stack,
|
|
53
|
+
);
|
|
54
|
+
originMethod.apply(this, args);
|
|
55
|
+
};
|
|
56
|
+
messenger.prependOnceListener('egg-ready', () => {
|
|
57
|
+
messenger[methodName] = originMethod;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async close() {
|
|
63
|
+
clearInterval(this.#agentAliveHandler);
|
|
64
|
+
await super.close();
|
|
65
|
+
}
|
|
66
|
+
}
|