egg 4.0.10 → 4.1.0-beta.10
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 +12 -0
- package/dist/config/config.default.js +260 -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} +41 -49
- 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 +22 -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} +73 -94
- package/dist/lib/types.js +36 -0
- package/dist/lib/utils.d.ts +5 -0
- package/dist/lib/utils.js +14 -0
- package/dist/urllib.d.ts +1 -0
- package/dist/urllib.js +3 -0
- package/package.json +81 -99
- 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/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/dist/{commonjs/config → config}/favicon.png +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { AppWorkerLoader } from "./loader/AppWorkerLoader.js";
|
|
2
|
+
import Helper from "../app/extend/helper.js";
|
|
3
|
+
import Context from "../app/extend/context.js";
|
|
4
|
+
import { EggApplicationCore, EggApplicationCoreOptions } from "./egg.js";
|
|
5
|
+
import http from "node:http";
|
|
6
|
+
import { Socket } from "node:net";
|
|
7
|
+
|
|
8
|
+
//#region src/lib/application.d.ts
|
|
9
|
+
declare const EGG_LOADER: unique symbol;
|
|
10
|
+
/**
|
|
11
|
+
* Singleton instance in App Worker, extend {@link EggApplicationCore}
|
|
12
|
+
* @augments EggApplicationCore
|
|
13
|
+
*/
|
|
14
|
+
declare class Application extends EggApplicationCore {
|
|
15
|
+
#private;
|
|
16
|
+
server?: http.Server;
|
|
17
|
+
/**
|
|
18
|
+
* reference to {@link Helper}
|
|
19
|
+
* @member {Helper} Application#Helper
|
|
20
|
+
*/
|
|
21
|
+
Helper: typeof Helper;
|
|
22
|
+
/**
|
|
23
|
+
* @class
|
|
24
|
+
* @param {Object} options - see {@link EggApplicationCore}
|
|
25
|
+
*/
|
|
26
|
+
constructor(options?: Omit<EggApplicationCoreOptions, 'type'>);
|
|
27
|
+
protected load(): Promise<void>;
|
|
28
|
+
get [EGG_LOADER](): typeof AppWorkerLoader;
|
|
29
|
+
onClientError(err: any, socket: Socket): void;
|
|
30
|
+
onServer(server: http.Server): void;
|
|
31
|
+
/**
|
|
32
|
+
* global locals for view
|
|
33
|
+
* @member {Object} Application#locals
|
|
34
|
+
* @see Context#locals
|
|
35
|
+
*/
|
|
36
|
+
get locals(): Record<string, any>;
|
|
37
|
+
set locals(val: Record<string, any>);
|
|
38
|
+
/**
|
|
39
|
+
* save routers to `run/router.json`
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
dumpConfig(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Run async function in the background
|
|
45
|
+
* @see Context#runInBackground
|
|
46
|
+
* @param {Function} scope - the first args is an anonymous ctx
|
|
47
|
+
*/
|
|
48
|
+
runInBackground(scope: (ctx: Context) => Promise<void>, req?: unknown): void;
|
|
49
|
+
/**
|
|
50
|
+
* secret key for Application
|
|
51
|
+
* @member {String} Application#keys
|
|
52
|
+
*/
|
|
53
|
+
get keys(): string[];
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated keep compatible with egg 3.x
|
|
56
|
+
*/
|
|
57
|
+
toAsyncFunction(fn: (...args: any[]) => any): (...args: any[]) => any;
|
|
58
|
+
}
|
|
59
|
+
declare module '@eggjs/core' {
|
|
60
|
+
interface EggCore {
|
|
61
|
+
onClientError(err: any, socket: Socket): void;
|
|
62
|
+
onServer(server: http.Server): void;
|
|
63
|
+
locals: Record<string, any>;
|
|
64
|
+
runInBackground(scope: (ctx: Context) => Promise<void>, req?: unknown): void;
|
|
65
|
+
toAsyncFunction(fn: (...args: any[]) => any): (...args: any[]) => any;
|
|
66
|
+
dumpConfig(): void;
|
|
67
|
+
get keys(): string[];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { Application };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { CookieLimitExceedError } from "./error/CookieLimitExceedError.js";
|
|
2
|
+
import { EggApplicationCore } from "./egg.js";
|
|
3
|
+
import { AppWorkerLoader } from "./loader/AppWorkerLoader.js";
|
|
4
|
+
import "./loader/index.js";
|
|
5
|
+
import Helper from "../app/extend/helper.js";
|
|
6
|
+
import { utils } from "@eggjs/core";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { assign } from "utility";
|
|
9
|
+
import fs from "node:fs";
|
|
10
|
+
import http from "node:http";
|
|
11
|
+
import { isGeneratorFunction } from "is-type-of";
|
|
12
|
+
import { Socket } from "node:net";
|
|
13
|
+
import { graceful } from "graceful";
|
|
14
|
+
|
|
15
|
+
//#region src/lib/application.ts
|
|
16
|
+
const EGG_LOADER = Symbol.for("egg#loader");
|
|
17
|
+
const DEFAULT_BAD_REQUEST_HTML = `<html>
|
|
18
|
+
<head><title>400 Bad Request</title></head>
|
|
19
|
+
<body bgcolor="white">
|
|
20
|
+
<center><h1>400 Bad Request</h1></center>
|
|
21
|
+
<hr><center>❤</center>
|
|
22
|
+
</body>
|
|
23
|
+
</html>`;
|
|
24
|
+
const DEFAULT_BAD_REQUEST_RESPONSE = `HTTP/1.1 400 Bad Request\r\nContent-Length: ${Buffer.byteLength(DEFAULT_BAD_REQUEST_HTML)}\r\n\r\n${DEFAULT_BAD_REQUEST_HTML}`;
|
|
25
|
+
function escapeHeaderValue(value) {
|
|
26
|
+
return /[\r\n]/.test(value) ? value.replace(/[\r\n]+[ \t]*/g, "") : value;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Singleton instance in App Worker, extend {@link EggApplicationCore}
|
|
30
|
+
* @augments EggApplicationCore
|
|
31
|
+
*/
|
|
32
|
+
var Application = class extends EggApplicationCore {
|
|
33
|
+
server;
|
|
34
|
+
#locals = {};
|
|
35
|
+
/**
|
|
36
|
+
* reference to {@link Helper}
|
|
37
|
+
* @member {Helper} Application#Helper
|
|
38
|
+
*/
|
|
39
|
+
Helper = Helper;
|
|
40
|
+
/**
|
|
41
|
+
* @class
|
|
42
|
+
* @param {Object} options - see {@link EggApplicationCore}
|
|
43
|
+
*/
|
|
44
|
+
constructor(options) {
|
|
45
|
+
super({
|
|
46
|
+
...options,
|
|
47
|
+
type: "application"
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async load() {
|
|
51
|
+
await super.load();
|
|
52
|
+
this.#warnConfusedConfig();
|
|
53
|
+
this.#bindEvents();
|
|
54
|
+
}
|
|
55
|
+
get [EGG_LOADER]() {
|
|
56
|
+
return AppWorkerLoader;
|
|
57
|
+
}
|
|
58
|
+
#responseRaw(socket, raw) {
|
|
59
|
+
if (!socket?.writable) return;
|
|
60
|
+
if (!raw) return socket.end(DEFAULT_BAD_REQUEST_RESPONSE);
|
|
61
|
+
const body = raw.body == null ? DEFAULT_BAD_REQUEST_HTML : raw.body;
|
|
62
|
+
const headers = raw.headers || {};
|
|
63
|
+
const status = raw.status || 400;
|
|
64
|
+
let responseHeaderLines = "";
|
|
65
|
+
const firstLine = `HTTP/1.1 ${status} ${http.STATUS_CODES[status] || "Unknown"}`;
|
|
66
|
+
for (const key of Object.keys(headers)) {
|
|
67
|
+
if (key.toLowerCase() === "content-length") {
|
|
68
|
+
delete headers[key];
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
responseHeaderLines += `${key}: ${escapeHeaderValue(headers[key])}\r\n`;
|
|
72
|
+
}
|
|
73
|
+
responseHeaderLines += `Content-Length: ${Buffer.byteLength(body)}\r\n`;
|
|
74
|
+
socket.end(`${firstLine}\r\n${responseHeaderLines}\r\n${body.toString()}`);
|
|
75
|
+
}
|
|
76
|
+
onClientError(err, socket) {
|
|
77
|
+
if (err.rawPacket) this.logger.warn("[egg:application] A client (%s:%d) error [%s] occurred: %s", socket.remoteAddress, socket.remotePort, err.code, err.message);
|
|
78
|
+
if (typeof this.config.onClientError === "function") utils.callFn(this.config.onClientError, [
|
|
79
|
+
err,
|
|
80
|
+
socket,
|
|
81
|
+
this
|
|
82
|
+
]).then((ret) => {
|
|
83
|
+
this.#responseRaw(socket, ret || {});
|
|
84
|
+
}).catch((err$1) => {
|
|
85
|
+
this.logger.error(err$1);
|
|
86
|
+
this.#responseRaw(socket);
|
|
87
|
+
});
|
|
88
|
+
else this.#responseRaw(socket);
|
|
89
|
+
}
|
|
90
|
+
onServer(server) {
|
|
91
|
+
this.server = server;
|
|
92
|
+
const serverGracefulIgnoreCode = this.config.serverGracefulIgnoreCode || [];
|
|
93
|
+
graceful({
|
|
94
|
+
server: [server],
|
|
95
|
+
error: (err, throwErrorCount) => {
|
|
96
|
+
const originMessage = err.message;
|
|
97
|
+
if (originMessage) Object.defineProperty(err, "message", {
|
|
98
|
+
get() {
|
|
99
|
+
return `${originMessage} (uncaughtException throw ${throwErrorCount} times on pid: ${process.pid})`;
|
|
100
|
+
},
|
|
101
|
+
configurable: true,
|
|
102
|
+
enumerable: false
|
|
103
|
+
});
|
|
104
|
+
this.coreLogger.error(err);
|
|
105
|
+
},
|
|
106
|
+
ignoreCode: serverGracefulIgnoreCode
|
|
107
|
+
});
|
|
108
|
+
server.on("clientError", (err, socket) => this.onClientError(err, socket));
|
|
109
|
+
if (typeof this.config.serverTimeout === "number") server.setTimeout(this.config.serverTimeout);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* global locals for view
|
|
113
|
+
* @member {Object} Application#locals
|
|
114
|
+
* @see Context#locals
|
|
115
|
+
*/
|
|
116
|
+
get locals() {
|
|
117
|
+
return this.#locals;
|
|
118
|
+
}
|
|
119
|
+
set locals(val) {
|
|
120
|
+
assign(this.#locals, val);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* save routers to `run/router.json`
|
|
124
|
+
* @private
|
|
125
|
+
*/
|
|
126
|
+
dumpConfig() {
|
|
127
|
+
super.dumpConfig();
|
|
128
|
+
const rundir = this.config.rundir;
|
|
129
|
+
const FULLPATH = this.loader.FileLoader.FULLPATH;
|
|
130
|
+
try {
|
|
131
|
+
const dumpRouterFile = path.join(rundir, "router.json");
|
|
132
|
+
const routers = [];
|
|
133
|
+
for (const layer of this.router.stack) routers.push({
|
|
134
|
+
name: layer.name,
|
|
135
|
+
methods: layer.methods,
|
|
136
|
+
paramNames: layer.paramNames,
|
|
137
|
+
path: layer.path,
|
|
138
|
+
regexp: layer.regexp.toString(),
|
|
139
|
+
stack: layer.stack.map((stack) => stack[FULLPATH] || stack._name || stack.name || "anonymous")
|
|
140
|
+
});
|
|
141
|
+
fs.writeFileSync(dumpRouterFile, JSON.stringify(routers, null, 2));
|
|
142
|
+
} catch (err) {
|
|
143
|
+
this.coreLogger.warn(`dumpConfig router.json error: ${err.message}`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Run async function in the background
|
|
148
|
+
* @see Context#runInBackground
|
|
149
|
+
* @param {Function} scope - the first args is an anonymous ctx
|
|
150
|
+
*/
|
|
151
|
+
runInBackground(scope, req) {
|
|
152
|
+
const ctx = this.createAnonymousContext(req);
|
|
153
|
+
if (!scope.name) Reflect.set(scope, "_name", utils.getCalleeFromStack(true));
|
|
154
|
+
this.ctxStorage.run(ctx, () => {
|
|
155
|
+
return ctx.runInBackground(scope);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* secret key for Application
|
|
160
|
+
* @member {String} Application#keys
|
|
161
|
+
*/
|
|
162
|
+
get keys() {
|
|
163
|
+
if (!this._keys) {
|
|
164
|
+
if (!this.config.keys) {
|
|
165
|
+
if (this.config.env === "local" || this.config.env === "unittest") {
|
|
166
|
+
const configPath = path.join(this.config.baseDir, "config/config.default.js");
|
|
167
|
+
console.error("Cookie need secret key to sign and encrypt.");
|
|
168
|
+
console.error("Please add `config.keys` in %s", configPath);
|
|
169
|
+
}
|
|
170
|
+
throw new Error("Please set config.keys first");
|
|
171
|
+
}
|
|
172
|
+
this._keys = this.config.keys.split(",").map((s) => s.trim());
|
|
173
|
+
}
|
|
174
|
+
return this._keys;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* @deprecated keep compatible with egg 3.x
|
|
178
|
+
*/
|
|
179
|
+
toAsyncFunction(fn) {
|
|
180
|
+
if (isGeneratorFunction(fn)) throw new Error("Generator function is not supported");
|
|
181
|
+
return fn;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* bind app's events
|
|
185
|
+
*
|
|
186
|
+
* @private
|
|
187
|
+
*/
|
|
188
|
+
#bindEvents() {
|
|
189
|
+
this.on("cookieLimitExceed", ({ name, value, ctx }) => {
|
|
190
|
+
const err = new CookieLimitExceedError(name, value);
|
|
191
|
+
ctx.coreLogger.error(err);
|
|
192
|
+
});
|
|
193
|
+
this.once("server", (server) => this.onServer(server));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* warn when confused configurations are present
|
|
197
|
+
*
|
|
198
|
+
* @private
|
|
199
|
+
*/
|
|
200
|
+
#warnConfusedConfig() {
|
|
201
|
+
const confusedConfigurations = this.config.confusedConfigurations;
|
|
202
|
+
Object.keys(confusedConfigurations).forEach((key) => {
|
|
203
|
+
if (this.config[key] !== void 0) this.logger.warn("[egg:application] Unexpected config key `%o` exists, Please use `%o` instead.", key, confusedConfigurations[key]);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
//#endregion
|
|
209
|
+
export { Application };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Context$1 from "../../app/extend/context.js";
|
|
2
|
+
import { EggApplicationCore } from "../egg.js";
|
|
3
|
+
import { BaseContextLogger } from "./base_context_logger.js";
|
|
4
|
+
import { BaseContextClass as BaseContextClass$1 } from "@eggjs/core";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/core/base_context_class.d.ts
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* BaseContextClass is a base class that can be extended,
|
|
10
|
+
* it's instantiated in context level,
|
|
11
|
+
* {@link Helper}, {@link Service} is extending it.
|
|
12
|
+
*/
|
|
13
|
+
declare class BaseContextClass extends BaseContextClass$1 {
|
|
14
|
+
#private;
|
|
15
|
+
[key: string | symbol]: any;
|
|
16
|
+
ctx: Context$1;
|
|
17
|
+
pathName?: string;
|
|
18
|
+
app: EggApplicationCore;
|
|
19
|
+
service: BaseContextClass;
|
|
20
|
+
get logger(): BaseContextLogger;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { BaseContextClass };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BaseContextLogger } from "./base_context_logger.js";
|
|
2
|
+
import { BaseContextClass as BaseContextClass$1 } from "@eggjs/core";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/core/base_context_class.ts
|
|
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
|
+
var BaseContextClass = class extends BaseContextClass$1 {
|
|
11
|
+
#logger;
|
|
12
|
+
get logger() {
|
|
13
|
+
if (!this.#logger) this.#logger = new BaseContextLogger(this.ctx, this.pathName);
|
|
14
|
+
return this.#logger;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { BaseContextClass };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { EggContext } from "../egg.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/core/base_context_logger.d.ts
|
|
4
|
+
declare class BaseContextLogger {
|
|
5
|
+
#private;
|
|
6
|
+
/**
|
|
7
|
+
* @class
|
|
8
|
+
* @param {Context} ctx - context instance
|
|
9
|
+
* @param {String} pathName - class path name
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
constructor(ctx: EggContext, pathName?: string);
|
|
13
|
+
protected _log(method: 'info' | 'warn' | 'error' | 'debug', args: any[]): void;
|
|
14
|
+
/**
|
|
15
|
+
* @member {Function} BaseContextLogger#debug
|
|
16
|
+
* @param {...any} args - log msg
|
|
17
|
+
* @since 1.2.0
|
|
18
|
+
*/
|
|
19
|
+
debug(...args: any[]): void;
|
|
20
|
+
/**
|
|
21
|
+
* @member {Function} BaseContextLogger#info
|
|
22
|
+
* @param {...any} args - log msg
|
|
23
|
+
* @since 1.2.0
|
|
24
|
+
*/
|
|
25
|
+
info(...args: any[]): void;
|
|
26
|
+
/**
|
|
27
|
+
* @member {Function} BaseContextLogger#warn
|
|
28
|
+
* @param {...any} args - log msg
|
|
29
|
+
* @since 1.2.0
|
|
30
|
+
*/
|
|
31
|
+
warn(...args: any[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* @member {Function} BaseContextLogger#error
|
|
34
|
+
* @param {...any} args - log msg
|
|
35
|
+
* @since 1.2.0
|
|
36
|
+
*/
|
|
37
|
+
error(...args: any[]): void;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { BaseContextLogger };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//#region src/lib/core/base_context_logger.ts
|
|
2
|
+
var BaseContextLogger = class {
|
|
3
|
+
#ctx;
|
|
4
|
+
#pathName;
|
|
5
|
+
/**
|
|
6
|
+
* @class
|
|
7
|
+
* @param {Context} ctx - context instance
|
|
8
|
+
* @param {String} pathName - class path name
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
constructor(ctx, pathName) {
|
|
12
|
+
/**
|
|
13
|
+
* @member {Context} BaseContextLogger#ctx
|
|
14
|
+
* @since 1.2.0
|
|
15
|
+
*/
|
|
16
|
+
this.#ctx = ctx;
|
|
17
|
+
this.#pathName = pathName;
|
|
18
|
+
}
|
|
19
|
+
_log(method, args) {
|
|
20
|
+
if (this.#pathName && typeof args[0] === "string") args[0] = `[${this.#pathName}] ${args[0]}`;
|
|
21
|
+
this.#ctx.app.logger[method](...args);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @member {Function} BaseContextLogger#debug
|
|
25
|
+
* @param {...any} args - log msg
|
|
26
|
+
* @since 1.2.0
|
|
27
|
+
*/
|
|
28
|
+
debug(...args) {
|
|
29
|
+
this._log("debug", args);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @member {Function} BaseContextLogger#info
|
|
33
|
+
* @param {...any} args - log msg
|
|
34
|
+
* @since 1.2.0
|
|
35
|
+
*/
|
|
36
|
+
info(...args) {
|
|
37
|
+
this._log("info", args);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @member {Function} BaseContextLogger#warn
|
|
41
|
+
* @param {...any} args - log msg
|
|
42
|
+
* @since 1.2.0
|
|
43
|
+
*/
|
|
44
|
+
warn(...args) {
|
|
45
|
+
this._log("warn", args);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @member {Function} BaseContextLogger#error
|
|
49
|
+
* @param {...any} args - log msg
|
|
50
|
+
* @since 1.2.0
|
|
51
|
+
*/
|
|
52
|
+
error(...args) {
|
|
53
|
+
this._log("error", args);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { BaseContextLogger };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Agent } from "../agent.js";
|
|
2
|
+
import { Application } from "../application.js";
|
|
3
|
+
import { EggAppConfig as EggAppConfig$1 } from "../types.js";
|
|
4
|
+
import { ILifecycleBoot } from "@eggjs/core";
|
|
5
|
+
import * as egg_logger0 from "egg-logger";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/core/base_hook_class.d.ts
|
|
8
|
+
declare class BaseHookClass implements ILifecycleBoot {
|
|
9
|
+
#private;
|
|
10
|
+
fullPath?: string;
|
|
11
|
+
constructor(instance: Application | Agent);
|
|
12
|
+
get logger(): egg_logger0.EggLogger;
|
|
13
|
+
get config(): EggAppConfig$1;
|
|
14
|
+
get app(): Application;
|
|
15
|
+
get agent(): Agent;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { BaseHookClass };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/core/base_hook_class.ts
|
|
4
|
+
var BaseHookClass = class {
|
|
5
|
+
#instance;
|
|
6
|
+
constructor(instance) {
|
|
7
|
+
this.#instance = instance;
|
|
8
|
+
}
|
|
9
|
+
get logger() {
|
|
10
|
+
return this.#instance.logger;
|
|
11
|
+
}
|
|
12
|
+
get config() {
|
|
13
|
+
return this.#instance.config;
|
|
14
|
+
}
|
|
15
|
+
get app() {
|
|
16
|
+
assert(this.#instance.type === "application", "agent boot should not use app instance");
|
|
17
|
+
return this.#instance;
|
|
18
|
+
}
|
|
19
|
+
get agent() {
|
|
20
|
+
assert(this.#instance.type === "agent", "app boot should not use agent instance");
|
|
21
|
+
return this.#instance;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { BaseHookClass };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { HttpClientRequestOptions, HttpClientRequestURL } from "./httpclient.js";
|
|
2
|
+
import Context from "../../app/extend/context.js";
|
|
3
|
+
import { EggApplicationCore } from "../egg.js";
|
|
4
|
+
import * as node_modules_urllib_dist_esm_Response_js0 from "node_modules/urllib/dist/esm/Response.js";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/core/context_httpclient.d.ts
|
|
7
|
+
declare class ContextHttpClient {
|
|
8
|
+
ctx: Context;
|
|
9
|
+
app: EggApplicationCore;
|
|
10
|
+
constructor(ctx: Context);
|
|
11
|
+
/**
|
|
12
|
+
* http request helper base on {@link HttpClient}, it will auto save httpclient log.
|
|
13
|
+
* Keep the same api with {@link Application#curl}.
|
|
14
|
+
*
|
|
15
|
+
* @param {String|Object} url - request url address.
|
|
16
|
+
* @param {Object} [options] - options for request.
|
|
17
|
+
*/
|
|
18
|
+
curl<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<node_modules_urllib_dist_esm_Response_js0.HttpClientResponse<T>>;
|
|
19
|
+
request<T = any>(url: HttpClientRequestURL, options?: HttpClientRequestOptions): Promise<node_modules_urllib_dist_esm_Response_js0.HttpClientResponse<T>>;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { ContextHttpClient };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/lib/core/context_httpclient.ts
|
|
2
|
+
var ContextHttpClient = class {
|
|
3
|
+
ctx;
|
|
4
|
+
app;
|
|
5
|
+
constructor(ctx) {
|
|
6
|
+
this.ctx = ctx;
|
|
7
|
+
this.app = ctx.app;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* http request helper base on {@link HttpClient}, it will auto save httpclient log.
|
|
11
|
+
* Keep the same api with {@link Application#curl}.
|
|
12
|
+
*
|
|
13
|
+
* @param {String|Object} url - request url address.
|
|
14
|
+
* @param {Object} [options] - options for request.
|
|
15
|
+
*/
|
|
16
|
+
async curl(url, options) {
|
|
17
|
+
options = {
|
|
18
|
+
...options,
|
|
19
|
+
ctx: this.ctx
|
|
20
|
+
};
|
|
21
|
+
return await this.app.curl(url, options);
|
|
22
|
+
}
|
|
23
|
+
async request(url, options) {
|
|
24
|
+
return await this.curl(url, options);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
export { ContextHttpClient };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EggApplicationCore } from "../egg.js";
|
|
2
|
+
import * as urllib0 from "urllib";
|
|
3
|
+
import { ClientOptions, ClientOptions as HttpClientOptions, HttpClient as HttpClient$1, HttpClientResponse, RequestOptions, RequestURL, RequestURL as HttpClientRequestURL } from "urllib";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/core/httpclient.d.ts
|
|
6
|
+
interface HttpClientRequestOptions extends RequestOptions {
|
|
7
|
+
ctx?: any;
|
|
8
|
+
tracer?: any;
|
|
9
|
+
}
|
|
10
|
+
declare class HttpClient extends HttpClient$1 {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(app: EggApplicationCore, options?: ClientOptions);
|
|
13
|
+
request<T = any>(url: RequestURL, options?: HttpClientRequestOptions): Promise<urllib0.HttpClientResponse<T>>;
|
|
14
|
+
curl<T = any>(url: RequestURL, options?: HttpClientRequestOptions): Promise<urllib0.HttpClientResponse<T>>;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { type HttpClient as EggContextHttpClient, type HttpClient as EggHttpClient, HttpClient, type HttpClientOptions, HttpClientRequestOptions, type HttpClientRequestURL, type HttpClientResponse };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { HttpClient as HttpClient$1 } from "urllib";
|
|
2
|
+
import { ms } from "humanize-ms";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/core/httpclient.ts
|
|
5
|
+
var HttpClient = class extends HttpClient$1 {
|
|
6
|
+
#app;
|
|
7
|
+
constructor(app, options = {}) {
|
|
8
|
+
normalizeConfig(app);
|
|
9
|
+
const config = app.config.httpclient;
|
|
10
|
+
const initOptions = {
|
|
11
|
+
...options,
|
|
12
|
+
defaultArgs: {
|
|
13
|
+
...config.request,
|
|
14
|
+
...options.defaultArgs
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
super(initOptions);
|
|
18
|
+
this.#app = app;
|
|
19
|
+
}
|
|
20
|
+
async request(url, options) {
|
|
21
|
+
options = options ?? {};
|
|
22
|
+
if (options.ctx?.tracer) options.tracer = options.ctx.tracer;
|
|
23
|
+
else options.tracer = options.tracer ?? this.#app.tracer;
|
|
24
|
+
return await super.request(url, options);
|
|
25
|
+
}
|
|
26
|
+
async curl(url, options) {
|
|
27
|
+
return await this.request(url, options);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function normalizeConfig(app) {
|
|
31
|
+
const config = app.config.httpclient;
|
|
32
|
+
if (typeof config.request?.timeout === "string") config.request.timeout = ms(config.request.timeout);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { HttpClient };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EggLoggers } from "egg-logger";
|
|
2
|
+
import { setCustomLogger } from "onelogger";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/core/logger.ts
|
|
5
|
+
function createLoggers(app) {
|
|
6
|
+
const loggerOptions = {
|
|
7
|
+
...app.config.logger,
|
|
8
|
+
type: app.type,
|
|
9
|
+
localStorage: app.ctxStorage
|
|
10
|
+
};
|
|
11
|
+
if (app.config.env === "prod" && loggerOptions.level === "DEBUG" && !app.config.logger.allowDebugAtProd) loggerOptions.level = "INFO";
|
|
12
|
+
const loggers = new EggLoggers({
|
|
13
|
+
logger: loggerOptions,
|
|
14
|
+
customLogger: app.config.customLogger
|
|
15
|
+
});
|
|
16
|
+
app.ready(() => {
|
|
17
|
+
if (app.config.logger.disableConsoleAfterReady) {
|
|
18
|
+
loggers.disableConsole();
|
|
19
|
+
loggers.coreLogger.info("[egg:lib:core:logger] disable console log after app ready");
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
for (const loggerName of Object.keys(loggers)) setCustomLogger(loggerName, loggers[loggerName]);
|
|
23
|
+
app.lifecycle.registerBeforeClose(() => {
|
|
24
|
+
for (const loggerName of Object.keys(loggers)) setCustomLogger(loggerName, void 0);
|
|
25
|
+
});
|
|
26
|
+
loggers.coreLogger.info("[egg:lib:core:logger] init all loggers with options: %j", loggerOptions);
|
|
27
|
+
return loggers;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { createLoggers };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { EventEmitter } from "node:events";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/lib/core/messenger/IMessenger.d.ts
|
|
4
|
+
interface IMessenger extends EventEmitter {
|
|
4
5
|
/**
|
|
5
6
|
* Send message to all agent and app
|
|
6
7
|
* @param {String} action - message key
|
|
@@ -8,7 +9,6 @@ export interface IMessenger extends EventEmitter {
|
|
|
8
9
|
* @return {Messenger} this
|
|
9
10
|
*/
|
|
10
11
|
broadcast(action: string, data?: unknown): IMessenger;
|
|
11
|
-
|
|
12
12
|
/**
|
|
13
13
|
* send message to the specified process
|
|
14
14
|
* @param {String} workerId - the workerId of the receiver
|
|
@@ -17,7 +17,6 @@ export interface IMessenger extends EventEmitter {
|
|
|
17
17
|
* @return {Messenger} this
|
|
18
18
|
*/
|
|
19
19
|
sendTo(workerId: string, action: string, data?: unknown): IMessenger;
|
|
20
|
-
|
|
21
20
|
/**
|
|
22
21
|
* send message to one app worker by random
|
|
23
22
|
* - if it's running in agent, it will send to one of app workers
|
|
@@ -27,7 +26,6 @@ export interface IMessenger extends EventEmitter {
|
|
|
27
26
|
* @return {Messenger} this
|
|
28
27
|
*/
|
|
29
28
|
sendRandom(action: string, data?: unknown): IMessenger;
|
|
30
|
-
|
|
31
29
|
/**
|
|
32
30
|
* send message to app
|
|
33
31
|
* @param {String} action - message key
|
|
@@ -35,7 +33,6 @@ export interface IMessenger extends EventEmitter {
|
|
|
35
33
|
* @return {Messenger} this
|
|
36
34
|
*/
|
|
37
35
|
sendToApp(action: string, data?: unknown): IMessenger;
|
|
38
|
-
|
|
39
36
|
/**
|
|
40
37
|
* send message to agent
|
|
41
38
|
* @param {String} action - message key
|
|
@@ -43,16 +40,15 @@ export interface IMessenger extends EventEmitter {
|
|
|
43
40
|
* @return {Messenger} this
|
|
44
41
|
*/
|
|
45
42
|
sendToAgent(action: string, data?: unknown): IMessenger;
|
|
46
|
-
|
|
47
43
|
/**
|
|
48
44
|
* @param {String} action - message key
|
|
49
45
|
* @param {Object} data - message value
|
|
50
46
|
* @param {String} to - let master know how to send message
|
|
51
47
|
* @return {Messenger} this
|
|
52
48
|
*/
|
|
53
|
-
send(action: string, data: unknown
|
|
54
|
-
|
|
49
|
+
send(action: string, data: unknown, to?: string): IMessenger;
|
|
55
50
|
close(): void;
|
|
56
|
-
|
|
57
51
|
onMessage(message: any): void;
|
|
58
52
|
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { IMessenger };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|