egg 4.0.0-beta.9 → 4.0.1
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/dist/commonjs/app/extend/context.d.ts +52 -12
- package/dist/commonjs/app/extend/context.js +25 -24
- package/dist/commonjs/app/extend/request.d.ts +15 -2
- package/dist/commonjs/app/extend/request.js +1 -1
- package/dist/commonjs/app/extend/response.d.ts +6 -0
- package/dist/commonjs/app/middleware/meta.d.ts +2 -2
- package/dist/commonjs/app/middleware/meta.js +1 -1
- package/dist/commonjs/app/middleware/notfound.d.ts +2 -2
- package/dist/commonjs/app/middleware/notfound.js +1 -1
- package/dist/commonjs/app/middleware/site_file.d.ts +3 -3
- package/dist/commonjs/app/middleware/site_file.js +1 -1
- package/dist/commonjs/config/config.default.d.ts +1 -1
- package/dist/commonjs/config/plugin.js +5 -6
- package/dist/commonjs/index.d.ts +12 -7
- package/dist/commonjs/index.js +11 -22
- package/dist/commonjs/lib/application.d.ts +7 -3
- package/dist/commonjs/lib/application.js +15 -4
- package/dist/commonjs/lib/core/base_context_class.d.ts +6 -3
- package/dist/commonjs/lib/core/base_context_class.js +1 -2
- package/dist/commonjs/lib/core/base_hook_class.d.ts +2 -2
- package/dist/commonjs/lib/core/base_hook_class.js +1 -2
- package/dist/commonjs/lib/core/context_httpclient.d.ts +3 -3
- package/dist/commonjs/lib/core/context_httpclient.js +1 -1
- package/dist/commonjs/lib/core/httpclient.d.ts +7 -6
- package/dist/commonjs/lib/core/httpclient.js +10 -5
- package/dist/commonjs/lib/core/messenger/base.d.ts +8 -0
- package/dist/commonjs/lib/core/messenger/base.js +31 -0
- package/dist/commonjs/lib/core/messenger/index.js +3 -2
- package/dist/commonjs/lib/core/messenger/ipc.d.ts +2 -3
- package/dist/commonjs/lib/core/messenger/ipc.js +4 -6
- package/dist/commonjs/lib/core/messenger/local.d.ts +2 -3
- package/dist/commonjs/lib/core/messenger/local.js +4 -9
- package/dist/commonjs/lib/core/utils.d.ts +1 -1
- package/dist/commonjs/lib/core/utils.js +3 -3
- package/dist/commonjs/lib/egg.d.ts +37 -13
- package/dist/commonjs/lib/egg.js +21 -6
- package/dist/commonjs/lib/error/CookieLimitExceedError.d.ts +5 -0
- package/dist/commonjs/lib/error/CookieLimitExceedError.js +16 -0
- package/dist/commonjs/lib/error/MessageUnhandledRejectionError.d.ts +5 -0
- package/dist/commonjs/lib/error/MessageUnhandledRejectionError.js +16 -0
- package/dist/commonjs/lib/error/index.d.ts +2 -0
- package/dist/commonjs/lib/error/index.js +19 -0
- package/dist/commonjs/lib/start.d.ts +10 -1
- package/dist/commonjs/lib/start.js +1 -1
- package/dist/commonjs/lib/{type.d.ts → types.d.ts} +51 -85
- package/dist/commonjs/lib/types.js +9 -0
- package/dist/commonjs/lib/utils.js +1 -1
- package/dist/commonjs/urllib.d.ts +1 -0
- package/dist/commonjs/urllib.js +18 -0
- package/dist/esm/app/extend/context.d.ts +52 -12
- package/dist/esm/app/extend/context.js +24 -20
- package/dist/esm/app/extend/request.d.ts +15 -2
- package/dist/esm/app/extend/request.js +1 -1
- package/dist/esm/app/extend/response.d.ts +6 -0
- package/dist/esm/app/middleware/meta.d.ts +2 -2
- package/dist/esm/app/middleware/meta.js +1 -1
- package/dist/esm/app/middleware/notfound.d.ts +2 -2
- package/dist/esm/app/middleware/notfound.js +1 -1
- package/dist/esm/app/middleware/site_file.d.ts +3 -3
- package/dist/esm/app/middleware/site_file.js +1 -1
- package/dist/esm/config/config.default.d.ts +1 -1
- package/dist/esm/config/plugin.js +5 -6
- package/dist/esm/index.d.ts +12 -7
- package/dist/esm/index.js +13 -8
- package/dist/esm/lib/application.d.ts +7 -3
- package/dist/esm/lib/application.js +15 -4
- package/dist/esm/lib/core/base_context_class.d.ts +6 -3
- package/dist/esm/lib/core/base_context_class.js +1 -2
- package/dist/esm/lib/core/base_hook_class.d.ts +2 -2
- package/dist/esm/lib/core/base_hook_class.js +1 -2
- package/dist/esm/lib/core/context_httpclient.d.ts +3 -3
- package/dist/esm/lib/core/context_httpclient.js +1 -1
- package/dist/esm/lib/core/httpclient.d.ts +7 -6
- package/dist/esm/lib/core/httpclient.js +10 -5
- package/dist/esm/lib/core/messenger/base.d.ts +8 -0
- package/dist/esm/lib/core/messenger/base.js +27 -0
- package/dist/esm/lib/core/messenger/index.js +3 -2
- package/dist/esm/lib/core/messenger/ipc.d.ts +2 -3
- package/dist/esm/lib/core/messenger/ipc.js +4 -6
- package/dist/esm/lib/core/messenger/local.d.ts +2 -3
- package/dist/esm/lib/core/messenger/local.js +4 -6
- package/dist/esm/lib/core/utils.d.ts +1 -1
- package/dist/esm/lib/core/utils.js +3 -3
- package/dist/esm/lib/egg.d.ts +37 -13
- package/dist/esm/lib/egg.js +23 -7
- package/dist/esm/lib/error/CookieLimitExceedError.d.ts +5 -0
- package/dist/esm/lib/error/CookieLimitExceedError.js +12 -0
- package/dist/esm/lib/error/MessageUnhandledRejectionError.d.ts +5 -0
- package/dist/esm/lib/error/MessageUnhandledRejectionError.js +12 -0
- package/dist/esm/lib/error/index.d.ts +2 -0
- package/dist/esm/lib/error/index.js +3 -0
- package/dist/esm/lib/start.d.ts +10 -1
- package/dist/esm/lib/start.js +1 -1
- package/dist/esm/lib/{type.d.ts → types.d.ts} +51 -85
- package/dist/esm/lib/types.js +7 -0
- package/dist/esm/lib/utils.js +1 -1
- package/dist/esm/urllib.d.ts +1 -0
- package/dist/esm/urllib.js +2 -0
- package/dist/package.json +1 -1
- package/package.json +30 -22
- package/src/app/extend/context.ts +53 -34
- package/src/app/extend/request.ts +18 -2
- package/src/app/extend/response.ts +8 -0
- package/src/app/middleware/meta.ts +2 -2
- package/src/app/middleware/notfound.ts +2 -2
- package/src/app/middleware/site_file.ts +3 -3
- package/src/config/config.default.ts +1 -1
- package/src/config/config.local.ts +1 -1
- package/src/config/config.unittest.ts +1 -1
- package/src/config/plugin.ts +4 -6
- package/src/index.ts +40 -7
- package/src/lib/agent.ts +1 -1
- package/src/lib/application.ts +18 -6
- package/src/lib/core/base_context_class.ts +6 -3
- package/src/lib/core/base_hook_class.ts +2 -2
- package/src/lib/core/context_httpclient.ts +3 -3
- package/src/lib/core/httpclient.ts +21 -8
- package/src/lib/core/messenger/base.ts +30 -0
- package/src/lib/core/messenger/index.ts +2 -1
- package/src/lib/core/messenger/ipc.ts +3 -5
- package/src/lib/core/messenger/local.ts +3 -5
- package/src/lib/core/utils.ts +2 -2
- package/src/lib/egg.ts +58 -23
- package/src/lib/error/CookieLimitExceedError.ts +12 -0
- package/src/lib/error/MessageUnhandledRejectionError.ts +12 -0
- package/src/lib/error/index.ts +2 -0
- package/src/lib/start.ts +12 -2
- package/src/lib/{type.ts → types.ts} +65 -89
- package/src/lib/utils.ts +0 -1
- package/src/urllib.ts +1 -0
- package/dist/commonjs/app/extend/context.types.d.ts +0 -16
- package/dist/commonjs/app/extend/context.types.js +0 -3
- package/dist/commonjs/lib/egg.types.d.ts +0 -6
- package/dist/commonjs/lib/egg.types.js +0 -3
- package/dist/commonjs/lib/type.js +0 -3
- package/dist/esm/app/extend/context.types.d.ts +0 -16
- package/dist/esm/app/extend/context.types.js +0 -2
- package/dist/esm/lib/egg.types.d.ts +0 -6
- package/dist/esm/lib/egg.types.js +0 -2
- package/dist/esm/lib/type.js +0 -2
- package/src/app/extend/context.types.ts +0 -24
- package/src/lib/egg.types.ts +0 -6
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export class MessageUnhandledRejectionError extends Error {
|
|
2
|
+
event;
|
|
3
|
+
args;
|
|
4
|
+
constructor(err, event, ...args) {
|
|
5
|
+
super(`event: ${String(event)}, error: ${err.message}`, { cause: err });
|
|
6
|
+
this.name = this.constructor.name;
|
|
7
|
+
this.event = event;
|
|
8
|
+
this.args = args;
|
|
9
|
+
Error.captureStackTrace(this, this.constructor);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTWVzc2FnZVVuaGFuZGxlZFJlamVjdGlvbkVycm9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xpYi9lcnJvci9NZXNzYWdlVW5oYW5kbGVkUmVqZWN0aW9uRXJyb3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsTUFBTSxPQUFPLDhCQUErQixTQUFRLEtBQUs7SUFDdkQsS0FBSyxDQUFrQjtJQUN2QixJQUFJLENBQVE7SUFFWixZQUFZLEdBQVUsRUFBRSxLQUFzQixFQUFFLEdBQUcsSUFBVztRQUM1RCxLQUFLLENBQUMsVUFBVSxNQUFNLENBQUMsS0FBSyxDQUFDLFlBQVksR0FBRyxDQUFDLE9BQU8sRUFBRSxFQUFFLEVBQUUsS0FBSyxFQUFFLEdBQUcsRUFBRSxDQUFDLENBQUM7UUFDeEUsSUFBSSxDQUFDLElBQUksR0FBRyxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQztRQUNsQyxJQUFJLENBQUMsS0FBSyxHQUFHLEtBQUssQ0FBQztRQUNuQixJQUFJLENBQUMsSUFBSSxHQUFHLElBQUksQ0FBQztRQUNqQixLQUFLLENBQUMsaUJBQWlCLENBQUMsSUFBSSxFQUFFLElBQUksQ0FBQyxXQUFXLENBQUMsQ0FBQztJQUNsRCxDQUFDO0NBQ0YifQ==
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export * from './CookieLimitExceedError.js';
|
|
2
|
+
export * from './MessageUnhandledRejectionError.js';
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbGliL2Vycm9yL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsNkJBQTZCLENBQUM7QUFDNUMsY0FBYyxxQ0FBcUMsQ0FBQyJ9
|
package/dist/esm/lib/start.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { Agent } from './agent.js';
|
|
1
2
|
import { Application } from './application.js';
|
|
3
|
+
import { EggPlugin } from './types.js';
|
|
2
4
|
export interface StartEggOptions {
|
|
3
5
|
/** specify framework that can be absolute path or npm package */
|
|
4
6
|
framework?: string;
|
|
@@ -8,8 +10,15 @@ export interface StartEggOptions {
|
|
|
8
10
|
ignoreWarning?: boolean;
|
|
9
11
|
mode?: 'single';
|
|
10
12
|
env?: string;
|
|
13
|
+
plugins?: EggPlugin;
|
|
14
|
+
}
|
|
15
|
+
export interface SingleModeApplication extends Application {
|
|
16
|
+
agent: SingleModeAgent;
|
|
17
|
+
}
|
|
18
|
+
export interface SingleModeAgent extends Agent {
|
|
19
|
+
app: SingleModeApplication;
|
|
11
20
|
}
|
|
12
21
|
/**
|
|
13
22
|
* Start egg with single process
|
|
14
23
|
*/
|
|
15
|
-
export declare function startEgg(options?: StartEggOptions): Promise<
|
|
24
|
+
export declare function startEgg(options?: StartEggOptions): Promise<SingleModeApplication>;
|
package/dist/esm/lib/start.js
CHANGED
|
@@ -40,4 +40,4 @@ export async function startEgg(options = {}) {
|
|
|
40
40
|
application.messenger.broadcast('egg-ready');
|
|
41
41
|
return application;
|
|
42
42
|
}
|
|
43
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
43
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhcnQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL3N0YXJ0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sSUFBSSxNQUFNLFdBQVcsQ0FBQztBQUM3QixPQUFPLEVBQUUsUUFBUSxFQUFFLE1BQU0sU0FBUyxDQUFDO0FBQ25DLE9BQU8sRUFBRSxZQUFZLEVBQUUsTUFBTSxjQUFjLENBQUM7QUFDNUMsT0FBTyxFQUFFLEtBQUssRUFBRSxNQUFNLFlBQVksQ0FBQztBQUNuQyxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUF1Qi9DOztHQUVHO0FBQ0gsTUFBTSxDQUFDLEtBQUssVUFBVSxRQUFRLENBQUMsVUFBMkIsRUFBRTtJQUMxRCxPQUFPLENBQUMsT0FBTyxHQUFHLE9BQU8sQ0FBQyxPQUFPLElBQUksT0FBTyxDQUFDLEdBQUcsRUFBRSxDQUFDO0lBQ25ELE9BQU8sQ0FBQyxJQUFJLEdBQUcsUUFBUSxDQUFDO0lBRXhCLDZEQUE2RDtJQUM3RCxJQUFJLENBQUMsT0FBTyxDQUFDLFNBQVMsRUFBRSxDQUFDO1FBQ3ZCLElBQUksQ0FBQztZQUNILE1BQU0sR0FBRyxHQUFHLE1BQU0sUUFBUSxDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLE9BQU8sRUFBRSxjQUFjLENBQUMsQ0FBQyxDQUFDO1lBQ3ZFLE9BQU8sQ0FBQyxTQUFTLEdBQUcsR0FBRyxDQUFDLEdBQUcsQ0FBQyxTQUFTLENBQUM7UUFDeEMsQ0FBQztRQUFDLE9BQU8sQ0FBQyxFQUFFLENBQUM7WUFDWCxTQUFTO1FBQ1gsQ0FBQztJQUNILENBQUM7SUFDRCxJQUFJLFVBQVUsR0FBRyxLQUFLLENBQUM7SUFDdkIsSUFBSSxnQkFBZ0IsR0FBRyxXQUFXLENBQUM7SUFDbkMsSUFBSSxPQUFPLENBQUMsU0FBUyxFQUFFLENBQUM7UUFDdEIsTUFBTSxTQUFTLEdBQUcsTUFBTSxZQUFZLENBQUMsT0FBTyxDQUFDLFNBQVMsRUFBRSxFQUFFLEtBQUssRUFBRSxDQUFFLE9BQU8sQ0FBQyxPQUFPLENBQUUsRUFBRSxDQUFDLENBQUM7UUFDeEYsVUFBVSxHQUFHLFNBQVMsQ0FBQyxLQUFLLENBQUM7UUFDN0IsZ0JBQWdCLEdBQUcsU0FBUyxDQUFDLFdBQVcsQ0FBQztJQUMzQyxDQUFDO0lBRUQsTUFBTSxLQUFLLEdBQUcsSUFBSSxVQUFVLENBQUM7UUFDM0IsR0FBRyxPQUFPO0tBQ1gsQ0FBb0IsQ0FBQztJQUN0QixNQUFNLEtBQUssQ0FBQyxLQUFLLEVBQUUsQ0FBQztJQUNwQixNQUFNLFdBQVcsR0FBRyxJQUFJLGdCQUFnQixDQUFDO1FBQ3ZDLEdBQUcsT0FBTztLQUNYLENBQTBCLENBQUM7SUFDNUIsV0FBVyxDQUFDLEtBQUssR0FBRyxLQUFLLENBQUM7SUFDMUIsS0FBSyxDQUFDLFdBQVcsR0FBRyxXQUFXLENBQUM7SUFDaEMsTUFBTSxXQUFXLENBQUMsS0FBSyxFQUFFLENBQUM7SUFFMUIsa0RBQWtEO0lBQ2xELFdBQVcsQ0FBQyxTQUFTLENBQUMsU0FBUyxDQUFDLFdBQVcsQ0FBQyxDQUFDO0lBQzdDLE9BQU8sV0FBVyxDQUFDO0FBQ3JCLENBQUMifQ==
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import type { Socket } from 'node:net';
|
|
2
2
|
import type { RequestOptions as HttpClientRequestOptions } from 'urllib';
|
|
3
3
|
import type { EggLoggerOptions, EggLoggersOptions } from 'egg-logger';
|
|
4
|
-
import type { FileLoaderOptions } from '@eggjs/core';
|
|
5
|
-
import type { EggApplicationCore,
|
|
4
|
+
import type { FileLoaderOptions, EggAppConfig as EggCoreAppConfig } from '@eggjs/core';
|
|
5
|
+
import type { EggApplicationCore, Context } from './egg.js';
|
|
6
6
|
import type { MetaMiddlewareOptions } from '../app/middleware/meta.js';
|
|
7
7
|
import type { NotFoundMiddlewareOptions } from '../app/middleware/notfound.js';
|
|
8
8
|
import type { SiteFileMiddlewareOptions } from '../app/middleware/site_file.js';
|
|
9
|
-
|
|
9
|
+
import '@eggjs/watcher';
|
|
10
|
+
import '@eggjs/development';
|
|
11
|
+
import '@eggjs/jsonp';
|
|
12
|
+
import '@eggjs/i18n';
|
|
13
|
+
import '@eggjs/static';
|
|
14
|
+
export type { EggAppInfo, } from '@eggjs/core';
|
|
15
|
+
type IgnoreItem = string | RegExp | ((ctx: Context) => boolean);
|
|
10
16
|
type IgnoreOrMatch = IgnoreItem | IgnoreItem[];
|
|
11
17
|
export interface ClientErrorResponse {
|
|
12
18
|
body: string | Buffer;
|
|
@@ -41,7 +47,17 @@ export interface CustomLoaderConfig extends Omit<FileLoaderOptions, 'inject' | '
|
|
|
41
47
|
*/
|
|
42
48
|
loadunit?: boolean;
|
|
43
49
|
}
|
|
44
|
-
export interface
|
|
50
|
+
export interface HttpClientConfig {
|
|
51
|
+
/** Request timeout */
|
|
52
|
+
timeout?: number;
|
|
53
|
+
/** Default request args for httpclient */
|
|
54
|
+
request?: HttpClientRequestOptions;
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated keep compatible with egg 3.x, no more used
|
|
57
|
+
*/
|
|
58
|
+
useHttpClientNext?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface EggAppConfig extends EggCoreAppConfig {
|
|
45
61
|
workerStartTimeout: number;
|
|
46
62
|
baseDir: string;
|
|
47
63
|
middleware: string[];
|
|
@@ -87,7 +103,7 @@ export interface EggAppConfig {
|
|
|
87
103
|
};
|
|
88
104
|
/** Default is `'error'`, it will return `400` response when `Prototype-Poisoning` happen. */
|
|
89
105
|
onProtoPoisoning: 'error' | 'remove' | 'ignore';
|
|
90
|
-
onerror(err: any, ctx:
|
|
106
|
+
onerror(err: any, ctx: Context): void;
|
|
91
107
|
};
|
|
92
108
|
/**
|
|
93
109
|
* logger options
|
|
@@ -112,48 +128,10 @@ export interface EggAppConfig {
|
|
|
112
128
|
[key: string]: EggLoggerOptions;
|
|
113
129
|
};
|
|
114
130
|
/** Configuration of httpclient in egg. */
|
|
115
|
-
httpclient:
|
|
116
|
-
/** Request timeout */
|
|
117
|
-
timeout?: number;
|
|
118
|
-
/** Default request args for httpclient */
|
|
119
|
-
request?: HttpClientRequestOptions;
|
|
120
|
-
};
|
|
121
|
-
development: {
|
|
122
|
-
/**
|
|
123
|
-
* dirs needed watch, when files under these change, application will reload, use relative path
|
|
124
|
-
*/
|
|
125
|
-
watchDirs: string[];
|
|
126
|
-
/**
|
|
127
|
-
* dirs don't need watch, including subdirectories, use relative path
|
|
128
|
-
*/
|
|
129
|
-
ignoreDirs: string[];
|
|
130
|
-
/**
|
|
131
|
-
* don't wait all plugins ready, default is true.
|
|
132
|
-
*/
|
|
133
|
-
fastReady: boolean;
|
|
134
|
-
/**
|
|
135
|
-
* whether reload on debug, default is true.
|
|
136
|
-
*/
|
|
137
|
-
reloadOnDebug: boolean;
|
|
138
|
-
/**
|
|
139
|
-
* whether override default watchDirs, default is false.
|
|
140
|
-
*/
|
|
141
|
-
overrideDefault: boolean;
|
|
142
|
-
/**
|
|
143
|
-
* whether override default ignoreDirs, default is false.
|
|
144
|
-
*/
|
|
145
|
-
overrideIgnore: boolean;
|
|
146
|
-
/**
|
|
147
|
-
* whether to reload, use https://github.com/sindresorhus/multimatch
|
|
148
|
-
*/
|
|
149
|
-
reloadPattern: string[] | string;
|
|
150
|
-
};
|
|
131
|
+
httpclient: HttpClientConfig;
|
|
151
132
|
/**
|
|
152
133
|
* customLoader config
|
|
153
134
|
*/
|
|
154
|
-
customLoader: {
|
|
155
|
-
[key: string]: CustomLoaderConfig;
|
|
156
|
-
};
|
|
157
135
|
/**
|
|
158
136
|
* It will ignore special keys when dumpConfig
|
|
159
137
|
*/
|
|
@@ -172,31 +150,6 @@ export interface EggAppConfig {
|
|
|
172
150
|
*/
|
|
173
151
|
HOME: string;
|
|
174
152
|
hostHeaders: string;
|
|
175
|
-
/**
|
|
176
|
-
* I18n options
|
|
177
|
-
*/
|
|
178
|
-
i18n: {
|
|
179
|
-
/**
|
|
180
|
-
* default value EN_US
|
|
181
|
-
*/
|
|
182
|
-
defaultLocale: string;
|
|
183
|
-
/**
|
|
184
|
-
* i18n resource file dir, not recommend to change default value
|
|
185
|
-
*/
|
|
186
|
-
dirs: string[];
|
|
187
|
-
/**
|
|
188
|
-
* custom the locale value field, default `query.locale`, you can modify this config, such as `query.lang`
|
|
189
|
-
*/
|
|
190
|
-
queryField: string;
|
|
191
|
-
/**
|
|
192
|
-
* The locale value key in the cookie, default is locale.
|
|
193
|
-
*/
|
|
194
|
-
cookieField: string;
|
|
195
|
-
/**
|
|
196
|
-
* Locale cookie expire time, default `1y`, If pass number value, the unit will be ms
|
|
197
|
-
*/
|
|
198
|
-
cookieMaxAge: string | number;
|
|
199
|
-
};
|
|
200
153
|
/**
|
|
201
154
|
* Detect request' ip from specified headers, not case-sensitive. Only worked when config.proxy set to true.
|
|
202
155
|
*/
|
|
@@ -209,20 +162,6 @@ export interface EggAppConfig {
|
|
|
209
162
|
sameSite?: string;
|
|
210
163
|
httpOnly?: boolean;
|
|
211
164
|
};
|
|
212
|
-
/**
|
|
213
|
-
* jsonp options
|
|
214
|
-
* @member Config#jsonp
|
|
215
|
-
* @property {String} callback - jsonp callback method key, default to `_callback`
|
|
216
|
-
* @property {Number} limit - callback method name's max length, default to `50`
|
|
217
|
-
* @property {Boolean} csrf - enable csrf check or not. default to false
|
|
218
|
-
* @property {String|RegExp|Array} whiteList - referrer white list
|
|
219
|
-
*/
|
|
220
|
-
jsonp: {
|
|
221
|
-
limit: number;
|
|
222
|
-
callback: string;
|
|
223
|
-
csrf: boolean;
|
|
224
|
-
whiteList: string | RegExp | Array<string | RegExp>;
|
|
225
|
-
};
|
|
226
165
|
/**
|
|
227
166
|
* The key that signing cookies. It can contain multiple keys separated by .
|
|
228
167
|
*/
|
|
@@ -267,7 +206,6 @@ export interface EggAppConfig {
|
|
|
267
206
|
enable: boolean;
|
|
268
207
|
allowedMethods: string[];
|
|
269
208
|
};
|
|
270
|
-
watcher: Record<string, any>;
|
|
271
209
|
onClientError?(err: Error, socket: Socket, app: EggApplicationCore): ClientErrorResponse | Promise<ClientErrorResponse>;
|
|
272
210
|
/**
|
|
273
211
|
* server timeout in milliseconds, default to 0 (no timeout).
|
|
@@ -290,4 +228,32 @@ export interface EggAppConfig {
|
|
|
290
228
|
};
|
|
291
229
|
[prop: string]: any;
|
|
292
230
|
}
|
|
293
|
-
export
|
|
231
|
+
export type RequestObjectBody = Record<string, any>;
|
|
232
|
+
/**
|
|
233
|
+
* plugin config item interface
|
|
234
|
+
*/
|
|
235
|
+
export interface IEggPluginItem {
|
|
236
|
+
env?: EggEnvType[];
|
|
237
|
+
path?: string;
|
|
238
|
+
package?: string;
|
|
239
|
+
enable?: boolean;
|
|
240
|
+
}
|
|
241
|
+
export type EggPluginItem = IEggPluginItem | boolean;
|
|
242
|
+
/**
|
|
243
|
+
* build-in plugin list
|
|
244
|
+
*/
|
|
245
|
+
export interface EggPlugin {
|
|
246
|
+
[key: string]: EggPluginItem | undefined;
|
|
247
|
+
onerror?: EggPluginItem;
|
|
248
|
+
session?: EggPluginItem;
|
|
249
|
+
i18n?: EggPluginItem;
|
|
250
|
+
watcher?: EggPluginItem;
|
|
251
|
+
multipart?: EggPluginItem;
|
|
252
|
+
security?: EggPluginItem;
|
|
253
|
+
development?: EggPluginItem;
|
|
254
|
+
logrotator?: EggPluginItem;
|
|
255
|
+
schedule?: EggPluginItem;
|
|
256
|
+
static?: EggPluginItem;
|
|
257
|
+
jsonp?: EggPluginItem;
|
|
258
|
+
view?: EggPluginItem;
|
|
259
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// import plugins types
|
|
2
|
+
import '@eggjs/watcher';
|
|
3
|
+
import '@eggjs/development';
|
|
4
|
+
import '@eggjs/jsonp';
|
|
5
|
+
import '@eggjs/i18n';
|
|
6
|
+
import '@eggjs/static';
|
|
7
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL3R5cGVzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQWtCQSx1QkFBdUI7QUFDdkIsT0FBTyxnQkFBZ0IsQ0FBQztBQUN4QixPQUFPLG9CQUFvQixDQUFDO0FBQzVCLE9BQU8sY0FBYyxDQUFDO0FBQ3RCLE9BQU8sYUFBYSxDQUFDO0FBQ3JCLE9BQU8sZUFBZSxDQUFDIn0=
|
package/dist/esm/lib/utils.js
CHANGED
|
@@ -11,4 +11,4 @@ export function getSourceDirname() {
|
|
|
11
11
|
export function getSourceFile(filename) {
|
|
12
12
|
return path.join(getSourceDirname(), filename);
|
|
13
13
|
}
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXRpbHMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL3V0aWxzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sSUFBSSxNQUFNLFdBQVcsQ0FBQztBQUM3QixPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sVUFBVSxDQUFDO0FBRXpDLE1BQU0sVUFBVSxnQkFBZ0I7SUFDOUIsSUFBSSxPQUFPLFNBQVMsS0FBSyxXQUFXLEVBQUUsQ0FBQztRQUNyQyxPQUFPLElBQUksQ0FBQyxPQUFPLENBQUMsU0FBUyxDQUFDLENBQUM7SUFDakMsQ0FBQztJQUNELDZEQUE2RDtJQUM3RCxhQUFhO0lBQ2IsT0FBTyxJQUFJLENBQUMsT0FBTyxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUMsYUFBYSxDQUFDLE1BQU0sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ3BFLENBQUM7QUFFRCxNQUFNLFVBQVUsYUFBYSxDQUFDLFFBQWdCO0lBQzVDLE9BQU8sSUFBSSxDQUFDLElBQUksQ0FBQyxnQkFBZ0IsRUFBRSxFQUFFLFFBQVEsQ0FBQyxDQUFDO0FBQ2pELENBQUMifQ==
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'urllib';
|
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "egg",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">= 18.19.0"
|
|
6
6
|
},
|
|
@@ -19,26 +19,25 @@
|
|
|
19
19
|
"egg"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@eggjs/cluster": "
|
|
22
|
+
"@eggjs/cluster": "^3.0.0",
|
|
23
23
|
"@eggjs/cookies": "^3.0.0",
|
|
24
|
-
"@eggjs/core": "^6.2.
|
|
24
|
+
"@eggjs/core": "^6.2.13",
|
|
25
|
+
"@eggjs/development": "^4.0.0",
|
|
26
|
+
"@eggjs/i18n": "^3.0.1",
|
|
27
|
+
"@eggjs/jsonp": "^3.0.0",
|
|
25
28
|
"@eggjs/schedule": "^5.0.2",
|
|
26
|
-
"@eggjs/
|
|
27
|
-
"@eggjs/
|
|
29
|
+
"@eggjs/static": "^3.0.0",
|
|
30
|
+
"@eggjs/utils": "^4.2.4",
|
|
31
|
+
"@eggjs/watcher": "^4.0.3",
|
|
28
32
|
"circular-json-for-egg": "^1.0.0",
|
|
29
33
|
"cluster-client": "^3.7.0",
|
|
30
|
-
"delegates": "^1.0.0",
|
|
31
|
-
"egg-development": "^3.0.0",
|
|
32
34
|
"egg-errors": "^2.3.1",
|
|
33
|
-
"egg-i18n": "^2.1.1",
|
|
34
|
-
"egg-jsonp": "^2.0.0",
|
|
35
35
|
"egg-logger": "^3.6.0",
|
|
36
36
|
"egg-logrotator": "^3.1.0",
|
|
37
37
|
"egg-multipart": "^3.1.0",
|
|
38
38
|
"egg-onerror": "^2.1.1",
|
|
39
39
|
"egg-security": "^3.0.0",
|
|
40
40
|
"egg-session": "^3.3.0",
|
|
41
|
-
"egg-static": "^2.2.0",
|
|
42
41
|
"egg-view": "^2.1.3",
|
|
43
42
|
"extend2": "^4.0.0",
|
|
44
43
|
"graceful": "^2.0.0",
|
|
@@ -46,10 +45,10 @@
|
|
|
46
45
|
"is-type-of": "^2.1.0",
|
|
47
46
|
"koa-bodyparser": "^4.4.1",
|
|
48
47
|
"koa-override": "^4.0.0",
|
|
49
|
-
"onelogger": "^1.0.
|
|
48
|
+
"onelogger": "^1.0.1",
|
|
50
49
|
"performance-ms": "^1.1.0",
|
|
51
50
|
"sendmessage": "^3.0.1",
|
|
52
|
-
"urllib": "^4.
|
|
51
|
+
"urllib": "^4.6.11",
|
|
53
52
|
"utility": "^2.1.0",
|
|
54
53
|
"ylru": "^1.3.2"
|
|
55
54
|
},
|
|
@@ -57,18 +56,18 @@
|
|
|
57
56
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
58
57
|
"@eggjs/bin": "^7.0.0",
|
|
59
58
|
"@eggjs/koa": "^2.19.1",
|
|
60
|
-
"@eggjs/mock": "
|
|
59
|
+
"@eggjs/mock": "^6.0.5",
|
|
60
|
+
"@eggjs/supertest": "^8.1.1",
|
|
61
61
|
"@eggjs/tsconfig": "1",
|
|
62
|
-
"@types/delegates": "^1.0.3",
|
|
63
62
|
"@types/koa-bodyparser": "^4.3.12",
|
|
64
63
|
"@types/mocha": "^10.0.7",
|
|
65
64
|
"@types/ms": "^0.7.34",
|
|
66
65
|
"@types/node": "22",
|
|
67
|
-
"@types/supertest": "^6.0.2",
|
|
68
66
|
"address": "2",
|
|
69
67
|
"assert-file": "1",
|
|
70
68
|
"coffee": "5",
|
|
71
69
|
"cross-env": "7",
|
|
70
|
+
"dumi": "^2.4.17",
|
|
72
71
|
"egg-plugin-puml": "^2.4.0",
|
|
73
72
|
"egg-tracer": "^2.1.0",
|
|
74
73
|
"egg-view-nunjucks": "^2.3.0",
|
|
@@ -77,13 +76,13 @@
|
|
|
77
76
|
"formstream": "^1.5.1",
|
|
78
77
|
"koa-static": "^5.0.0",
|
|
79
78
|
"mm": "^3.4.0",
|
|
80
|
-
"pedding": "^
|
|
79
|
+
"pedding": "^2.0.1",
|
|
81
80
|
"prettier": "^2.7.1",
|
|
82
81
|
"rimraf": "6",
|
|
83
82
|
"runscript": "^2.0.1",
|
|
84
83
|
"sdk-base": "^4.2.1",
|
|
85
84
|
"spy": "^1.0.0",
|
|
86
|
-
"
|
|
85
|
+
"tsd": "^0.31.2",
|
|
87
86
|
"tshy": "^3.0.2",
|
|
88
87
|
"tshy-after": "1",
|
|
89
88
|
"typescript": "5"
|
|
@@ -98,11 +97,9 @@
|
|
|
98
97
|
"preci": "npm run clean && npm run lint",
|
|
99
98
|
"ci": "egg-bin cov",
|
|
100
99
|
"postci": "npm run prepublishOnly && npm run clean",
|
|
101
|
-
"prepublishOnly": "tshy && tshy-after && attw --pack",
|
|
102
|
-
"site:dev": "cross-env
|
|
103
|
-
"site:
|
|
104
|
-
"site:build": "cross-env NODE_OPTIONS=--openssl-legacy-provider APP_ROOT=./site dumi build",
|
|
105
|
-
"site:buildWithNode14-16": "cross-env APP_ROOT=./site dumi build",
|
|
100
|
+
"prepublishOnly": "tshy && tshy-after && attw --pack --profile node16",
|
|
101
|
+
"site:dev": "cross-env APP_ROOT=./site dumi dev",
|
|
102
|
+
"site:build": "cross-env APP_ROOT=./site dumi build",
|
|
106
103
|
"site:prettier": "prettier --config site/.prettierrc --ignore-path site/.prettierignore --write \"site/**/*.{js,jsx,tsx,ts,less,md,json}\"",
|
|
107
104
|
"puml": "puml . --dest ./site"
|
|
108
105
|
},
|
|
@@ -131,6 +128,7 @@
|
|
|
131
128
|
"tshy": {
|
|
132
129
|
"exports": {
|
|
133
130
|
".": "./src/index.ts",
|
|
131
|
+
"./urllib": "./src/urllib.ts",
|
|
134
132
|
"./package.json": "./package.json"
|
|
135
133
|
}
|
|
136
134
|
},
|
|
@@ -145,6 +143,16 @@
|
|
|
145
143
|
"default": "./dist/commonjs/index.js"
|
|
146
144
|
}
|
|
147
145
|
},
|
|
146
|
+
"./urllib": {
|
|
147
|
+
"import": {
|
|
148
|
+
"types": "./dist/esm/urllib.d.ts",
|
|
149
|
+
"default": "./dist/esm/urllib.js"
|
|
150
|
+
},
|
|
151
|
+
"require": {
|
|
152
|
+
"types": "./dist/commonjs/urllib.d.ts",
|
|
153
|
+
"default": "./dist/commonjs/urllib.js"
|
|
154
|
+
}
|
|
155
|
+
},
|
|
148
156
|
"./package.json": "./package.json"
|
|
149
157
|
},
|
|
150
158
|
"types": "./dist/commonjs/index.d.ts",
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
import delegate from 'delegates';
|
|
2
1
|
import { assign } from 'utility';
|
|
3
2
|
import { now, diff } from 'performance-ms';
|
|
4
3
|
import {
|
|
5
4
|
utils, Context as EggCoreContext, Router,
|
|
6
|
-
type ContextDelegation as EggCoreContextDelegation,
|
|
7
5
|
} from '@eggjs/core';
|
|
8
6
|
import type { Cookies as ContextCookies } from '@eggjs/cookies';
|
|
9
|
-
import { EggLogger } from 'egg-logger';
|
|
7
|
+
import type { EggLogger } from 'egg-logger';
|
|
10
8
|
import type { Application } from '../../lib/application.js';
|
|
11
9
|
import type {
|
|
12
10
|
HttpClientRequestURL, HttpClientRequestOptions, HttpClient,
|
|
13
11
|
} from '../../lib/core/httpclient.js';
|
|
14
|
-
import type { ContextHttpClient } from '../../lib/core/context_httpclient.js';
|
|
15
12
|
import type { BaseContextClass } from '../../lib//core/base_context_class.js';
|
|
16
|
-
import Request from './request.js';
|
|
17
|
-
import Response from './response.js';
|
|
13
|
+
import type Request from './request.js';
|
|
14
|
+
import type Response from './response.js';
|
|
18
15
|
import type Helper from './helper.js';
|
|
19
16
|
|
|
20
|
-
import './context.types.js';
|
|
21
|
-
|
|
22
17
|
const HELPER = Symbol('ctx helper');
|
|
23
18
|
const LOCALS = Symbol('ctx locals');
|
|
24
19
|
const LOCALS_LIST = Symbol('ctx localsList');
|
|
@@ -34,7 +29,9 @@ interface Cookies extends ContextCookies {
|
|
|
34
29
|
export default class Context extends EggCoreContext {
|
|
35
30
|
declare app: Application;
|
|
36
31
|
declare request: Request;
|
|
32
|
+
declare response: Response;
|
|
37
33
|
declare service: BaseContextClass;
|
|
34
|
+
declare proxy: any;
|
|
38
35
|
|
|
39
36
|
/**
|
|
40
37
|
* Request start time
|
|
@@ -61,19 +58,19 @@ export default class Context extends EggCoreContext {
|
|
|
61
58
|
/**
|
|
62
59
|
* Get a wrapper httpclient instance contain ctx in the hold request process
|
|
63
60
|
*
|
|
64
|
-
* @return {
|
|
61
|
+
* @return {HttpClient} the wrapper httpclient instance
|
|
65
62
|
*/
|
|
66
|
-
get httpclient():
|
|
63
|
+
get httpclient(): HttpClient {
|
|
67
64
|
if (!this[CONTEXT_HTTPCLIENT]) {
|
|
68
65
|
this[CONTEXT_HTTPCLIENT] = new this.app.ContextHttpClient(this as any);
|
|
69
66
|
}
|
|
70
|
-
return this[CONTEXT_HTTPCLIENT] as
|
|
67
|
+
return this[CONTEXT_HTTPCLIENT] as HttpClient;
|
|
71
68
|
}
|
|
72
69
|
|
|
73
70
|
/**
|
|
74
71
|
* Alias to {@link Context#httpclient}
|
|
75
72
|
*/
|
|
76
|
-
get httpClient():
|
|
73
|
+
get httpClient(): HttpClient {
|
|
77
74
|
return this.httpclient;
|
|
78
75
|
}
|
|
79
76
|
|
|
@@ -231,7 +228,7 @@ export default class Context extends EggCoreContext {
|
|
|
231
228
|
* });
|
|
232
229
|
* ```
|
|
233
230
|
*/
|
|
234
|
-
runInBackground(scope: (ctx:
|
|
231
|
+
runInBackground(scope: (ctx: Context) => Promise<void>, taskName?: string): void {
|
|
235
232
|
// try to use custom function name first
|
|
236
233
|
if (!taskName) {
|
|
237
234
|
taskName = Reflect.get(scope, '_name') || scope.name || utils.getCalleeFromStack(true);
|
|
@@ -244,7 +241,7 @@ export default class Context extends EggCoreContext {
|
|
|
244
241
|
|
|
245
242
|
// let plugins or frameworks to reuse _runInBackground in some cases.
|
|
246
243
|
// e.g.: https://github.com/eggjs/egg-mock/pull/78
|
|
247
|
-
async _runInBackground(scope: (ctx:
|
|
244
|
+
async _runInBackground(scope: (ctx: Context) => Promise<void>, taskName: string) {
|
|
248
245
|
const startTime = now();
|
|
249
246
|
try {
|
|
250
247
|
await scope(this as any);
|
|
@@ -258,46 +255,68 @@ export default class Context extends EggCoreContext {
|
|
|
258
255
|
this.app.emit('error', err, this);
|
|
259
256
|
}
|
|
260
257
|
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Context delegation.
|
|
265
|
-
*/
|
|
266
258
|
|
|
267
|
-
delegate(Context.prototype, 'request')
|
|
268
259
|
/**
|
|
269
260
|
* @member {Boolean} Context#acceptJSON
|
|
270
261
|
* @see Request#acceptJSON
|
|
271
262
|
* @since 1.0.0
|
|
272
263
|
*/
|
|
273
|
-
|
|
264
|
+
get acceptJSON(): boolean {
|
|
265
|
+
return this.request.acceptJSON;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
get query(): Record<string, string> {
|
|
269
|
+
return this.request.query;
|
|
270
|
+
}
|
|
271
|
+
|
|
274
272
|
/**
|
|
275
273
|
* @member {Array} Context#queries
|
|
276
274
|
* @see Request#queries
|
|
277
275
|
* @since 1.0.0
|
|
278
276
|
*/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
* @since 1.0.0
|
|
284
|
-
*/
|
|
285
|
-
.getter('accept')
|
|
277
|
+
get queries(): Record<string, string[]> {
|
|
278
|
+
return this.request.queries;
|
|
279
|
+
}
|
|
280
|
+
|
|
286
281
|
/**
|
|
287
282
|
* @member {string} Context#ip
|
|
288
283
|
* @see Request#ip
|
|
289
284
|
* @since 1.0.0
|
|
290
285
|
*/
|
|
291
|
-
|
|
286
|
+
get ip(): string {
|
|
287
|
+
return this.request.ip;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
set ip(val: string) {
|
|
291
|
+
this.request.ip = val;
|
|
292
|
+
}
|
|
292
293
|
|
|
293
|
-
delegate(Context.prototype, 'response')
|
|
294
294
|
/**
|
|
295
295
|
* @member {Number} Context#realStatus
|
|
296
296
|
* @see Response#realStatus
|
|
297
297
|
* @since 1.0.0
|
|
298
298
|
*/
|
|
299
|
-
|
|
299
|
+
get realStatus(): number {
|
|
300
|
+
return this.response.realStatus;
|
|
301
|
+
}
|
|
300
302
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
303
|
+
set realStatus(val: number) {
|
|
304
|
+
this.response.realStatus = val;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
declare module '@eggjs/core' {
|
|
309
|
+
// add Context overrides types
|
|
310
|
+
interface Context {
|
|
311
|
+
curl(url: HttpClientRequestURL, options?: HttpClientRequestOptions): ReturnType<HttpClient['request']>;
|
|
312
|
+
get router(): Router;
|
|
313
|
+
set router(val: Router);
|
|
314
|
+
get helper(): Helper;
|
|
315
|
+
get httpclient(): HttpClient;
|
|
316
|
+
get httpClient(): HttpClient;
|
|
317
|
+
getLogger(name: string): EggLogger;
|
|
318
|
+
get logger(): EggLogger;
|
|
319
|
+
get coreLogger(): EggLogger;
|
|
320
|
+
get locals(): Record<string, any>;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import querystring from 'node:querystring';
|
|
2
2
|
import { Request as EggCoreRequest } from '@eggjs/core';
|
|
3
3
|
import type { Application } from '../../lib/application.js';
|
|
4
|
-
import type
|
|
4
|
+
import type Context from './context.js';
|
|
5
5
|
import Response from './response.js';
|
|
6
6
|
|
|
7
7
|
const QUERY_CACHE = Symbol('request query cache');
|
|
@@ -13,9 +13,14 @@ const RE_ARRAY_KEY = /[^\[\]]+\[\]$/;
|
|
|
13
13
|
|
|
14
14
|
export default class Request extends EggCoreRequest {
|
|
15
15
|
declare app: Application;
|
|
16
|
-
declare ctx:
|
|
16
|
+
declare ctx: Context;
|
|
17
17
|
declare response: Response;
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Request body, parsed from koa-bodyparser or egg-multipart
|
|
21
|
+
*/
|
|
22
|
+
declare body: any;
|
|
23
|
+
|
|
19
24
|
/**
|
|
20
25
|
* Parse the "Host" header field host
|
|
21
26
|
* and support X-Forwarded-Host when a
|
|
@@ -259,6 +264,17 @@ export default class Request extends EggCoreRequest {
|
|
|
259
264
|
}
|
|
260
265
|
}
|
|
261
266
|
|
|
267
|
+
declare module '@eggjs/core' {
|
|
268
|
+
// add Request overrides types
|
|
269
|
+
interface Request {
|
|
270
|
+
body: any;
|
|
271
|
+
get acceptJSON(): boolean;
|
|
272
|
+
get query(): Record<string, string>;
|
|
273
|
+
set query(obj: Record<string, string>);
|
|
274
|
+
get queries(): Record<string, string[]>;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
262
278
|
function firstValue(value: string | string[]) {
|
|
263
279
|
if (Array.isArray(value)) {
|
|
264
280
|
value = value[0];
|
|
@@ -34,3 +34,11 @@ export default class Response extends KoaResponse {
|
|
|
34
34
|
this[REAL_STATUS] = status;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
|
|
38
|
+
declare module '@eggjs/core' {
|
|
39
|
+
// add Response overrides types
|
|
40
|
+
interface Response {
|
|
41
|
+
get realStatus(): number;
|
|
42
|
+
set realStatus(status: number);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import { performance } from 'node:perf_hooks';
|
|
6
|
-
import type {
|
|
6
|
+
import type { Context, Next } from '../../lib/egg.js';
|
|
7
7
|
|
|
8
8
|
export interface MetaMiddlewareOptions {
|
|
9
9
|
enable: boolean;
|
|
@@ -11,7 +11,7 @@ export interface MetaMiddlewareOptions {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export default (options: MetaMiddlewareOptions) => {
|
|
14
|
-
return async function meta(ctx:
|
|
14
|
+
return async function meta(ctx: Context, next: Next) {
|
|
15
15
|
if (options.logging) {
|
|
16
16
|
ctx.coreLogger.info('[meta] request started, host: %s, user-agent: %s',
|
|
17
17
|
ctx.host, ctx.header['user-agent']);
|