egg 4.1.0-beta.35 → 4.1.0-beta.36
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/agent.d.ts +7 -3
- package/dist/agent.js +10 -6
- package/dist/ajv.d.ts +1 -1
- package/dist/ajv.js +3 -2
- package/dist/aop.d.ts +1 -1
- package/dist/aop.js +3 -2
- package/dist/app/extend/context.d.ts +181 -178
- package/dist/app/extend/context.js +244 -259
- package/dist/app/extend/helper.d.ts +40 -35
- package/dist/app/extend/helper.js +45 -41
- package/dist/app/extend/request.d.ts +135 -131
- package/dist/app/extend/request.js +219 -258
- package/dist/app/extend/response.d.ts +28 -24
- package/dist/app/extend/response.js +36 -34
- package/dist/app/middleware/body_parser.d.ts +2 -2
- package/dist/app/middleware/body_parser.js +7 -3
- package/dist/app/middleware/meta.d.ts +8 -8
- package/dist/app/middleware/meta.js +15 -18
- package/dist/app/middleware/notfound.d.ts +8 -5
- package/dist/app/middleware/notfound.js +25 -28
- package/dist/app/middleware/override_method.d.ts +2 -2
- package/dist/app/middleware/override_method.js +7 -3
- package/dist/app/middleware/site_file.d.ts +11 -7
- package/dist/app/middleware/site_file.js +37 -52
- package/dist/config/config.default.d.ts +11 -6
- package/dist/config/config.default.js +258 -375
- package/dist/config/config.local.d.ts +6 -3
- package/dist/config/config.local.js +7 -8
- package/dist/config/config.unittest.d.ts +6 -3
- package/dist/config/config.unittest.js +10 -8
- package/dist/config/plugin.d.ts +6 -2
- package/dist/config/plugin.js +67 -131
- package/dist/dal.d.ts +1 -1
- package/dist/dal.js +3 -2
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +3 -2
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +3 -2
- package/dist/index.d.ts +24 -106
- package/dist/index.js +23 -89
- package/dist/lib/agent.d.ts +21 -15
- package/dist/lib/agent.js +53 -45
- package/dist/lib/application.d.ts +60 -54
- package/dist/lib/application.js +199 -249
- package/dist/lib/core/base_context_class.d.ts +23 -17
- package/dist/lib/core/base_context_class.js +17 -15
- package/dist/lib/core/base_context_logger.d.ts +39 -35
- package/dist/lib/core/base_context_logger.js +58 -60
- package/dist/lib/core/base_hook_class.d.ts +18 -11
- package/dist/lib/core/base_hook_class.js +26 -22
- package/dist/lib/core/context_httpclient.d.ts +21 -16
- package/dist/lib/core/context_httpclient.js +29 -26
- package/dist/lib/core/httpclient.d.ts +14 -12
- package/dist/lib/core/httpclient.js +34 -37
- package/dist/lib/core/logger.d.ts +7 -3
- package/dist/lib/core/logger.js +30 -36
- package/dist/lib/core/messenger/IMessenger.d.ts +53 -49
- package/dist/lib/core/messenger/IMessenger.js +1 -2
- package/dist/lib/core/messenger/base.d.ts +11 -7
- package/dist/lib/core/messenger/base.js +30 -29
- package/dist/lib/core/messenger/index.d.ts +10 -6
- package/dist/lib/core/messenger/index.js +11 -8
- package/dist/lib/core/messenger/ipc.d.ts +62 -57
- package/dist/lib/core/messenger/ipc.js +126 -138
- package/dist/lib/core/messenger/local.d.ts +63 -58
- package/dist/lib/core/messenger/local.js +126 -131
- package/dist/lib/core/utils.d.ts +5 -2
- package/dist/lib/core/utils.js +44 -66
- package/dist/lib/define.d.ts +72 -67
- package/dist/lib/define.js +54 -53
- package/dist/lib/egg.d.ts +283 -281
- package/dist/lib/egg.js +512 -573
- package/dist/lib/error/CookieLimitExceedError.d.ts +7 -4
- package/dist/lib/error/CookieLimitExceedError.js +15 -12
- package/dist/lib/error/MessageUnhandledRejectionError.d.ts +7 -4
- package/dist/lib/error/MessageUnhandledRejectionError.js +15 -12
- package/dist/lib/error/index.d.ts +3 -2
- package/dist/lib/error/index.js +4 -3
- package/dist/lib/loader/AgentWorkerLoader.d.ts +15 -10
- package/dist/lib/loader/AgentWorkerLoader.js +22 -18
- package/dist/lib/loader/AppWorkerLoader.d.ts +20 -15
- package/dist/lib/loader/AppWorkerLoader.js +35 -37
- package/dist/lib/loader/EggApplicationLoader.d.ts +7 -3
- package/dist/lib/loader/EggApplicationLoader.js +7 -4
- package/dist/lib/loader/index.d.ts +4 -3
- package/dist/lib/loader/index.js +5 -4
- package/dist/lib/start.d.ts +24 -20
- package/dist/lib/start.js +32 -42
- package/dist/lib/types.d.ts +288 -286
- package/dist/lib/types.js +2 -2
- package/dist/lib/types.plugin.d.ts +21 -21
- package/dist/lib/types.plugin.js +23 -24
- package/dist/orm.d.ts +1 -1
- package/dist/orm.js +3 -2
- package/dist/schedule.d.ts +2 -2
- package/dist/schedule.js +5 -5
- package/dist/transaction.d.ts +1 -1
- package/dist/transaction.js +3 -2
- package/dist/urllib.d.ts +1 -1
- package/dist/urllib.js +3 -2
- package/package.json +60 -64
|
@@ -1,265 +1,226 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Request as
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
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");
|
|
9
11
|
const RE_ARRAY_KEY = /[^[\]]+\[\]$/;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
* "b[]": "1",
|
|
206
|
-
* "e": "val"
|
|
207
|
-
* }
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
get query() {
|
|
211
|
-
return this._customQuery(QUERY_CACHE, firstValue);
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* get params pass by querystring, all value are Array type. {@link Request#query}
|
|
215
|
-
* @member {Array} Request#queries
|
|
216
|
-
* @example
|
|
217
|
-
* ```js
|
|
218
|
-
* GET http://127.0.0.1:7001?a=b&a=c&o[foo]=bar&b[]=1&b[]=2&e=val
|
|
219
|
-
* this.queries
|
|
220
|
-
* =>
|
|
221
|
-
* {
|
|
222
|
-
* "a": ["b", "c"],
|
|
223
|
-
* "o[foo]": ["bar"],
|
|
224
|
-
* "b[]": ["1", "2"],
|
|
225
|
-
* "e": ["val"]
|
|
226
|
-
* }
|
|
227
|
-
* ```
|
|
228
|
-
*/
|
|
229
|
-
get queries() {
|
|
230
|
-
return this._customQuery(QUERIES_CACHE, arrayValue);
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Set query-string as an object.
|
|
234
|
-
*
|
|
235
|
-
* @function Request#query
|
|
236
|
-
* @param {Object} obj set querystring and query object for request.
|
|
237
|
-
*/
|
|
238
|
-
set query(obj) {
|
|
239
|
-
this.querystring = querystring.stringify(obj);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
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
|
+
};
|
|
242
207
|
function firstValue(value) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
return value;
|
|
208
|
+
if (Array.isArray(value)) value = value[0];
|
|
209
|
+
return value;
|
|
247
210
|
}
|
|
248
211
|
function arrayValue(value) {
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
return value;
|
|
212
|
+
if (!Array.isArray(value)) value = [value];
|
|
213
|
+
return value;
|
|
253
214
|
}
|
|
254
215
|
function getFromHeaders(request, names) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
}
|
|
263
|
-
return '';
|
|
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 "";
|
|
264
223
|
}
|
|
265
|
-
|
|
224
|
+
|
|
225
|
+
//#endregion
|
|
226
|
+
export { Request as default };
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { Response as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
1
|
+
import { Response as Response$1 } from "@eggjs/core";
|
|
2
|
+
|
|
3
|
+
//#region src/app/extend/response.d.ts
|
|
4
|
+
declare class Response extends Response$1 {
|
|
5
|
+
/**
|
|
6
|
+
* Get or set a real status code.
|
|
7
|
+
*
|
|
8
|
+
* e.g.: Using 302 status redirect to the global error page
|
|
9
|
+
* instead of show current 500 status page.
|
|
10
|
+
* And access log should save 500 not 302,
|
|
11
|
+
* then the `realStatus` can help us find out the real status code.
|
|
12
|
+
* @member {Number} Response#realStatus
|
|
13
|
+
* @return {Number} The status code to be set.
|
|
14
|
+
*/
|
|
15
|
+
get realStatus(): number;
|
|
16
|
+
/**
|
|
17
|
+
* Set a real status code.
|
|
18
|
+
*
|
|
19
|
+
* e.g.: Using 302 status redirect to the global error page
|
|
20
|
+
* instead of show current 500 status page.
|
|
21
|
+
* And access log should save 500 not 302,
|
|
22
|
+
* then the `realStatus` can help us find out the real status code.
|
|
23
|
+
* @member {Number} Response#realStatus
|
|
24
|
+
* @param {Number} status The status code to be set.
|
|
25
|
+
*/
|
|
26
|
+
set realStatus(status: number);
|
|
25
27
|
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Response as default };
|
|
@@ -1,34 +1,36 @@
|
|
|
1
|
-
import { Response as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
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 };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import bodyparser from
|
|
2
|
-
export default
|
|
1
|
+
import bodyparser from "koa-bodyparser";
|
|
2
|
+
export { bodyparser as default };
|