egg 4.0.9 → 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 -56
- 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 -56
- 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 -296
- 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,145 @@
|
|
|
1
|
+
import { Application } from "../../lib/application.js";
|
|
2
|
+
import Response$1 from "./response.js";
|
|
3
|
+
import Context$1 from "./context.js";
|
|
4
|
+
import { Request as Request$1 } from "@eggjs/core";
|
|
5
|
+
|
|
6
|
+
//#region src/app/extend/request.d.ts
|
|
7
|
+
declare class Request extends Request$1 {
|
|
8
|
+
app: Application;
|
|
9
|
+
ctx: Context$1;
|
|
10
|
+
response: Response$1;
|
|
11
|
+
/**
|
|
12
|
+
* Request body, parsed from koa-bodyparser or @eggjs/multipart
|
|
13
|
+
*/
|
|
14
|
+
body: any;
|
|
15
|
+
/**
|
|
16
|
+
* Parse the "Host" header field host
|
|
17
|
+
* and support X-Forwarded-Host when a
|
|
18
|
+
* proxy is enabled.
|
|
19
|
+
* @member {String} Request#host
|
|
20
|
+
* @example
|
|
21
|
+
* ip + port
|
|
22
|
+
* ```js
|
|
23
|
+
* this.request.host
|
|
24
|
+
* => '127.0.0.1:7001'
|
|
25
|
+
* ```
|
|
26
|
+
* or domain
|
|
27
|
+
* ```js
|
|
28
|
+
* this.request.host
|
|
29
|
+
* => 'demo.eggjs.org'
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
get host(): string;
|
|
33
|
+
/**
|
|
34
|
+
* @member {String} Request#protocol
|
|
35
|
+
* @example
|
|
36
|
+
* ```js
|
|
37
|
+
* this.request.protocol
|
|
38
|
+
* => 'https'
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
get protocol(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get all pass through ip addresses from the request.
|
|
44
|
+
* Enable only on `app.config.proxy = true`
|
|
45
|
+
*
|
|
46
|
+
* @member {Array} Request#ips
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* this.request.ips
|
|
50
|
+
* => ['100.23.1.2', '201.10.10.2']
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
get ips(): string[];
|
|
54
|
+
/**
|
|
55
|
+
* Get the request remote IPv4 address
|
|
56
|
+
* @member {String} Request#ip
|
|
57
|
+
* @return {String} IPv4 address
|
|
58
|
+
* @example
|
|
59
|
+
* ```js
|
|
60
|
+
* this.request.ip
|
|
61
|
+
* => '127.0.0.1'
|
|
62
|
+
* => '111.10.2.1'
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
get ip(): string;
|
|
66
|
+
/**
|
|
67
|
+
* Set the request remote IPv4 address
|
|
68
|
+
* @member {String} Request#ip
|
|
69
|
+
* @param {String} ip - IPv4 address
|
|
70
|
+
* @example
|
|
71
|
+
* ```js
|
|
72
|
+
* this.request.ip
|
|
73
|
+
* => '127.0.0.1'
|
|
74
|
+
* => '111.10.2.1'
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
set ip(ip: string);
|
|
78
|
+
/**
|
|
79
|
+
* detect if response should be json
|
|
80
|
+
* 1. url path ends with `.json`
|
|
81
|
+
* 2. response type is set to json
|
|
82
|
+
* 3. detect by request accept header
|
|
83
|
+
*
|
|
84
|
+
* @member {Boolean} Request#acceptJSON
|
|
85
|
+
* @since 1.0.0
|
|
86
|
+
*/
|
|
87
|
+
get acceptJSON(): boolean;
|
|
88
|
+
_customQuery(cacheName: symbol, filter: (value: string | string[]) => string | string[]): Record<string, string | string[]>;
|
|
89
|
+
/**
|
|
90
|
+
* get params pass by querystring, all values are of string type.
|
|
91
|
+
* @member {Object} Request#query
|
|
92
|
+
* @example
|
|
93
|
+
* ```js
|
|
94
|
+
* GET http://127.0.0.1:7001?name=Foo&age=20&age=21
|
|
95
|
+
* this.query
|
|
96
|
+
* => { 'name': 'Foo', 'age': '20' }
|
|
97
|
+
*
|
|
98
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
99
|
+
* this.query
|
|
100
|
+
* =>
|
|
101
|
+
* {
|
|
102
|
+
* "a": "b",
|
|
103
|
+
* "o[foo]": "bar",
|
|
104
|
+
* "b[]": "1",
|
|
105
|
+
* "e": "val"
|
|
106
|
+
* }
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
get query(): Record<string, string>;
|
|
110
|
+
/**
|
|
111
|
+
* get params pass by querystring, all value are Array type. {@link Request#query}
|
|
112
|
+
* @member {Array} Request#queries
|
|
113
|
+
* @example
|
|
114
|
+
* ```js
|
|
115
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
116
|
+
* this.queries
|
|
117
|
+
* =>
|
|
118
|
+
* {
|
|
119
|
+
* "a": ["b", "c"],
|
|
120
|
+
* "o[foo]": ["bar"],
|
|
121
|
+
* "b[]": ["1", "2"],
|
|
122
|
+
* "e": ["val"]
|
|
123
|
+
* }
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
get queries(): Record<string, string[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Set query-string as an object.
|
|
129
|
+
*
|
|
130
|
+
* @function Request#query
|
|
131
|
+
* @param {Object} obj set querystring and query object for request.
|
|
132
|
+
*/
|
|
133
|
+
set query(obj: Record<string, string>);
|
|
134
|
+
}
|
|
135
|
+
declare module '@eggjs/core' {
|
|
136
|
+
interface Request {
|
|
137
|
+
body: any;
|
|
138
|
+
get acceptJSON(): boolean;
|
|
139
|
+
get query(): Record<string, string>;
|
|
140
|
+
set query(obj: Record<string, string>);
|
|
141
|
+
get queries(): Record<string, string[]>;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
export { Request as default };
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import "./response.js";
|
|
2
|
+
import { Request as Request$1 } from "@eggjs/core";
|
|
3
|
+
import querystring from "node:querystring";
|
|
4
|
+
|
|
5
|
+
//#region src/app/extend/request.ts
|
|
6
|
+
const QUERY_CACHE = Symbol("request query cache");
|
|
7
|
+
const QUERIES_CACHE = Symbol("request queries cache");
|
|
8
|
+
const PROTOCOL = Symbol("request protocol");
|
|
9
|
+
const HOST = Symbol("request host");
|
|
10
|
+
const IPS = Symbol("request ips");
|
|
11
|
+
const RE_ARRAY_KEY = /[^[\]]+\[\]$/;
|
|
12
|
+
var Request = class extends Request$1 {
|
|
13
|
+
/**
|
|
14
|
+
* Parse the "Host" header field host
|
|
15
|
+
* and support X-Forwarded-Host when a
|
|
16
|
+
* proxy is enabled.
|
|
17
|
+
* @member {String} Request#host
|
|
18
|
+
* @example
|
|
19
|
+
* ip + port
|
|
20
|
+
* ```js
|
|
21
|
+
* this.request.host
|
|
22
|
+
* => '127.0.0.1:7001'
|
|
23
|
+
* ```
|
|
24
|
+
* or domain
|
|
25
|
+
* ```js
|
|
26
|
+
* this.request.host
|
|
27
|
+
* => 'demo.eggjs.org'
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
get host() {
|
|
31
|
+
let host = this[HOST];
|
|
32
|
+
if (host) return host;
|
|
33
|
+
if (this.app.config.proxy) host = getFromHeaders(this, this.app.config.hostHeaders);
|
|
34
|
+
host = host || this.get("host") || "";
|
|
35
|
+
this[HOST] = host = host.split(",")[0].trim();
|
|
36
|
+
return host;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @member {String} Request#protocol
|
|
40
|
+
* @example
|
|
41
|
+
* ```js
|
|
42
|
+
* this.request.protocol
|
|
43
|
+
* => 'https'
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
get protocol() {
|
|
47
|
+
let protocol = this[PROTOCOL];
|
|
48
|
+
if (protocol) return protocol;
|
|
49
|
+
if (this.socket?.encrypted) {
|
|
50
|
+
this[PROTOCOL] = protocol = "https";
|
|
51
|
+
return protocol;
|
|
52
|
+
}
|
|
53
|
+
if (this.app.config.proxy) {
|
|
54
|
+
const proto = getFromHeaders(this, this.app.config.protocolHeaders);
|
|
55
|
+
if (proto) {
|
|
56
|
+
this[PROTOCOL] = protocol = proto.split(/\s*,\s*/)[0];
|
|
57
|
+
return protocol;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
this[PROTOCOL] = protocol = this.app.config.protocol || "http";
|
|
61
|
+
return protocol;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get all pass through ip addresses from the request.
|
|
65
|
+
* Enable only on `app.config.proxy = true`
|
|
66
|
+
*
|
|
67
|
+
* @member {Array} Request#ips
|
|
68
|
+
* @example
|
|
69
|
+
* ```js
|
|
70
|
+
* this.request.ips
|
|
71
|
+
* => ['100.23.1.2', '201.10.10.2']
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
get ips() {
|
|
75
|
+
let ips = this[IPS];
|
|
76
|
+
if (ips) return ips;
|
|
77
|
+
if (!this.app.config.proxy) {
|
|
78
|
+
this[IPS] = ips = [];
|
|
79
|
+
return ips;
|
|
80
|
+
}
|
|
81
|
+
const val = getFromHeaders(this, this.app.config.ipHeaders);
|
|
82
|
+
this[IPS] = ips = val ? val.split(/\s*,\s*/) : [];
|
|
83
|
+
let maxIpsCount = this.app.config.maxIpsCount;
|
|
84
|
+
if (!maxIpsCount && this.app.config.maxProxyCount) maxIpsCount = this.app.config.maxProxyCount + 1;
|
|
85
|
+
if (maxIpsCount > 0) this[IPS] = ips = ips.slice(-maxIpsCount);
|
|
86
|
+
return ips;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Get the request remote IPv4 address
|
|
90
|
+
* @member {String} Request#ip
|
|
91
|
+
* @return {String} IPv4 address
|
|
92
|
+
* @example
|
|
93
|
+
* ```js
|
|
94
|
+
* this.request.ip
|
|
95
|
+
* => '127.0.0.1'
|
|
96
|
+
* => '111.10.2.1'
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
get ip() {
|
|
100
|
+
if (this._ip) return this._ip;
|
|
101
|
+
const ip = this.ips[0] ?? this.socket.remoteAddress;
|
|
102
|
+
this._ip = ip && ip.startsWith("::ffff:") ? ip.substring(7) : ip;
|
|
103
|
+
return this._ip;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Set the request remote IPv4 address
|
|
107
|
+
* @member {String} Request#ip
|
|
108
|
+
* @param {String} ip - IPv4 address
|
|
109
|
+
* @example
|
|
110
|
+
* ```js
|
|
111
|
+
* this.request.ip
|
|
112
|
+
* => '127.0.0.1'
|
|
113
|
+
* => '111.10.2.1'
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
set ip(ip) {
|
|
117
|
+
this._ip = ip;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* detect if response should be json
|
|
121
|
+
* 1. url path ends with `.json`
|
|
122
|
+
* 2. response type is set to json
|
|
123
|
+
* 3. detect by request accept header
|
|
124
|
+
*
|
|
125
|
+
* @member {Boolean} Request#acceptJSON
|
|
126
|
+
* @since 1.0.0
|
|
127
|
+
*/
|
|
128
|
+
get acceptJSON() {
|
|
129
|
+
if (this.path.endsWith(".json")) return true;
|
|
130
|
+
if (this.response.type && this.response.type.indexOf("json") >= 0) return true;
|
|
131
|
+
if (this.accepts("html", "text", "json") === "json") return true;
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
_customQuery(cacheName, filter) {
|
|
135
|
+
const str = this.querystring || "";
|
|
136
|
+
let c = this[cacheName];
|
|
137
|
+
if (!c) c = this[cacheName] = {};
|
|
138
|
+
let cacheQuery = c[str];
|
|
139
|
+
if (!cacheQuery) {
|
|
140
|
+
cacheQuery = c[str] = {};
|
|
141
|
+
const isQueries = cacheName === QUERIES_CACHE;
|
|
142
|
+
const query = str ? querystring.parse(str) : {};
|
|
143
|
+
for (const key in query) {
|
|
144
|
+
if (!key) continue;
|
|
145
|
+
const value = filter(query[key]);
|
|
146
|
+
cacheQuery[key] = value;
|
|
147
|
+
if (isQueries && RE_ARRAY_KEY.test(key)) {
|
|
148
|
+
const subKey = key.substring(0, key.length - 2);
|
|
149
|
+
if (!cacheQuery[subKey]) cacheQuery[subKey] = value;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return cacheQuery;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* get params pass by querystring, all values are of string type.
|
|
157
|
+
* @member {Object} Request#query
|
|
158
|
+
* @example
|
|
159
|
+
* ```js
|
|
160
|
+
* GET http://127.0.0.1:7001?name=Foo&age=20&age=21
|
|
161
|
+
* this.query
|
|
162
|
+
* => { 'name': 'Foo', 'age': '20' }
|
|
163
|
+
*
|
|
164
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
165
|
+
* this.query
|
|
166
|
+
* =>
|
|
167
|
+
* {
|
|
168
|
+
* "a": "b",
|
|
169
|
+
* "o[foo]": "bar",
|
|
170
|
+
* "b[]": "1",
|
|
171
|
+
* "e": "val"
|
|
172
|
+
* }
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
get query() {
|
|
176
|
+
return this._customQuery(QUERY_CACHE, firstValue);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* get params pass by querystring, all value are Array type. {@link Request#query}
|
|
180
|
+
* @member {Array} Request#queries
|
|
181
|
+
* @example
|
|
182
|
+
* ```js
|
|
183
|
+
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
184
|
+
* this.queries
|
|
185
|
+
* =>
|
|
186
|
+
* {
|
|
187
|
+
* "a": ["b", "c"],
|
|
188
|
+
* "o[foo]": ["bar"],
|
|
189
|
+
* "b[]": ["1", "2"],
|
|
190
|
+
* "e": ["val"]
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
get queries() {
|
|
195
|
+
return this._customQuery(QUERIES_CACHE, arrayValue);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Set query-string as an object.
|
|
199
|
+
*
|
|
200
|
+
* @function Request#query
|
|
201
|
+
* @param {Object} obj set querystring and query object for request.
|
|
202
|
+
*/
|
|
203
|
+
set query(obj) {
|
|
204
|
+
this.querystring = querystring.stringify(obj);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
function firstValue(value) {
|
|
208
|
+
if (Array.isArray(value)) value = value[0];
|
|
209
|
+
return value;
|
|
210
|
+
}
|
|
211
|
+
function arrayValue(value) {
|
|
212
|
+
if (!Array.isArray(value)) value = [value];
|
|
213
|
+
return value;
|
|
214
|
+
}
|
|
215
|
+
function getFromHeaders(request, names) {
|
|
216
|
+
if (!names) return "";
|
|
217
|
+
const fields = names.split(/\s*,\s*/);
|
|
218
|
+
for (const name of fields) {
|
|
219
|
+
const value = request.get(name);
|
|
220
|
+
if (value) return value;
|
|
221
|
+
}
|
|
222
|
+
return "";
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
//#endregion
|
|
226
|
+
export { Request as default };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { Response as
|
|
1
|
+
import { Response as Response$1 } from "@eggjs/core";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export default class Response extends KoaResponse {
|
|
3
|
+
//#region src/app/extend/response.d.ts
|
|
4
|
+
declare class Response extends Response$1 {
|
|
6
5
|
/**
|
|
7
6
|
* Get or set a real status code.
|
|
8
7
|
*
|
|
@@ -13,13 +12,7 @@ export default class Response extends KoaResponse {
|
|
|
13
12
|
* @member {Number} Response#realStatus
|
|
14
13
|
* @return {Number} The status code to be set.
|
|
15
14
|
*/
|
|
16
|
-
get realStatus(): number
|
|
17
|
-
if (this[REAL_STATUS]) {
|
|
18
|
-
return this[REAL_STATUS] as number;
|
|
19
|
-
}
|
|
20
|
-
return this.status;
|
|
21
|
-
}
|
|
22
|
-
|
|
15
|
+
get realStatus(): number;
|
|
23
16
|
/**
|
|
24
17
|
* Set a real status code.
|
|
25
18
|
*
|
|
@@ -30,15 +23,13 @@ export default class Response extends KoaResponse {
|
|
|
30
23
|
* @member {Number} Response#realStatus
|
|
31
24
|
* @param {Number} status The status code to be set.
|
|
32
25
|
*/
|
|
33
|
-
set realStatus(status: number)
|
|
34
|
-
this[REAL_STATUS] = status;
|
|
35
|
-
}
|
|
26
|
+
set realStatus(status: number);
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
declare module '@eggjs/core' {
|
|
39
|
-
// add Response overrides types
|
|
40
29
|
interface Response {
|
|
41
30
|
get realStatus(): number;
|
|
42
31
|
set realStatus(status: number);
|
|
43
32
|
}
|
|
44
33
|
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { Response as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Response as Response$1 } from "@eggjs/core";
|
|
2
|
+
|
|
3
|
+
//#region src/app/extend/response.ts
|
|
4
|
+
const REAL_STATUS = Symbol("response realStatus");
|
|
5
|
+
var Response = class extends Response$1 {
|
|
6
|
+
/**
|
|
7
|
+
* Get or set a real status code.
|
|
8
|
+
*
|
|
9
|
+
* e.g.: Using 302 status redirect to the global error page
|
|
10
|
+
* instead of show current 500 status page.
|
|
11
|
+
* And access log should save 500 not 302,
|
|
12
|
+
* then the `realStatus` can help us find out the real status code.
|
|
13
|
+
* @member {Number} Response#realStatus
|
|
14
|
+
* @return {Number} The status code to be set.
|
|
15
|
+
*/
|
|
16
|
+
get realStatus() {
|
|
17
|
+
if (this[REAL_STATUS]) return this[REAL_STATUS];
|
|
18
|
+
return this.status;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Set a real status code.
|
|
22
|
+
*
|
|
23
|
+
* e.g.: Using 302 status redirect to the global error page
|
|
24
|
+
* instead of show current 500 status page.
|
|
25
|
+
* And access log should save 500 not 302,
|
|
26
|
+
* then the `realStatus` can help us find out the real status code.
|
|
27
|
+
* @member {Number} Response#realStatus
|
|
28
|
+
* @param {Number} status The status code to be set.
|
|
29
|
+
*/
|
|
30
|
+
set realStatus(status) {
|
|
31
|
+
this[REAL_STATUS] = status;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { Response as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Context from "../extend/context.js";
|
|
2
|
+
import { Next } from "../../lib/egg.js";
|
|
3
|
+
|
|
4
|
+
//#region src/app/middleware/meta.d.ts
|
|
5
|
+
interface MetaMiddlewareOptions {
|
|
6
|
+
enable: boolean;
|
|
7
|
+
logging: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (options: MetaMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { MetaMiddlewareOptions, _default as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { performance } from "node:perf_hooks";
|
|
2
|
+
|
|
3
|
+
//#region src/app/middleware/meta.ts
|
|
4
|
+
var meta_default = (options) => {
|
|
5
|
+
return async function meta(ctx, next) {
|
|
6
|
+
if (options.logging) ctx.coreLogger.info("[meta] request started, host: %s, user-agent: %s", ctx.host, ctx.header["user-agent"]);
|
|
7
|
+
await next();
|
|
8
|
+
if (ctx.performanceStarttime) ctx.set("x-readtime", Math.floor((performance.now() - ctx.performanceStarttime) * 1e3) / 1e3);
|
|
9
|
+
else ctx.set("x-readtime", Date.now() - ctx.starttime);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { meta_default as default };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Context from "../extend/context.js";
|
|
2
|
+
import { Next } from "../../lib/egg.js";
|
|
3
|
+
|
|
4
|
+
//#region src/app/middleware/notfound.d.ts
|
|
5
|
+
interface NotFoundMiddlewareOptions {
|
|
6
|
+
enable: boolean;
|
|
7
|
+
pageUrl: string;
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (options: NotFoundMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { NotFoundMiddlewareOptions, _default as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region src/app/middleware/notfound.ts
|
|
2
|
+
var notfound_default = (options) => {
|
|
3
|
+
return async function notfound(ctx, next) {
|
|
4
|
+
await next();
|
|
5
|
+
if (ctx.status !== 404 || ctx.body) return;
|
|
6
|
+
ctx.status = 404;
|
|
7
|
+
if (ctx.acceptJSON) {
|
|
8
|
+
ctx.body = { message: "Not Found" };
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const notFoundHtml = "<h1>404 Not Found</h1>";
|
|
12
|
+
if (options.pageUrl && ctx.path === options.pageUrl) {
|
|
13
|
+
ctx.body = `${notFoundHtml}<p><pre><code>config.notfound.pageUrl(${options.pageUrl})</code></pre> is unimplemented</p>`;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (options.pageUrl) {
|
|
17
|
+
ctx.realStatus = 404;
|
|
18
|
+
ctx.redirect(options.pageUrl);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
ctx.body = notFoundHtml;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { notfound_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Context from "../extend/context.js";
|
|
2
|
+
import { Next } from "../../lib/egg.js";
|
|
3
|
+
|
|
4
|
+
//#region src/app/middleware/site_file.d.ts
|
|
5
|
+
type SiteFileContentFun = (ctx: Context) => Promise<Buffer | string>;
|
|
6
|
+
interface SiteFileMiddlewareOptions {
|
|
7
|
+
enable: boolean;
|
|
8
|
+
cacheControl: string;
|
|
9
|
+
[key: string]: string | Buffer | boolean | SiteFileContentFun | URL;
|
|
10
|
+
}
|
|
11
|
+
declare const _default: (options: SiteFileMiddlewareOptions) => (ctx: Context, next: Next) => Promise<void>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { SiteFileContentFun, SiteFileMiddlewareOptions, _default as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
|
|
5
|
+
//#region src/app/middleware/site_file.ts
|
|
6
|
+
const BUFFER_CACHE = Symbol("siteFile URL buffer cache");
|
|
7
|
+
var site_file_default = (options) => {
|
|
8
|
+
return async function siteFile(ctx, next) {
|
|
9
|
+
if (ctx.method !== "HEAD" && ctx.method !== "GET") return next();
|
|
10
|
+
if (ctx.path[0] !== "/") return next();
|
|
11
|
+
let content = options[ctx.path];
|
|
12
|
+
if (!content) return next();
|
|
13
|
+
if (typeof content === "function") content = await content(ctx);
|
|
14
|
+
if (typeof content === "string") return ctx.redirect(content);
|
|
15
|
+
if (content instanceof URL) {
|
|
16
|
+
if (content.protocol !== "file:") return ctx.redirect(content.href);
|
|
17
|
+
let buffer = Reflect.get(content, BUFFER_CACHE);
|
|
18
|
+
if (!buffer) {
|
|
19
|
+
buffer = await readFile(fileURLToPath(content));
|
|
20
|
+
Reflect.set(content, BUFFER_CACHE, buffer);
|
|
21
|
+
}
|
|
22
|
+
ctx.set("cache-control", options.cacheControl);
|
|
23
|
+
ctx.body = content;
|
|
24
|
+
ctx.type = path.extname(ctx.path);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (Buffer.isBuffer(content)) {
|
|
28
|
+
ctx.set("cache-control", options.cacheControl);
|
|
29
|
+
ctx.body = content;
|
|
30
|
+
ctx.type = path.extname(ctx.path);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
return next();
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { site_file_default as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EggAppInfo, PartialEggConfig } from "../lib/types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/config/config.default.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The configuration of egg application, can be access by `app.config`
|
|
7
|
+
* @class Config
|
|
8
|
+
* @since 1.0.0
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: (appInfo: EggAppInfo) => PartialEggConfig;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { _default as default };
|