egg 4.0.10 → 4.1.0-beta.3
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 +1 -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/dist/lib/egg.js
ADDED
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import { BaseHookClass } from "./core/base_hook_class.js";
|
|
2
|
+
import { BaseContextClass as BaseContextClass$1 } from "./core/base_context_class.js";
|
|
3
|
+
import Context from "../app/extend/context.js";
|
|
4
|
+
import { create } from "./core/messenger/index.js";
|
|
5
|
+
import { ContextHttpClient } from "./core/context_httpclient.js";
|
|
6
|
+
import { HttpClient } from "./core/httpclient.js";
|
|
7
|
+
import { createLoggers } from "./core/logger.js";
|
|
8
|
+
import { convertObject } from "./core/utils.js";
|
|
9
|
+
import { getSourceDirname } from "./utils.js";
|
|
10
|
+
import { EggCore, Request as Request$1, Response as Response$1, Router, utils } from "@eggjs/core";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { performance } from "node:perf_hooks";
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import http from "node:http";
|
|
15
|
+
import inspector from "node:inspector";
|
|
16
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
17
|
+
import createClusterClient, { close } from "cluster-client";
|
|
18
|
+
import { extend } from "@eggjs/extend2";
|
|
19
|
+
import { EggContextLogger, EggLogger, EggLoggers } from "egg-logger";
|
|
20
|
+
import { Cookies } from "@eggjs/cookies";
|
|
21
|
+
import CircularJSON from "circular-json-for-egg";
|
|
22
|
+
|
|
23
|
+
//#region src/lib/egg.ts
|
|
24
|
+
const EGG_PATH = Symbol.for("egg#eggPath");
|
|
25
|
+
var Request = class extends Request$1 {};
|
|
26
|
+
var Response = class extends Response$1 {};
|
|
27
|
+
/**
|
|
28
|
+
* Based on koa's Application
|
|
29
|
+
* @see https://github.com/eggjs/egg-core
|
|
30
|
+
* @see https://github.com/eggjs/koa/blob/master/src/application.ts
|
|
31
|
+
* @augments EggCore
|
|
32
|
+
*/
|
|
33
|
+
var EggApplicationCore = class extends EggCore {
|
|
34
|
+
ContextCookies = Cookies;
|
|
35
|
+
ContextLogger = EggContextLogger;
|
|
36
|
+
ContextHttpClient = ContextHttpClient;
|
|
37
|
+
HttpClient = HttpClient;
|
|
38
|
+
HttpClientNext = HttpClient;
|
|
39
|
+
/**
|
|
40
|
+
* Retrieve base context class
|
|
41
|
+
* @member {BaseContextClass} BaseContextClass
|
|
42
|
+
* @since 1.0.0
|
|
43
|
+
*/
|
|
44
|
+
BaseContextClass = BaseContextClass$1;
|
|
45
|
+
/**
|
|
46
|
+
* Retrieve base controller
|
|
47
|
+
* @member {Controller} Controller
|
|
48
|
+
* @since 1.0.0
|
|
49
|
+
*/
|
|
50
|
+
Controller = BaseContextClass$1;
|
|
51
|
+
/**
|
|
52
|
+
* Retrieve base service
|
|
53
|
+
* @member {Service} Service
|
|
54
|
+
* @since 1.0.0
|
|
55
|
+
*/
|
|
56
|
+
Service = BaseContextClass$1;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieve base subscription
|
|
59
|
+
* @member {Subscription} Subscription
|
|
60
|
+
* @since 2.12.0
|
|
61
|
+
*/
|
|
62
|
+
Subscription = BaseContextClass$1;
|
|
63
|
+
/**
|
|
64
|
+
* Retrieve base context class
|
|
65
|
+
* @member {BaseHookClass} BaseHookClass
|
|
66
|
+
*/
|
|
67
|
+
BaseHookClass = BaseHookClass;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieve base boot
|
|
70
|
+
* @member {Boot}
|
|
71
|
+
* @alias BaseHookClass
|
|
72
|
+
*/
|
|
73
|
+
Boot = BaseHookClass;
|
|
74
|
+
#httpClient;
|
|
75
|
+
#loggers;
|
|
76
|
+
#clusterClients = [];
|
|
77
|
+
messenger;
|
|
78
|
+
agent;
|
|
79
|
+
application;
|
|
80
|
+
/**
|
|
81
|
+
* @class
|
|
82
|
+
* @param {Object} options
|
|
83
|
+
* - {Object} [type] - type of instance, Agent and Application both extend koa, type can determine what it is.
|
|
84
|
+
* - {String} [baseDir] - app root dir, default is `process.cwd()`
|
|
85
|
+
* - {Object} [plugins] - custom plugin config, use it in unittest
|
|
86
|
+
* - {String} [mode] - process mode, can be cluster / single, default is `cluster`
|
|
87
|
+
*/
|
|
88
|
+
constructor(options) {
|
|
89
|
+
options = {
|
|
90
|
+
mode: "cluster",
|
|
91
|
+
type: "application",
|
|
92
|
+
baseDir: process.cwd(),
|
|
93
|
+
...options
|
|
94
|
+
};
|
|
95
|
+
super(options);
|
|
96
|
+
/**
|
|
97
|
+
* messenger instance
|
|
98
|
+
* @member {Messenger}
|
|
99
|
+
* @since 1.0.0
|
|
100
|
+
*/
|
|
101
|
+
this.messenger = create(this);
|
|
102
|
+
this.messenger.once("egg-ready", () => {
|
|
103
|
+
this.lifecycle.triggerServerDidReady();
|
|
104
|
+
});
|
|
105
|
+
this.lifecycle.registerBeforeStart(async () => {
|
|
106
|
+
await this.load();
|
|
107
|
+
}, "load files");
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* @deprecated please use `options` property instead
|
|
111
|
+
*/
|
|
112
|
+
get _options() {
|
|
113
|
+
return this.options;
|
|
114
|
+
}
|
|
115
|
+
async loadConfig() {
|
|
116
|
+
await this.loader.loadConfig();
|
|
117
|
+
}
|
|
118
|
+
async load() {
|
|
119
|
+
await this.loadConfig();
|
|
120
|
+
this.ready(() => process.nextTick(() => {
|
|
121
|
+
const dumpStartTime = Date.now();
|
|
122
|
+
this.dumpConfig();
|
|
123
|
+
this.dumpTiming();
|
|
124
|
+
this.coreLogger.info("[egg] dump config after ready, %sms", Date.now() - dumpStartTime);
|
|
125
|
+
}));
|
|
126
|
+
this.#setupTimeoutTimer();
|
|
127
|
+
this.console.info("[egg] App root: %s", this.baseDir);
|
|
128
|
+
this.console.info("[egg] All *.log files save on %j", this.config.logger.dir);
|
|
129
|
+
this.console.info("[egg] Loaded enabled plugin %j", this.loader.orderPlugins);
|
|
130
|
+
this._unhandledRejectionHandler = this._unhandledRejectionHandler.bind(this);
|
|
131
|
+
process.on("unhandledRejection", this._unhandledRejectionHandler);
|
|
132
|
+
this.lifecycle.registerBeforeClose(async () => {
|
|
133
|
+
for (const clusterClient of this.#clusterClients) await close(clusterClient);
|
|
134
|
+
this.#clusterClients = [];
|
|
135
|
+
if (this.type === "application" && this.options.mode === "single") await this.agent.close();
|
|
136
|
+
for (const logger of this.loggers.values()) logger.close();
|
|
137
|
+
this.messenger.close();
|
|
138
|
+
process.removeListener("unhandledRejection", this._unhandledRejectionHandler);
|
|
139
|
+
});
|
|
140
|
+
await this.loader.load();
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Usage: new ApiClient({ cluster: app.cluster })
|
|
144
|
+
*/
|
|
145
|
+
get cluster() {
|
|
146
|
+
return this.clusterWrapper.bind(this);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Wrap the Client with Leader/Follower Pattern
|
|
150
|
+
*
|
|
151
|
+
* @description almost the same as Agent.cluster API, the only different is that this method create Follower.
|
|
152
|
+
*
|
|
153
|
+
* @see https://github.com/node-modules/cluster-client
|
|
154
|
+
* @param {Function} clientClass - client class function
|
|
155
|
+
* @param {Object} [options]
|
|
156
|
+
* - {Boolean} [autoGenerate] - whether generate delegate rule automatically, default is true
|
|
157
|
+
* - {Function} [formatKey] - a method to transform the subscription info into a string,default is JSON.stringify
|
|
158
|
+
* - {Object} [transcode|JSON.stringify/parse]
|
|
159
|
+
* - {Function} encode - custom serialize method
|
|
160
|
+
* - {Function} decode - custom deserialize method
|
|
161
|
+
* - {Boolean} [isBroadcast] - whether broadcast subscription result to all followers or just one, default is true
|
|
162
|
+
* - {Number} [responseTimeout] - response timeout, default is 3 seconds
|
|
163
|
+
* - {Number} [maxWaitTime|30000] - leader startup max time, default is 30 seconds
|
|
164
|
+
* @return {ClientWrapper} wrapper
|
|
165
|
+
*/
|
|
166
|
+
clusterWrapper(clientClass, options) {
|
|
167
|
+
const clientClassOptions = {
|
|
168
|
+
...this.config.clusterClient,
|
|
169
|
+
...options,
|
|
170
|
+
singleMode: this.options.mode === "single",
|
|
171
|
+
port: this.options.clusterPort,
|
|
172
|
+
isLeader: this.type === "agent",
|
|
173
|
+
logger: this.coreLogger,
|
|
174
|
+
isCheckHeartbeat: this.config.env === "prod" ? true : inspector.url() === void 0
|
|
175
|
+
};
|
|
176
|
+
const client = createClusterClient(clientClass, clientClassOptions);
|
|
177
|
+
this.#patchClusterClient(client);
|
|
178
|
+
return client;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* print the information when console.log(app)
|
|
182
|
+
* @return {Object} inspected app.
|
|
183
|
+
* @since 1.0.0
|
|
184
|
+
* @example
|
|
185
|
+
* ```js
|
|
186
|
+
* console.log(app);
|
|
187
|
+
* =>
|
|
188
|
+
* {
|
|
189
|
+
* name: 'mock-app',
|
|
190
|
+
* env: 'test',
|
|
191
|
+
* subdomainOffset: 2,
|
|
192
|
+
* config: '<egg config>',
|
|
193
|
+
* controller: '<egg controller>',
|
|
194
|
+
* service: '<egg service>',
|
|
195
|
+
* middlewares: '<egg middlewares>',
|
|
196
|
+
* urllib: '<egg urllib>',
|
|
197
|
+
* loggers: '<egg loggers>'
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
inspect() {
|
|
202
|
+
const res = { env: this.config.env };
|
|
203
|
+
function delegate(res$1, app, keys) {
|
|
204
|
+
for (const key of keys) if (app[key]) res$1[key] = app[key];
|
|
205
|
+
}
|
|
206
|
+
function abbr(res$1, app, keys) {
|
|
207
|
+
for (const key of keys) if (app[key]) res$1[key] = `<egg ${key}>`;
|
|
208
|
+
}
|
|
209
|
+
delegate(res, this, [
|
|
210
|
+
"name",
|
|
211
|
+
"baseDir",
|
|
212
|
+
"subdomainOffset"
|
|
213
|
+
]);
|
|
214
|
+
abbr(res, this, [
|
|
215
|
+
"config",
|
|
216
|
+
"controller",
|
|
217
|
+
"httpclient",
|
|
218
|
+
"loggers",
|
|
219
|
+
"middlewares",
|
|
220
|
+
"router",
|
|
221
|
+
"serviceClasses"
|
|
222
|
+
]);
|
|
223
|
+
return res;
|
|
224
|
+
}
|
|
225
|
+
toJSON() {
|
|
226
|
+
return this.inspect();
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* http request helper base on {@link httpclient}, it will auto save httpclient log.
|
|
230
|
+
* Keep the same api with `httpclient.request(url, args)`.
|
|
231
|
+
*
|
|
232
|
+
* See https://github.com/node-modules/urllib#api-doc for more details.
|
|
233
|
+
*
|
|
234
|
+
* @param {String} url request url address.
|
|
235
|
+
* @param {Object} options
|
|
236
|
+
* - method {String} - Request method, defaults to GET. Could be GET, POST, DELETE or PUT. Alias 'type'.
|
|
237
|
+
* - data {Object} - Data to be sent. Will be stringify automatically.
|
|
238
|
+
* - dataType {String} - String - Type of response data. Could be `text` or `json`.
|
|
239
|
+
* If it's `text`, the callback data would be a String.
|
|
240
|
+
* If it's `json`, the data of callback would be a parsed JSON Object.
|
|
241
|
+
* Default callback data would be a Buffer.
|
|
242
|
+
* - headers {Object} - Request headers.
|
|
243
|
+
* - timeout {Number} - Request timeout in milliseconds. Defaults to exports.TIMEOUT.
|
|
244
|
+
* Include remote server connecting timeout and response timeout.
|
|
245
|
+
* When timeout happen, will return ConnectionTimeout or ResponseTimeout.
|
|
246
|
+
* - auth {String} - `username:password` used in HTTP Basic Authorization.
|
|
247
|
+
* - followRedirect {Boolean} - follow HTTP 3xx responses as redirects. defaults to false.
|
|
248
|
+
* - gzip {Boolean} - let you get the res object when request connected, default false. alias customResponse
|
|
249
|
+
* - nestedQuerystring {Boolean} - urllib default use querystring to stringify form data which don't
|
|
250
|
+
* support nested object, will use qs instead of querystring to support nested object by set this option to true.
|
|
251
|
+
* - more options see https://github.com/node-modules/urllib
|
|
252
|
+
* @return {Object}
|
|
253
|
+
* - status {Number} - HTTP response status
|
|
254
|
+
* - headers {Object} - HTTP response headers
|
|
255
|
+
* - res {Object} - HTTP response meta
|
|
256
|
+
* - data {Object} - HTTP response body
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```js
|
|
260
|
+
* const result = await app.curl('http://example.com/foo.json', {
|
|
261
|
+
* method: 'GET',
|
|
262
|
+
* dataType: 'json',
|
|
263
|
+
* });
|
|
264
|
+
* console.log(result.status, result.headers, result.data);
|
|
265
|
+
* ```
|
|
266
|
+
*/
|
|
267
|
+
async curl(url, options) {
|
|
268
|
+
return await this.httpClient.request(url, options);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Create a new HttpClient instance with custom options
|
|
272
|
+
* @param {Object} [options] HttpClient init options
|
|
273
|
+
*/
|
|
274
|
+
createHttpClient(options) {
|
|
275
|
+
return new this.HttpClient(this, options);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* HttpClient instance
|
|
279
|
+
* @see https://github.com/node-modules/urllib
|
|
280
|
+
* @member {HttpClient}
|
|
281
|
+
*/
|
|
282
|
+
get httpClient() {
|
|
283
|
+
if (!this.#httpClient) this.#httpClient = this.createHttpClient();
|
|
284
|
+
return this.#httpClient;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* @deprecated please use httpClient instead
|
|
288
|
+
* @alias httpClient
|
|
289
|
+
* @member {HttpClient}
|
|
290
|
+
*/
|
|
291
|
+
get httpclient() {
|
|
292
|
+
return this.httpClient;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* All loggers contain logger, coreLogger and customLogger
|
|
296
|
+
* @member {Object}
|
|
297
|
+
* @since 1.0.0
|
|
298
|
+
*/
|
|
299
|
+
get loggers() {
|
|
300
|
+
if (!this.#loggers) this.#loggers = createLoggers(this);
|
|
301
|
+
return this.#loggers;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Get logger by name, it's equal to app.loggers['name'],
|
|
305
|
+
* but you can extend it with your own logical.
|
|
306
|
+
* @param {String} name - logger name
|
|
307
|
+
* @return {Logger} logger
|
|
308
|
+
*/
|
|
309
|
+
getLogger(name) {
|
|
310
|
+
return this.loggers[name] || null;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* application logger, log file is `$HOME/logs/{appname}/{appname}-web`
|
|
314
|
+
* @member {Logger}
|
|
315
|
+
* @since 1.0.0
|
|
316
|
+
*/
|
|
317
|
+
get logger() {
|
|
318
|
+
return this.getLogger("logger");
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* core logger for framework and plugins, log file is `$HOME/logs/{appname}/egg-web`
|
|
322
|
+
* @member {Logger}
|
|
323
|
+
* @since 1.0.0
|
|
324
|
+
*/
|
|
325
|
+
get coreLogger() {
|
|
326
|
+
return this.getLogger("coreLogger");
|
|
327
|
+
}
|
|
328
|
+
_unhandledRejectionHandler(err) {
|
|
329
|
+
this.coreLogger.error("[egg:unhandledRejection] %s", err && err.message || err);
|
|
330
|
+
if (!(err instanceof Error)) {
|
|
331
|
+
const newError = new Error(String(err));
|
|
332
|
+
if (err) {
|
|
333
|
+
if (err.name) newError.name = err.name;
|
|
334
|
+
if (err.message) newError.message = err.message;
|
|
335
|
+
if (err.stack) newError.stack = err.stack;
|
|
336
|
+
}
|
|
337
|
+
err = newError;
|
|
338
|
+
}
|
|
339
|
+
if (err.name === "Error") err.name = "unhandledRejectionError";
|
|
340
|
+
this.coreLogger.error(err);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* dump out the config and meta object
|
|
344
|
+
* @private
|
|
345
|
+
*/
|
|
346
|
+
dumpConfigToObject() {
|
|
347
|
+
let ignoreList;
|
|
348
|
+
try {
|
|
349
|
+
ignoreList = Array.from(this.config.dump.ignore);
|
|
350
|
+
} catch {
|
|
351
|
+
ignoreList = [];
|
|
352
|
+
}
|
|
353
|
+
const config = extend(true, {}, {
|
|
354
|
+
config: this.config,
|
|
355
|
+
plugins: this.loader.allPlugins,
|
|
356
|
+
appInfo: this.loader.appInfo
|
|
357
|
+
});
|
|
358
|
+
convertObject(config, ignoreList);
|
|
359
|
+
return {
|
|
360
|
+
config,
|
|
361
|
+
meta: this.loader.configMeta
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* save app.config to `run/${type}_config.json`
|
|
366
|
+
* @private
|
|
367
|
+
*/
|
|
368
|
+
dumpConfig() {
|
|
369
|
+
const rundir = this.config.rundir;
|
|
370
|
+
try {
|
|
371
|
+
if (!fs.existsSync(rundir)) fs.mkdirSync(rundir);
|
|
372
|
+
const { config, meta } = this.dumpConfigToObject();
|
|
373
|
+
const dumpFile = path.join(rundir, `${this.type}_config.json`);
|
|
374
|
+
fs.writeFileSync(dumpFile, CircularJSON.stringify(config, null, 2));
|
|
375
|
+
const dumpMetaFile = path.join(rundir, `${this.type}_config_meta.json`);
|
|
376
|
+
fs.writeFileSync(dumpMetaFile, CircularJSON.stringify(meta, null, 2));
|
|
377
|
+
} catch (err) {
|
|
378
|
+
this.coreLogger.warn(`[egg] dumpConfig error: ${err.message}`);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
dumpTiming() {
|
|
382
|
+
try {
|
|
383
|
+
const items = this.timing.toJSON();
|
|
384
|
+
const rundir = this.config.rundir;
|
|
385
|
+
const dumpFile = path.join(rundir, `${this.type}_timing_${process.pid}.json`);
|
|
386
|
+
fs.writeFileSync(dumpFile, CircularJSON.stringify(items, null, 2));
|
|
387
|
+
this.coreLogger.info(this.timing.toString());
|
|
388
|
+
this.timing.disable();
|
|
389
|
+
for (const item of items) if (item.index > 0 && item.duration && item.duration >= this.config.dump.timing.slowBootActionMinDuration) this.coreLogger.warn("[egg][dumpTiming][slow-boot-action] #%d %dms, name: %s", item.index, item.duration, item.name);
|
|
390
|
+
} catch (err) {
|
|
391
|
+
this.coreLogger.warn(`[egg] dumpTiming error: ${err.message}`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
get [EGG_PATH]() {
|
|
395
|
+
return getSourceDirname();
|
|
396
|
+
}
|
|
397
|
+
#setupTimeoutTimer() {
|
|
398
|
+
const startTimeoutTimer = setTimeout(() => {
|
|
399
|
+
this.coreLogger.error(this.timing.toString());
|
|
400
|
+
this.coreLogger.error(`${this.type} still doesn't ready after ${this.config.workerStartTimeout} ms.`);
|
|
401
|
+
const items = this.timing.toJSON();
|
|
402
|
+
for (const item of items) {
|
|
403
|
+
if (item.end) continue;
|
|
404
|
+
this.coreLogger.error(`unfinished timing item: ${CircularJSON.stringify(item)}`);
|
|
405
|
+
}
|
|
406
|
+
this.coreLogger.error("[egg][setupTimeoutTimer] check run/%s_timing_%s.json for more details.", this.type, process.pid);
|
|
407
|
+
this.emit("startTimeout");
|
|
408
|
+
this.dumpConfig();
|
|
409
|
+
this.dumpTiming();
|
|
410
|
+
}, this.config.workerStartTimeout);
|
|
411
|
+
this.ready(() => clearTimeout(startTimeoutTimer));
|
|
412
|
+
}
|
|
413
|
+
get config() {
|
|
414
|
+
return super.config;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* app.env delegate app.config.env
|
|
418
|
+
* @deprecated
|
|
419
|
+
*/
|
|
420
|
+
get env() {
|
|
421
|
+
this.deprecate("please use app.config.env instead");
|
|
422
|
+
return this.config.env;
|
|
423
|
+
}
|
|
424
|
+
set env(_) {}
|
|
425
|
+
/**
|
|
426
|
+
* app.proxy delegate app.config.proxy
|
|
427
|
+
* @deprecated
|
|
428
|
+
*/
|
|
429
|
+
get proxy() {
|
|
430
|
+
return this.config.proxy;
|
|
431
|
+
}
|
|
432
|
+
set proxy(_) {}
|
|
433
|
+
#patchClusterClient(client) {
|
|
434
|
+
const rawCreate = client.create;
|
|
435
|
+
client.create = (...args) => {
|
|
436
|
+
const realClient = rawCreate.apply(client, args);
|
|
437
|
+
this.#clusterClients.push(realClient);
|
|
438
|
+
return realClient;
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Create an anonymous context, the context isn't request level, so the request is mocked.
|
|
443
|
+
* then you can use context level API like `ctx.service`
|
|
444
|
+
* @member {String} EggApplication#createAnonymousContext
|
|
445
|
+
* @param {Request} [req] - if you want to mock request like querystring, you can pass an object to this function.
|
|
446
|
+
* @return {Context} context
|
|
447
|
+
*/
|
|
448
|
+
createAnonymousContext(req) {
|
|
449
|
+
const request = {
|
|
450
|
+
headers: {
|
|
451
|
+
host: "127.0.0.1",
|
|
452
|
+
"x-forwarded-for": "127.0.0.1"
|
|
453
|
+
},
|
|
454
|
+
query: {},
|
|
455
|
+
querystring: "",
|
|
456
|
+
host: "127.0.0.1",
|
|
457
|
+
hostname: "127.0.0.1",
|
|
458
|
+
protocol: "http",
|
|
459
|
+
secure: "false",
|
|
460
|
+
method: "GET",
|
|
461
|
+
url: "/",
|
|
462
|
+
path: "/",
|
|
463
|
+
socket: {
|
|
464
|
+
remoteAddress: "127.0.0.1",
|
|
465
|
+
remotePort: 7001
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
if (req) for (const key in req) if (key === "headers" || key === "query" || key === "socket") Object.assign(request[key], req[key]);
|
|
469
|
+
else request[key] = req[key];
|
|
470
|
+
const response = new http.ServerResponse(request);
|
|
471
|
+
return this.createContext(request, response);
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Run async function in the anonymous context scope
|
|
475
|
+
* @see Context#runInAnonymousContextScope
|
|
476
|
+
* @param {Function} scope - the first args is an anonymous ctx, scope should be async function
|
|
477
|
+
* @param {Request} [req] - if you want to mock request like querystring, you can pass an object to this function.
|
|
478
|
+
*/
|
|
479
|
+
async runInAnonymousContextScope(scope, req) {
|
|
480
|
+
const ctx = this.createAnonymousContext(req);
|
|
481
|
+
if (!scope.name) Reflect.set(scope, "_name", utils.getCalleeFromStack(true));
|
|
482
|
+
return await this.ctxStorage.run(ctx, async () => {
|
|
483
|
+
return await scope(ctx);
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Create egg context
|
|
488
|
+
* @function EggApplication#createContext
|
|
489
|
+
* @param {Req} req - node native Request object
|
|
490
|
+
* @param {Res} res - node native Response object
|
|
491
|
+
* @return {Context} context object
|
|
492
|
+
*/
|
|
493
|
+
createContext(req, res) {
|
|
494
|
+
const context = Object.create(this.context);
|
|
495
|
+
const request = context.request = Object.create(this.request);
|
|
496
|
+
const response = context.response = Object.create(this.response);
|
|
497
|
+
context.app = request.app = response.app = this;
|
|
498
|
+
context.req = request.req = response.req = req;
|
|
499
|
+
context.res = request.res = response.res = res;
|
|
500
|
+
request.ctx = response.ctx = context;
|
|
501
|
+
request.response = response;
|
|
502
|
+
response.request = request;
|
|
503
|
+
context.onerror = context.onerror.bind(context);
|
|
504
|
+
context.originalUrl = request.originalUrl = req.url;
|
|
505
|
+
context.starttime = Date.now();
|
|
506
|
+
context.performanceStarttime = performance.now();
|
|
507
|
+
return context;
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
|
|
511
|
+
//#endregion
|
|
512
|
+
export { Context, EggApplicationCore, Request, Response, Router };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/lib/error/CookieLimitExceedError.ts
|
|
2
|
+
var CookieLimitExceedError = class extends Error {
|
|
3
|
+
key;
|
|
4
|
+
cookie;
|
|
5
|
+
constructor(key, cookie) {
|
|
6
|
+
super(`cookie ${key}'s length(${cookie.length}) exceed the limit(4093)`);
|
|
7
|
+
this.name = this.constructor.name;
|
|
8
|
+
this.key = key;
|
|
9
|
+
this.cookie = cookie;
|
|
10
|
+
Error.captureStackTrace(this, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { CookieLimitExceedError };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/lib/error/MessageUnhandledRejectionError.d.ts
|
|
2
|
+
declare class MessageUnhandledRejectionError extends Error {
|
|
3
|
+
event: string | symbol;
|
|
4
|
+
args: any[];
|
|
5
|
+
constructor(err: Error, event: string | symbol, ...args: any[]);
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { MessageUnhandledRejectionError };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/lib/error/MessageUnhandledRejectionError.ts
|
|
2
|
+
var MessageUnhandledRejectionError = class extends Error {
|
|
3
|
+
event;
|
|
4
|
+
args;
|
|
5
|
+
constructor(err, event, ...args) {
|
|
6
|
+
super(`event: ${String(event)}, error: ${err.message}`, { cause: err });
|
|
7
|
+
this.name = this.constructor.name;
|
|
8
|
+
this.event = event;
|
|
9
|
+
this.args = args;
|
|
10
|
+
Error.captureStackTrace(this, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { MessageUnhandledRejectionError };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/AgentWorkerLoader.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Agent worker process loader
|
|
7
|
+
* @see https://github.com/eggjs/egg-core/blob/master/src/loader/egg_loader.ts
|
|
8
|
+
*/
|
|
9
|
+
declare class AgentWorkerLoader extends EggApplicationLoader {
|
|
10
|
+
/**
|
|
11
|
+
* loadPlugin first, then loadConfig
|
|
12
|
+
*/
|
|
13
|
+
loadConfig(): Promise<void>;
|
|
14
|
+
load(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { AgentWorkerLoader };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/AgentWorkerLoader.ts
|
|
4
|
+
/**
|
|
5
|
+
* Agent worker process loader
|
|
6
|
+
* @see https://github.com/eggjs/egg-core/blob/master/src/loader/egg_loader.ts
|
|
7
|
+
*/
|
|
8
|
+
var AgentWorkerLoader = class extends EggApplicationLoader {
|
|
9
|
+
/**
|
|
10
|
+
* loadPlugin first, then loadConfig
|
|
11
|
+
*/
|
|
12
|
+
async loadConfig() {
|
|
13
|
+
await this.loadPlugin();
|
|
14
|
+
await super.loadConfig();
|
|
15
|
+
}
|
|
16
|
+
async load() {
|
|
17
|
+
await this.loadAgentExtend();
|
|
18
|
+
await this.loadContextExtend();
|
|
19
|
+
await this.loadCustomAgent();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { AgentWorkerLoader };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/AppWorkerLoader.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* App worker process Loader, will load plugins
|
|
7
|
+
* @see https://github.com/eggjs/egg-core/blob/master/src/loader/egg_loader.ts
|
|
8
|
+
*/
|
|
9
|
+
declare class AppWorkerLoader extends EggApplicationLoader {
|
|
10
|
+
/**
|
|
11
|
+
* loadPlugin first, then loadConfig
|
|
12
|
+
* @since 1.0.0
|
|
13
|
+
*/
|
|
14
|
+
loadConfig(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Load all directories in convention
|
|
17
|
+
* @since 1.0.0
|
|
18
|
+
*/
|
|
19
|
+
load(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { AppWorkerLoader };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { EggApplicationLoader } from "./EggApplicationLoader.js";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/loader/AppWorkerLoader.ts
|
|
4
|
+
/**
|
|
5
|
+
* App worker process Loader, will load plugins
|
|
6
|
+
* @see https://github.com/eggjs/egg-core/blob/master/src/loader/egg_loader.ts
|
|
7
|
+
*/
|
|
8
|
+
var AppWorkerLoader = class extends EggApplicationLoader {
|
|
9
|
+
/**
|
|
10
|
+
* loadPlugin first, then loadConfig
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
*/
|
|
13
|
+
async loadConfig() {
|
|
14
|
+
await this.loadPlugin();
|
|
15
|
+
await super.loadConfig();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Load all directories in convention
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
21
|
+
async load() {
|
|
22
|
+
await this.loadApplicationExtend();
|
|
23
|
+
await this.loadRequestExtend();
|
|
24
|
+
await this.loadResponseExtend();
|
|
25
|
+
await this.loadContextExtend();
|
|
26
|
+
await this.loadHelperExtend();
|
|
27
|
+
await this.loadCustomLoader();
|
|
28
|
+
await this.loadCustomApp();
|
|
29
|
+
await this.loadService();
|
|
30
|
+
await this.loadMiddleware();
|
|
31
|
+
await this.loadController();
|
|
32
|
+
await this.loadRouter();
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { AppWorkerLoader };
|