egg 4.0.10 → 4.1.0-beta.2
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 +4 -22
- package/dist/agent.d.ts +8 -0
- package/dist/agent.js +11 -0
- package/dist/app/extend/context.d.ts +207 -0
- package/dist/app/extend/context.js +244 -0
- package/{src/app/extend/helper.ts → dist/app/extend/helper.d.ts} +8 -10
- package/dist/app/extend/helper.js +47 -0
- package/dist/app/extend/request.d.ts +145 -0
- package/dist/app/extend/request.js +226 -0
- package/{src/app/extend/response.ts → dist/app/extend/response.d.ts} +7 -16
- package/dist/app/extend/response.js +36 -0
- package/dist/app/middleware/body_parser.d.ts +2 -0
- package/dist/app/middleware/body_parser.js +7 -0
- package/dist/app/middleware/meta.d.ts +11 -0
- package/dist/app/middleware/meta.js +14 -0
- package/dist/app/middleware/notfound.d.ts +11 -0
- package/dist/app/middleware/notfound.js +26 -0
- package/dist/app/middleware/override_method.d.ts +2 -0
- package/dist/app/middleware/override_method.js +7 -0
- package/dist/app/middleware/site_file.d.ts +13 -0
- package/dist/app/middleware/site_file.js +38 -0
- package/dist/config/config.default.d.ts +13 -0
- package/dist/config/config.default.js +257 -0
- package/dist/config/config.local.d.ts +10 -0
- package/dist/config/config.local.js +7 -0
- package/dist/config/config.unittest.d.ts +9 -0
- package/dist/config/config.unittest.js +10 -0
- package/{src/config/plugin.ts → dist/config/plugin.d.ts} +40 -48
- package/dist/config/plugin.js +54 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +21 -0
- package/dist/lib/agent.d.ts +22 -0
- package/dist/lib/agent.js +56 -0
- package/dist/lib/application.d.ts +71 -0
- package/dist/lib/application.js +209 -0
- package/dist/lib/core/base_context_class.d.ts +23 -0
- package/dist/lib/core/base_context_class.js +19 -0
- package/dist/lib/core/base_context_logger.d.ts +40 -0
- package/dist/lib/core/base_context_logger.js +58 -0
- package/dist/lib/core/base_hook_class.d.ts +18 -0
- package/dist/lib/core/base_hook_class.js +26 -0
- package/dist/lib/core/context_httpclient.d.ts +21 -0
- package/dist/lib/core/context_httpclient.js +29 -0
- package/dist/lib/core/httpclient.d.ts +17 -0
- package/dist/lib/core/httpclient.js +36 -0
- package/dist/lib/core/logger.d.ts +7 -0
- package/dist/lib/core/logger.js +31 -0
- package/{src/lib/core/messenger/IMessenger.ts → dist/lib/core/messenger/IMessenger.d.ts} +6 -10
- package/dist/lib/core/messenger/IMessenger.js +1 -0
- package/dist/lib/core/messenger/base.d.ts +12 -0
- package/dist/lib/core/messenger/base.js +29 -0
- package/dist/lib/core/messenger/index.d.ts +11 -0
- package/dist/lib/core/messenger/index.js +13 -0
- package/dist/lib/core/messenger/ipc.d.ts +63 -0
- package/dist/lib/core/messenger/ipc.js +122 -0
- package/dist/lib/core/messenger/local.d.ts +65 -0
- package/dist/lib/core/messenger/local.js +126 -0
- package/dist/lib/core/utils.d.ts +5 -0
- package/dist/lib/core/utils.js +48 -0
- package/dist/lib/egg.d.ts +306 -0
- package/dist/lib/egg.js +512 -0
- package/dist/lib/error/CookieLimitExceedError.d.ts +8 -0
- package/dist/lib/error/CookieLimitExceedError.js +15 -0
- package/dist/lib/error/MessageUnhandledRejectionError.d.ts +8 -0
- package/dist/lib/error/MessageUnhandledRejectionError.js +15 -0
- package/dist/lib/error/index.d.ts +3 -0
- package/dist/lib/error/index.js +4 -0
- package/dist/lib/loader/AgentWorkerLoader.d.ts +17 -0
- package/dist/lib/loader/AgentWorkerLoader.js +24 -0
- package/dist/lib/loader/AppWorkerLoader.d.ts +22 -0
- package/dist/lib/loader/AppWorkerLoader.js +37 -0
- package/dist/lib/loader/EggApplicationLoader.d.ts +8 -0
- package/dist/lib/loader/EggApplicationLoader.js +7 -0
- package/dist/lib/loader/index.d.ts +4 -0
- package/dist/lib/loader/index.js +5 -0
- package/dist/lib/start.d.ts +28 -0
- package/dist/lib/start.js +36 -0
- package/{src/lib/types.ts → dist/lib/types.d.ts} +45 -94
- package/dist/lib/types.js +14 -0
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.js +14 -0
- package/dist/urllib.d.ts +2 -0
- package/dist/urllib.js +3 -0
- package/package.json +76 -97
- package/README.zh-CN.md +0 -61
- package/dist/commonjs/agent.d.ts +0 -4
- package/dist/commonjs/agent.js +0 -10
- package/dist/commonjs/app/extend/context.d.ts +0 -204
- package/dist/commonjs/app/extend/context.js +0 -262
- package/dist/commonjs/app/extend/helper.d.ts +0 -37
- package/dist/commonjs/app/extend/helper.js +0 -49
- package/dist/commonjs/app/extend/request.d.ts +0 -141
- package/dist/commonjs/app/extend/request.js +0 -270
- package/dist/commonjs/app/extend/response.d.ts +0 -31
- package/dist/commonjs/app/extend/response.js +0 -37
- package/dist/commonjs/app/middleware/body_parser.d.ts +0 -2
- package/dist/commonjs/app/middleware/body_parser.js +0 -8
- package/dist/commonjs/app/middleware/meta.d.ts +0 -10
- package/dist/commonjs/app/middleware/meta.js +0 -22
- package/dist/commonjs/app/middleware/notfound.d.ts +0 -7
- package/dist/commonjs/app/middleware/notfound.js +0 -31
- package/dist/commonjs/app/middleware/override_method.d.ts +0 -2
- package/dist/commonjs/app/middleware/override_method.js +0 -8
- package/dist/commonjs/app/middleware/site_file.d.ts +0 -9
- package/dist/commonjs/app/middleware/site_file.js +0 -58
- package/dist/commonjs/config/config.default.d.ts +0 -9
- package/dist/commonjs/config/config.default.js +0 -379
- package/dist/commonjs/config/config.local.d.ts +0 -8
- package/dist/commonjs/config/config.local.js +0 -12
- package/dist/commonjs/config/config.unittest.d.ts +0 -7
- package/dist/commonjs/config/config.unittest.js +0 -11
- package/dist/commonjs/config/favicon.png +0 -0
- package/dist/commonjs/config/plugin.d.ts +0 -122
- package/dist/commonjs/config/plugin.js +0 -124
- package/dist/commonjs/index.d.ts +0 -69
- package/dist/commonjs/index.js +0 -83
- package/dist/commonjs/lib/agent.d.ts +0 -19
- package/dist/commonjs/lib/agent.js +0 -58
- package/dist/commonjs/lib/application.d.ts +0 -67
- package/dist/commonjs/lib/application.js +0 -266
- package/dist/commonjs/lib/core/base_context_class.d.ts +0 -17
- package/dist/commonjs/lib/core/base_context_class.js +0 -21
- package/dist/commonjs/lib/core/base_context_logger.d.ts +0 -36
- package/dist/commonjs/lib/core/base_context_logger.js +0 -64
- package/dist/commonjs/lib/core/base_hook_class.d.ts +0 -11
- package/dist/commonjs/lib/core/base_hook_class.js +0 -29
- package/dist/commonjs/lib/core/context_httpclient.d.ts +0 -16
- package/dist/commonjs/lib/core/context_httpclient.js +0 -30
- package/dist/commonjs/lib/core/httpclient.d.ts +0 -14
- package/dist/commonjs/lib/core/httpclient.js +0 -42
- package/dist/commonjs/lib/core/logger.d.ts +0 -3
- package/dist/commonjs/lib/core/logger.js +0 -40
- package/dist/commonjs/lib/core/messenger/IMessenger.d.ts +0 -50
- package/dist/commonjs/lib/core/messenger/IMessenger.js +0 -3
- package/dist/commonjs/lib/core/messenger/base.d.ts +0 -8
- package/dist/commonjs/lib/core/messenger/base.js +0 -31
- package/dist/commonjs/lib/core/messenger/index.d.ts +0 -7
- package/dist/commonjs/lib/core/messenger/index.js +0 -15
- package/dist/commonjs/lib/core/messenger/ipc.d.ts +0 -58
- package/dist/commonjs/lib/core/messenger/ipc.js +0 -135
- package/dist/commonjs/lib/core/messenger/local.d.ts +0 -60
- package/dist/commonjs/lib/core/messenger/local.js +0 -132
- package/dist/commonjs/lib/core/utils.d.ts +0 -2
- package/dist/commonjs/lib/core/utils.js +0 -77
- package/dist/commonjs/lib/egg.d.ts +0 -305
- package/dist/commonjs/lib/egg.js +0 -628
- package/dist/commonjs/lib/error/CookieLimitExceedError.d.ts +0 -5
- package/dist/commonjs/lib/error/CookieLimitExceedError.js +0 -16
- package/dist/commonjs/lib/error/MessageUnhandledRejectionError.d.ts +0 -5
- package/dist/commonjs/lib/error/MessageUnhandledRejectionError.js +0 -16
- package/dist/commonjs/lib/error/index.d.ts +0 -2
- package/dist/commonjs/lib/error/index.js +0 -19
- package/dist/commonjs/lib/loader/AgentWorkerLoader.d.ts +0 -12
- package/dist/commonjs/lib/loader/AgentWorkerLoader.js +0 -24
- package/dist/commonjs/lib/loader/AppWorkerLoader.d.ts +0 -17
- package/dist/commonjs/lib/loader/AppWorkerLoader.js +0 -43
- package/dist/commonjs/lib/loader/EggApplicationLoader.d.ts +0 -4
- package/dist/commonjs/lib/loader/EggApplicationLoader.js +0 -8
- package/dist/commonjs/lib/loader/index.d.ts +0 -3
- package/dist/commonjs/lib/loader/index.js +0 -22
- package/dist/commonjs/lib/start.d.ts +0 -24
- package/dist/commonjs/lib/start.js +0 -49
- package/dist/commonjs/lib/types.d.ts +0 -257
- package/dist/commonjs/lib/types.js +0 -16
- package/dist/commonjs/lib/utils.d.ts +0 -2
- package/dist/commonjs/lib/utils.js +0 -21
- package/dist/commonjs/package.json +0 -3
- package/dist/commonjs/urllib.d.ts +0 -1
- package/dist/commonjs/urllib.js +0 -18
- package/dist/esm/agent.d.ts +0 -4
- package/dist/esm/agent.js +0 -7
- package/dist/esm/app/extend/context.d.ts +0 -204
- package/dist/esm/app/extend/context.js +0 -259
- package/dist/esm/app/extend/helper.d.ts +0 -37
- package/dist/esm/app/extend/helper.js +0 -43
- package/dist/esm/app/extend/request.d.ts +0 -141
- package/dist/esm/app/extend/request.js +0 -264
- package/dist/esm/app/extend/response.d.ts +0 -31
- package/dist/esm/app/extend/response.js +0 -34
- package/dist/esm/app/middleware/body_parser.d.ts +0 -2
- package/dist/esm/app/middleware/body_parser.js +0 -3
- package/dist/esm/app/middleware/meta.d.ts +0 -10
- package/dist/esm/app/middleware/meta.js +0 -20
- package/dist/esm/app/middleware/notfound.d.ts +0 -7
- package/dist/esm/app/middleware/notfound.js +0 -29
- package/dist/esm/app/middleware/override_method.d.ts +0 -2
- package/dist/esm/app/middleware/override_method.js +0 -3
- package/dist/esm/app/middleware/site_file.d.ts +0 -9
- package/dist/esm/app/middleware/site_file.js +0 -53
- package/dist/esm/config/config.default.d.ts +0 -9
- package/dist/esm/config/config.default.js +0 -374
- package/dist/esm/config/config.local.d.ts +0 -8
- package/dist/esm/config/config.local.js +0 -10
- package/dist/esm/config/config.unittest.d.ts +0 -7
- package/dist/esm/config/config.unittest.js +0 -9
- package/dist/esm/config/favicon.png +0 -0
- package/dist/esm/config/plugin.d.ts +0 -122
- package/dist/esm/config/plugin.js +0 -122
- package/dist/esm/index.d.ts +0 -69
- package/dist/esm/index.js +0 -73
- package/dist/esm/lib/agent.d.ts +0 -19
- package/dist/esm/lib/agent.js +0 -54
- package/dist/esm/lib/application.d.ts +0 -67
- package/dist/esm/lib/application.js +0 -259
- package/dist/esm/lib/core/base_context_class.d.ts +0 -17
- package/dist/esm/lib/core/base_context_class.js +0 -17
- package/dist/esm/lib/core/base_context_logger.d.ts +0 -36
- package/dist/esm/lib/core/base_context_logger.js +0 -60
- package/dist/esm/lib/core/base_hook_class.d.ts +0 -11
- package/dist/esm/lib/core/base_hook_class.js +0 -22
- package/dist/esm/lib/core/context_httpclient.d.ts +0 -16
- package/dist/esm/lib/core/context_httpclient.js +0 -26
- package/dist/esm/lib/core/httpclient.d.ts +0 -14
- package/dist/esm/lib/core/httpclient.js +0 -38
- package/dist/esm/lib/core/logger.d.ts +0 -3
- package/dist/esm/lib/core/logger.js +0 -37
- package/dist/esm/lib/core/messenger/IMessenger.d.ts +0 -50
- package/dist/esm/lib/core/messenger/IMessenger.js +0 -2
- package/dist/esm/lib/core/messenger/base.d.ts +0 -8
- package/dist/esm/lib/core/messenger/base.js +0 -27
- package/dist/esm/lib/core/messenger/index.d.ts +0 -7
- package/dist/esm/lib/core/messenger/index.js +0 -12
- package/dist/esm/lib/core/messenger/ipc.d.ts +0 -58
- package/dist/esm/lib/core/messenger/ipc.js +0 -128
- package/dist/esm/lib/core/messenger/local.d.ts +0 -60
- package/dist/esm/lib/core/messenger/local.js +0 -128
- package/dist/esm/lib/core/utils.d.ts +0 -2
- package/dist/esm/lib/core/utils.js +0 -70
- package/dist/esm/lib/egg.d.ts +0 -305
- package/dist/esm/lib/egg.js +0 -586
- package/dist/esm/lib/error/CookieLimitExceedError.d.ts +0 -5
- package/dist/esm/lib/error/CookieLimitExceedError.js +0 -12
- package/dist/esm/lib/error/MessageUnhandledRejectionError.d.ts +0 -5
- package/dist/esm/lib/error/MessageUnhandledRejectionError.js +0 -12
- package/dist/esm/lib/error/index.d.ts +0 -2
- package/dist/esm/lib/error/index.js +0 -3
- package/dist/esm/lib/loader/AgentWorkerLoader.d.ts +0 -12
- package/dist/esm/lib/loader/AgentWorkerLoader.js +0 -20
- package/dist/esm/lib/loader/AppWorkerLoader.d.ts +0 -17
- package/dist/esm/lib/loader/AppWorkerLoader.js +0 -39
- package/dist/esm/lib/loader/EggApplicationLoader.d.ts +0 -4
- package/dist/esm/lib/loader/EggApplicationLoader.js +0 -4
- package/dist/esm/lib/loader/index.d.ts +0 -3
- package/dist/esm/lib/loader/index.js +0 -4
- package/dist/esm/lib/start.d.ts +0 -24
- package/dist/esm/lib/start.js +0 -43
- package/dist/esm/lib/types.d.ts +0 -257
- package/dist/esm/lib/types.js +0 -14
- package/dist/esm/lib/utils.d.ts +0 -2
- package/dist/esm/lib/utils.js +0 -14
- package/dist/esm/package.json +0 -3
- package/dist/esm/urllib.d.ts +0 -1
- package/dist/esm/urllib.js +0 -2
- package/dist/package.json +0 -4
- package/src/agent.ts +0 -7
- package/src/app/extend/context.ts +0 -332
- package/src/app/extend/request.ts +0 -300
- package/src/app/middleware/body_parser.ts +0 -3
- package/src/app/middleware/meta.ts +0 -27
- package/src/app/middleware/notfound.ts +0 -41
- package/src/app/middleware/override_method.ts +0 -3
- package/src/app/middleware/site_file.ts +0 -68
- package/src/config/config.default.ts +0 -404
- package/src/config/config.local.ts +0 -11
- package/src/config/config.unittest.ts +0 -10
- package/src/config/favicon.png +0 -0
- package/src/index.ts +0 -120
- package/src/lib/agent.ts +0 -66
- package/src/lib/application.ts +0 -308
- package/src/lib/core/base_context_class.ts +0 -24
- package/src/lib/core/base_context_logger.ts +0 -67
- package/src/lib/core/base_hook_class.ts +0 -30
- package/src/lib/core/context_httpclient.ts +0 -33
- package/src/lib/core/httpclient.ts +0 -64
- package/src/lib/core/logger.ts +0 -42
- package/src/lib/core/messenger/base.ts +0 -30
- package/src/lib/core/messenger/index.ts +0 -16
- package/src/lib/core/messenger/ipc.ts +0 -146
- package/src/lib/core/messenger/local.ts +0 -147
- package/src/lib/core/utils.ts +0 -77
- package/src/lib/egg.ts +0 -705
- package/src/lib/error/CookieLimitExceedError.ts +0 -12
- package/src/lib/error/MessageUnhandledRejectionError.ts +0 -12
- package/src/lib/error/index.ts +0 -2
- package/src/lib/loader/AgentWorkerLoader.ts +0 -21
- package/src/lib/loader/AppWorkerLoader.ts +0 -42
- package/src/lib/loader/EggApplicationLoader.ts +0 -5
- package/src/lib/loader/index.ts +0 -3
- package/src/lib/start.ts +0 -66
- package/src/lib/utils.ts +0 -15
- package/src/urllib.ts +0 -1
package/src/lib/application.ts
DELETED
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fs from 'node:fs';
|
|
3
|
-
import http from 'node:http';
|
|
4
|
-
import { Socket } from 'node:net';
|
|
5
|
-
import { graceful } from 'graceful';
|
|
6
|
-
import { assign } from 'utility';
|
|
7
|
-
import { utils as eggUtils } from '@eggjs/core';
|
|
8
|
-
import { isGeneratorFunction } from 'is-type-of';
|
|
9
|
-
import {
|
|
10
|
-
EggApplicationCore,
|
|
11
|
-
type EggApplicationCoreOptions,
|
|
12
|
-
type Context,
|
|
13
|
-
} from './egg.js';
|
|
14
|
-
import { AppWorkerLoader } from './loader/index.js';
|
|
15
|
-
import Helper from '../app/extend/helper.js';
|
|
16
|
-
import { CookieLimitExceedError } from './error/index.js';
|
|
17
|
-
|
|
18
|
-
const EGG_LOADER = Symbol.for('egg#loader');
|
|
19
|
-
|
|
20
|
-
// client error => 400 Bad Request
|
|
21
|
-
// Refs: https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_event_clienterror
|
|
22
|
-
const DEFAULT_BAD_REQUEST_HTML = `<html>
|
|
23
|
-
<head><title>400 Bad Request</title></head>
|
|
24
|
-
<body bgcolor="white">
|
|
25
|
-
<center><h1>400 Bad Request</h1></center>
|
|
26
|
-
<hr><center>❤</center>
|
|
27
|
-
</body>
|
|
28
|
-
</html>`;
|
|
29
|
-
const DEFAULT_BAD_REQUEST_HTML_LENGTH = Buffer.byteLength(DEFAULT_BAD_REQUEST_HTML);
|
|
30
|
-
const DEFAULT_BAD_REQUEST_RESPONSE =
|
|
31
|
-
`HTTP/1.1 400 Bad Request\r\nContent-Length: ${DEFAULT_BAD_REQUEST_HTML_LENGTH}` +
|
|
32
|
-
`\r\n\r\n${DEFAULT_BAD_REQUEST_HTML}`;
|
|
33
|
-
|
|
34
|
-
// Refs: https://github.com/nodejs/node/blob/b38c81/lib/_http_outgoing.js#L706-L710
|
|
35
|
-
function escapeHeaderValue(value: string) {
|
|
36
|
-
// Protect against response splitting. The regex test is there to
|
|
37
|
-
// minimize the performance impact in the common case.
|
|
38
|
-
return /[\r\n]/.test(value) ? value.replace(/[\r\n]+[ \t]*/g, '') : value;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Singleton instance in App Worker, extend {@link EggApplicationCore}
|
|
43
|
-
* @augments EggApplicationCore
|
|
44
|
-
*/
|
|
45
|
-
export class Application extends EggApplicationCore {
|
|
46
|
-
// will auto set after 'server' event emit
|
|
47
|
-
server?: http.Server;
|
|
48
|
-
#locals: Record<string, any> = {};
|
|
49
|
-
/**
|
|
50
|
-
* reference to {@link Helper}
|
|
51
|
-
* @member {Helper} Application#Helper
|
|
52
|
-
*/
|
|
53
|
-
Helper = Helper;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @class
|
|
57
|
-
* @param {Object} options - see {@link EggApplicationCore}
|
|
58
|
-
*/
|
|
59
|
-
constructor(options?: Omit<EggApplicationCoreOptions, 'type'>) {
|
|
60
|
-
super({
|
|
61
|
-
...options,
|
|
62
|
-
type: 'application',
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
protected async load() {
|
|
67
|
-
await super.load();
|
|
68
|
-
this.#warnConfusedConfig();
|
|
69
|
-
this.#bindEvents();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
get [EGG_LOADER]() {
|
|
73
|
-
return AppWorkerLoader;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
#responseRaw(socket: Socket, raw?: any) {
|
|
77
|
-
if (!socket?.writable) return;
|
|
78
|
-
if (!raw) {
|
|
79
|
-
return socket.end(DEFAULT_BAD_REQUEST_RESPONSE);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const body = (raw.body == null) ? DEFAULT_BAD_REQUEST_HTML : raw.body;
|
|
83
|
-
const headers = raw.headers || {};
|
|
84
|
-
const status = raw.status || 400;
|
|
85
|
-
|
|
86
|
-
let responseHeaderLines = '';
|
|
87
|
-
const firstLine = `HTTP/1.1 ${status} ${http.STATUS_CODES[status] || 'Unknown'}`;
|
|
88
|
-
|
|
89
|
-
// Not that safe because no validation for header keys.
|
|
90
|
-
// Refs: https://github.com/nodejs/node/blob/b38c81/lib/_http_outgoing.js#L451
|
|
91
|
-
for (const key of Object.keys(headers)) {
|
|
92
|
-
if (key.toLowerCase() === 'content-length') {
|
|
93
|
-
delete headers[key];
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
responseHeaderLines += `${key}: ${escapeHeaderValue(headers[key])}\r\n`;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
responseHeaderLines += `Content-Length: ${Buffer.byteLength(body)}\r\n`;
|
|
100
|
-
|
|
101
|
-
socket.end(`${firstLine}\r\n${responseHeaderLines}\r\n${body.toString()}`);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
onClientError(err: any, socket: Socket) {
|
|
105
|
-
// ignore when there is no http body, it almost like an ECONNRESET
|
|
106
|
-
if (err.rawPacket) {
|
|
107
|
-
this.logger.warn('[egg:application] A client (%s:%d) error [%s] occurred: %s',
|
|
108
|
-
socket.remoteAddress,
|
|
109
|
-
socket.remotePort,
|
|
110
|
-
err.code,
|
|
111
|
-
err.message);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (typeof this.config.onClientError === 'function') {
|
|
115
|
-
const p = eggUtils.callFn(this.config.onClientError, [ err, socket, this ]);
|
|
116
|
-
|
|
117
|
-
// the returned object should be something like:
|
|
118
|
-
//
|
|
119
|
-
// {
|
|
120
|
-
// body: '...',
|
|
121
|
-
// headers: {
|
|
122
|
-
// ...
|
|
123
|
-
// },
|
|
124
|
-
// status: 400
|
|
125
|
-
// }
|
|
126
|
-
//
|
|
127
|
-
// default values:
|
|
128
|
-
//
|
|
129
|
-
// + body: ''
|
|
130
|
-
// + headers: {}
|
|
131
|
-
// + status: 400
|
|
132
|
-
p.then(ret => {
|
|
133
|
-
this.#responseRaw(socket, ret || {});
|
|
134
|
-
}).catch(err => {
|
|
135
|
-
this.logger.error(err);
|
|
136
|
-
this.#responseRaw(socket);
|
|
137
|
-
});
|
|
138
|
-
} else {
|
|
139
|
-
// because it's a raw socket object, we should return the raw HTTP response
|
|
140
|
-
// packet.
|
|
141
|
-
this.#responseRaw(socket);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
onServer(server: http.Server) {
|
|
146
|
-
// expose app.server
|
|
147
|
-
this.server = server;
|
|
148
|
-
// set ignore code
|
|
149
|
-
const serverGracefulIgnoreCode = this.config.serverGracefulIgnoreCode || [];
|
|
150
|
-
|
|
151
|
-
graceful({
|
|
152
|
-
server: [ server ],
|
|
153
|
-
error: (err: Error, throwErrorCount: number) => {
|
|
154
|
-
const originMessage = err.message;
|
|
155
|
-
if (originMessage) {
|
|
156
|
-
// shouldjs will override error property but only getter
|
|
157
|
-
// https://github.com/shouldjs/should.js/blob/889e22ebf19a06bc2747d24cf34b25cc00b37464/lib/assertion-error.js#L26
|
|
158
|
-
Object.defineProperty(err, 'message', {
|
|
159
|
-
get() {
|
|
160
|
-
return `${originMessage} (uncaughtException throw ${throwErrorCount} times on pid: ${process.pid})`;
|
|
161
|
-
},
|
|
162
|
-
configurable: true,
|
|
163
|
-
enumerable: false,
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
this.coreLogger.error(err);
|
|
167
|
-
},
|
|
168
|
-
ignoreCode: serverGracefulIgnoreCode,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
server.on('clientError', (err, socket) => this.onClientError(err, socket as Socket));
|
|
172
|
-
|
|
173
|
-
// server timeout
|
|
174
|
-
if (typeof this.config.serverTimeout === 'number') {
|
|
175
|
-
server.setTimeout(this.config.serverTimeout);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* global locals for view
|
|
181
|
-
* @member {Object} Application#locals
|
|
182
|
-
* @see Context#locals
|
|
183
|
-
*/
|
|
184
|
-
get locals() {
|
|
185
|
-
return this.#locals;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
set locals(val: Record<string, any>) {
|
|
189
|
-
assign(this.#locals, val);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* save routers to `run/router.json`
|
|
194
|
-
* @private
|
|
195
|
-
*/
|
|
196
|
-
dumpConfig() {
|
|
197
|
-
super.dumpConfig();
|
|
198
|
-
|
|
199
|
-
// dump routers to router.json
|
|
200
|
-
const rundir = this.config.rundir;
|
|
201
|
-
const FULLPATH = this.loader.FileLoader.FULLPATH;
|
|
202
|
-
try {
|
|
203
|
-
const dumpRouterFile = path.join(rundir, 'router.json');
|
|
204
|
-
const routers = [];
|
|
205
|
-
for (const layer of this.router.stack) {
|
|
206
|
-
routers.push({
|
|
207
|
-
name: layer.name,
|
|
208
|
-
methods: layer.methods,
|
|
209
|
-
paramNames: layer.paramNames,
|
|
210
|
-
path: layer.path,
|
|
211
|
-
regexp: layer.regexp.toString(),
|
|
212
|
-
stack: layer.stack.map((stack: any) => stack[FULLPATH] || stack._name || stack.name || 'anonymous'),
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
fs.writeFileSync(dumpRouterFile, JSON.stringify(routers, null, 2));
|
|
216
|
-
} catch (err: any) {
|
|
217
|
-
this.coreLogger.warn(`dumpConfig router.json error: ${err.message}`);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Run async function in the background
|
|
223
|
-
* @see Context#runInBackground
|
|
224
|
-
* @param {Function} scope - the first args is an anonymous ctx
|
|
225
|
-
*/
|
|
226
|
-
runInBackground(scope: (ctx: Context) => Promise<void>, req?: unknown) {
|
|
227
|
-
const ctx = this.createAnonymousContext(req);
|
|
228
|
-
if (!scope.name) {
|
|
229
|
-
Reflect.set(scope, '_name', eggUtils.getCalleeFromStack(true));
|
|
230
|
-
}
|
|
231
|
-
this.ctxStorage.run(ctx, () => {
|
|
232
|
-
return ctx.runInBackground(scope);
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* secret key for Application
|
|
238
|
-
* @member {String} Application#keys
|
|
239
|
-
*/
|
|
240
|
-
get keys() {
|
|
241
|
-
if (!this._keys) {
|
|
242
|
-
if (!this.config.keys) {
|
|
243
|
-
if (this.config.env === 'local' || this.config.env === 'unittest') {
|
|
244
|
-
const configPath = path.join(this.config.baseDir, 'config/config.default.js');
|
|
245
|
-
console.error('Cookie need secret key to sign and encrypt.');
|
|
246
|
-
console.error('Please add `config.keys` in %s', configPath);
|
|
247
|
-
}
|
|
248
|
-
throw new Error('Please set config.keys first');
|
|
249
|
-
}
|
|
250
|
-
this._keys = this.config.keys.split(',').map(s => s.trim());
|
|
251
|
-
}
|
|
252
|
-
return this._keys;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* @deprecated keep compatible with egg 3.x
|
|
257
|
-
*/
|
|
258
|
-
toAsyncFunction(fn: (...args: any[]) => any) {
|
|
259
|
-
if (isGeneratorFunction(fn)) {
|
|
260
|
-
throw new Error('Generator function is not supported');
|
|
261
|
-
}
|
|
262
|
-
return fn;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* bind app's events
|
|
267
|
-
*
|
|
268
|
-
* @private
|
|
269
|
-
*/
|
|
270
|
-
#bindEvents() {
|
|
271
|
-
// Browser Cookie Limits: http://browsercookielimits.iain.guru/
|
|
272
|
-
// https://github.com/eggjs/egg-cookies/blob/58ef4ea497a0eb4dd711d7e9751e56bc5fcee004/src/cookies.ts#L145
|
|
273
|
-
this.on('cookieLimitExceed', ({ name, value, ctx }) => {
|
|
274
|
-
const err = new CookieLimitExceedError(name, value);
|
|
275
|
-
ctx.coreLogger.error(err);
|
|
276
|
-
});
|
|
277
|
-
// expose server to support websocket
|
|
278
|
-
this.once('server', (server: http.Server) => this.onServer(server));
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* warn when confused configurations are present
|
|
283
|
-
*
|
|
284
|
-
* @private
|
|
285
|
-
*/
|
|
286
|
-
#warnConfusedConfig() {
|
|
287
|
-
const confusedConfigurations = this.config.confusedConfigurations;
|
|
288
|
-
Object.keys(confusedConfigurations).forEach(key => {
|
|
289
|
-
if (this.config[key] !== undefined) {
|
|
290
|
-
this.logger.warn('[egg:application] Unexpected config key `%o` exists, Please use `%o` instead.',
|
|
291
|
-
key, confusedConfigurations[key]);
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
declare module '@eggjs/core' {
|
|
298
|
-
// add EggApplicationCore overrides types
|
|
299
|
-
interface EggCore {
|
|
300
|
-
onClientError(err: any, socket: Socket): void;
|
|
301
|
-
onServer(server: http.Server): void;
|
|
302
|
-
locals: Record<string, any>;
|
|
303
|
-
runInBackground(scope: (ctx: Context) => Promise<void>, req?: unknown): void;
|
|
304
|
-
toAsyncFunction(fn: (...args: any[]) => any): (...args: any[]) => any;
|
|
305
|
-
dumpConfig(): void;
|
|
306
|
-
get keys(): string[];
|
|
307
|
-
}
|
|
308
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { BaseContextClass as EggCoreBaseContextClass } from '@eggjs/core';
|
|
2
|
-
import type { Context, EggApplicationCore } from '../egg.js';
|
|
3
|
-
import { BaseContextLogger } from './base_context_logger.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* BaseContextClass is a base class that can be extended,
|
|
7
|
-
* it's instantiated in context level,
|
|
8
|
-
* {@link Helper}, {@link Service} is extending it.
|
|
9
|
-
*/
|
|
10
|
-
export class BaseContextClass extends EggCoreBaseContextClass {
|
|
11
|
-
[key: string | symbol]: any;
|
|
12
|
-
declare ctx: Context;
|
|
13
|
-
declare pathName?: string;
|
|
14
|
-
declare app: EggApplicationCore;
|
|
15
|
-
declare service: BaseContextClass;
|
|
16
|
-
#logger?: BaseContextLogger;
|
|
17
|
-
|
|
18
|
-
get logger() {
|
|
19
|
-
if (!this.#logger) {
|
|
20
|
-
this.#logger = new BaseContextLogger(this.ctx, this.pathName);
|
|
21
|
-
}
|
|
22
|
-
return this.#logger;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { EggContext } from '../egg.js';
|
|
2
|
-
|
|
3
|
-
export class BaseContextLogger {
|
|
4
|
-
readonly #ctx: EggContext;
|
|
5
|
-
readonly #pathName?: string;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @class
|
|
9
|
-
* @param {Context} ctx - context instance
|
|
10
|
-
* @param {String} pathName - class path name
|
|
11
|
-
* @since 1.0.0
|
|
12
|
-
*/
|
|
13
|
-
constructor(ctx: EggContext, pathName?: string) {
|
|
14
|
-
/**
|
|
15
|
-
* @member {Context} BaseContextLogger#ctx
|
|
16
|
-
* @since 1.2.0
|
|
17
|
-
*/
|
|
18
|
-
this.#ctx = ctx;
|
|
19
|
-
this.#pathName = pathName;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
protected _log(method: 'info' | 'warn' | 'error' | 'debug', args: any[]) {
|
|
23
|
-
// add `[${pathName}]` in log
|
|
24
|
-
if (this.#pathName && typeof args[0] === 'string') {
|
|
25
|
-
args[0] = `[${this.#pathName}] ${args[0]}`;
|
|
26
|
-
}
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
28
|
-
// @ts-ignore
|
|
29
|
-
this.#ctx.app.logger[method](...args);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @member {Function} BaseContextLogger#debug
|
|
34
|
-
* @param {...any} args - log msg
|
|
35
|
-
* @since 1.2.0
|
|
36
|
-
*/
|
|
37
|
-
debug(...args: any[]) {
|
|
38
|
-
this._log('debug', args);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @member {Function} BaseContextLogger#info
|
|
43
|
-
* @param {...any} args - log msg
|
|
44
|
-
* @since 1.2.0
|
|
45
|
-
*/
|
|
46
|
-
info(...args: any[]) {
|
|
47
|
-
this._log('info', args);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @member {Function} BaseContextLogger#warn
|
|
52
|
-
* @param {...any} args - log msg
|
|
53
|
-
* @since 1.2.0
|
|
54
|
-
*/
|
|
55
|
-
warn(...args: any[]) {
|
|
56
|
-
this._log('warn', args);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @member {Function} BaseContextLogger#error
|
|
61
|
-
* @param {...any} args - log msg
|
|
62
|
-
* @since 1.2.0
|
|
63
|
-
*/
|
|
64
|
-
error(...args: any[]) {
|
|
65
|
-
this._log('error', args);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert';
|
|
2
|
-
import type { ILifecycleBoot } from '@eggjs/core';
|
|
3
|
-
import type { Application, Agent } from '../../index.js';
|
|
4
|
-
|
|
5
|
-
export class BaseHookClass implements ILifecycleBoot {
|
|
6
|
-
declare fullPath?: string;
|
|
7
|
-
#instance: Application | Agent;
|
|
8
|
-
|
|
9
|
-
constructor(instance: Application | Agent) {
|
|
10
|
-
this.#instance = instance;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get logger() {
|
|
14
|
-
return this.#instance.logger;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get config() {
|
|
18
|
-
return this.#instance.config;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
get app() {
|
|
22
|
-
assert(this.#instance.type === 'application', 'agent boot should not use app instance');
|
|
23
|
-
return this.#instance as Application;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get agent() {
|
|
27
|
-
assert(this.#instance.type === 'agent', 'app boot should not use agent instance');
|
|
28
|
-
return this.#instance as Agent;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { Context, EggApplicationCore } from '../egg.js';
|
|
2
|
-
import type {
|
|
3
|
-
HttpClientRequestURL, HttpClientRequestOptions,
|
|
4
|
-
} from './httpclient.js';
|
|
5
|
-
|
|
6
|
-
export class ContextHttpClient {
|
|
7
|
-
ctx: Context;
|
|
8
|
-
app: EggApplicationCore;
|
|
9
|
-
|
|
10
|
-
constructor(ctx: Context) {
|
|
11
|
-
this.ctx = ctx;
|
|
12
|
-
this.app = ctx.app;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* http request helper base on {@link HttpClient}, it will auto save httpclient log.
|
|
17
|
-
* Keep the same api with {@link Application#curl}.
|
|
18
|
-
*
|
|
19
|
-
* @param {String|Object} url - request url address.
|
|
20
|
-
* @param {Object} [options] - options for request.
|
|
21
|
-
*/
|
|
22
|
-
async curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions) {
|
|
23
|
-
options = {
|
|
24
|
-
...options,
|
|
25
|
-
ctx: this.ctx,
|
|
26
|
-
};
|
|
27
|
-
return await this.app.curl<T>(url, options);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async request<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions) {
|
|
31
|
-
return await this.curl<T>(url, options);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HttpClient as RawHttpClient,
|
|
3
|
-
RequestURL as HttpClientRequestURL,
|
|
4
|
-
RequestOptions,
|
|
5
|
-
ClientOptions as HttpClientOptions,
|
|
6
|
-
} from 'urllib';
|
|
7
|
-
import { ms } from 'humanize-ms';
|
|
8
|
-
import type { EggApplicationCore } from '../egg.js';
|
|
9
|
-
|
|
10
|
-
export type {
|
|
11
|
-
HttpClientResponse,
|
|
12
|
-
RequestURL as HttpClientRequestURL,
|
|
13
|
-
ClientOptions as HttpClientOptions,
|
|
14
|
-
} from 'urllib';
|
|
15
|
-
|
|
16
|
-
export interface HttpClientRequestOptions extends RequestOptions {
|
|
17
|
-
ctx?: any;
|
|
18
|
-
tracer?: any;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class HttpClient extends RawHttpClient {
|
|
22
|
-
readonly #app: EggApplicationCore & { tracer?: any };
|
|
23
|
-
|
|
24
|
-
constructor(app: EggApplicationCore, options: HttpClientOptions = {}) {
|
|
25
|
-
normalizeConfig(app);
|
|
26
|
-
const config = app.config.httpclient;
|
|
27
|
-
const initOptions: HttpClientOptions = {
|
|
28
|
-
...options,
|
|
29
|
-
defaultArgs: {
|
|
30
|
-
...config.request,
|
|
31
|
-
...options.defaultArgs,
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
super(initOptions);
|
|
35
|
-
this.#app = app;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async request<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions) {
|
|
39
|
-
options = options ?? {};
|
|
40
|
-
if (options.ctx?.tracer) {
|
|
41
|
-
options.tracer = options.ctx.tracer;
|
|
42
|
-
} else {
|
|
43
|
-
options.tracer = options.tracer ?? this.#app.tracer;
|
|
44
|
-
}
|
|
45
|
-
return await super.request<T>(url, options);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions) {
|
|
49
|
-
return await this.request<T>(url, options);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// keep compatible
|
|
54
|
-
export type {
|
|
55
|
-
HttpClient as EggHttpClient,
|
|
56
|
-
HttpClient as EggContextHttpClient,
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
function normalizeConfig(app: EggApplicationCore) {
|
|
60
|
-
const config = app.config.httpclient;
|
|
61
|
-
if (typeof config.request?.timeout === 'string') {
|
|
62
|
-
config.request.timeout = ms(config.request.timeout);
|
|
63
|
-
}
|
|
64
|
-
}
|
package/src/lib/core/logger.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { EggLoggers, EggLoggersOptions } from 'egg-logger';
|
|
2
|
-
import { setCustomLogger } from 'onelogger';
|
|
3
|
-
import type { EggApplicationCore } from '../egg.js';
|
|
4
|
-
|
|
5
|
-
export function createLoggers(app: EggApplicationCore) {
|
|
6
|
-
const loggerOptions = {
|
|
7
|
-
...app.config.logger,
|
|
8
|
-
type: app.type,
|
|
9
|
-
localStorage: app.ctxStorage,
|
|
10
|
-
} as EggLoggersOptions;
|
|
11
|
-
|
|
12
|
-
// set DEBUG level into INFO on prod env
|
|
13
|
-
if (app.config.env === 'prod' && loggerOptions.level === 'DEBUG' && !app.config.logger.allowDebugAtProd) {
|
|
14
|
-
loggerOptions.level = 'INFO';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const loggers = new EggLoggers({
|
|
18
|
-
logger: loggerOptions,
|
|
19
|
-
customLogger: app.config.customLogger,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// won't print to console after started, except for local and unittest
|
|
23
|
-
app.ready(() => {
|
|
24
|
-
if (app.config.logger.disableConsoleAfterReady) {
|
|
25
|
-
loggers.disableConsole();
|
|
26
|
-
loggers.coreLogger.info('[egg:lib:core:logger] disable console log after app ready');
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// set global logger
|
|
31
|
-
for (const loggerName of Object.keys(loggers)) {
|
|
32
|
-
setCustomLogger(loggerName, loggers[loggerName]);
|
|
33
|
-
}
|
|
34
|
-
// reset global logger on beforeClose hook
|
|
35
|
-
app.lifecycle.registerBeforeClose(() => {
|
|
36
|
-
for (const loggerName of Object.keys(loggers)) {
|
|
37
|
-
setCustomLogger(loggerName, undefined);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
loggers.coreLogger.info('[egg:lib:core:logger] init all loggers with options: %j', loggerOptions);
|
|
41
|
-
return loggers;
|
|
42
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { EventEmitter, captureRejectionSymbol } from 'node:events';
|
|
2
|
-
import { MessageUnhandledRejectionError } from '../../error/index.js';
|
|
3
|
-
import { EggApplicationCore } from '../../egg.js';
|
|
4
|
-
|
|
5
|
-
export class BaseMessenger extends EventEmitter {
|
|
6
|
-
protected readonly egg: EggApplicationCore;
|
|
7
|
-
|
|
8
|
-
constructor(egg: EggApplicationCore) {
|
|
9
|
-
super({ captureRejections: true });
|
|
10
|
-
this.egg = egg;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
[captureRejectionSymbol](err: Error, event: string | symbol, ...args: any[]) {
|
|
14
|
-
this.egg.coreLogger.error(new MessageUnhandledRejectionError(err, event, args));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
emit(eventName: string | symbol, ...args: any[]): boolean {
|
|
18
|
-
const hasListeners = this.listenerCount(eventName) > 0;
|
|
19
|
-
try {
|
|
20
|
-
return super.emit(eventName, ...args);
|
|
21
|
-
} catch (e: unknown) {
|
|
22
|
-
let err = e as Error;
|
|
23
|
-
if (!(err instanceof Error)) {
|
|
24
|
-
err = new Error(String(err));
|
|
25
|
-
}
|
|
26
|
-
this.egg.coreLogger.error(new MessageUnhandledRejectionError(err, eventName, args));
|
|
27
|
-
return hasListeners;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Messenger as LocalMessenger } from './local.js';
|
|
2
|
-
import { Messenger as IPCMessenger } from './ipc.js';
|
|
3
|
-
import type { IMessenger } from './IMessenger.js';
|
|
4
|
-
import type { EggApplicationCore } from '../../egg.js';
|
|
5
|
-
|
|
6
|
-
export type { IMessenger } from './IMessenger.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @class Messenger
|
|
10
|
-
*/
|
|
11
|
-
export function create(egg: EggApplicationCore): IMessenger {
|
|
12
|
-
const messenger = egg.options.mode === 'single'
|
|
13
|
-
? new LocalMessenger(egg)
|
|
14
|
-
: new IPCMessenger(egg);
|
|
15
|
-
return messenger;
|
|
16
|
-
}
|