egg 4.1.0-beta.2 → 4.1.0-beta.21

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.
Files changed (86) hide show
  1. package/dist/agent.d.ts +3 -7
  2. package/dist/agent.js +6 -10
  3. package/dist/app/extend/context.d.ts +166 -193
  4. package/dist/app/extend/context.js +259 -244
  5. package/dist/app/extend/helper.d.ts +31 -36
  6. package/dist/app/extend/helper.js +41 -45
  7. package/dist/app/extend/request.d.ts +127 -140
  8. package/dist/app/extend/request.js +258 -219
  9. package/dist/app/extend/response.d.ts +22 -32
  10. package/dist/app/extend/response.js +34 -36
  11. package/dist/app/middleware/body_parser.d.ts +2 -2
  12. package/dist/app/middleware/body_parser.js +3 -7
  13. package/dist/app/middleware/meta.d.ts +8 -9
  14. package/dist/app/middleware/meta.js +19 -13
  15. package/dist/app/middleware/notfound.d.ts +5 -9
  16. package/dist/app/middleware/notfound.js +28 -25
  17. package/dist/app/middleware/override_method.d.ts +2 -2
  18. package/dist/app/middleware/override_method.js +3 -7
  19. package/dist/app/middleware/site_file.d.ts +7 -11
  20. package/dist/app/middleware/site_file.js +52 -37
  21. package/dist/config/config.default.d.ts +2 -8
  22. package/dist/config/config.default.js +376 -256
  23. package/dist/config/config.local.d.ts +5 -7
  24. package/dist/config/config.local.js +9 -6
  25. package/dist/config/config.unittest.d.ts +5 -7
  26. package/dist/config/config.unittest.js +8 -9
  27. package/dist/config/favicon.png +0 -0
  28. package/dist/config/plugin.d.ts +120 -122
  29. package/dist/config/plugin.js +121 -53
  30. package/dist/index.d.ts +66 -19
  31. package/dist/index.js +68 -19
  32. package/dist/lib/agent.d.ts +13 -16
  33. package/dist/lib/agent.js +46 -54
  34. package/dist/lib/application.d.ts +46 -61
  35. package/dist/lib/application.js +249 -197
  36. package/dist/lib/core/base_context_class.d.ts +12 -17
  37. package/dist/lib/core/base_context_class.js +15 -17
  38. package/dist/lib/core/base_context_logger.d.ts +35 -39
  39. package/dist/lib/core/base_context_logger.js +60 -58
  40. package/dist/lib/core/base_hook_class.d.ts +10 -17
  41. package/dist/lib/core/base_hook_class.js +22 -26
  42. package/dist/lib/core/context_httpclient.d.ts +16 -20
  43. package/dist/lib/core/context_httpclient.js +26 -29
  44. package/dist/lib/core/httpclient.d.ts +12 -15
  45. package/dist/lib/core/httpclient.js +37 -34
  46. package/dist/lib/core/logger.d.ts +3 -7
  47. package/dist/lib/core/logger.js +36 -30
  48. package/dist/lib/core/messenger/IMessenger.d.ts +49 -53
  49. package/dist/lib/core/messenger/IMessenger.js +2 -1
  50. package/dist/lib/core/messenger/base.d.ts +7 -11
  51. package/dist/lib/core/messenger/base.js +28 -29
  52. package/dist/lib/core/messenger/index.d.ts +4 -8
  53. package/dist/lib/core/messenger/index.js +8 -11
  54. package/dist/lib/core/messenger/ipc.d.ts +55 -59
  55. package/dist/lib/core/messenger/ipc.js +149 -120
  56. package/dist/lib/core/messenger/local.d.ts +56 -61
  57. package/dist/lib/core/messenger/local.js +126 -124
  58. package/dist/lib/core/utils.d.ts +2 -5
  59. package/dist/lib/core/utils.js +66 -44
  60. package/dist/lib/egg.d.ts +271 -292
  61. package/dist/lib/egg.js +576 -506
  62. package/dist/lib/error/CookieLimitExceedError.d.ts +4 -7
  63. package/dist/lib/error/CookieLimitExceedError.js +12 -15
  64. package/dist/lib/error/MessageUnhandledRejectionError.d.ts +4 -7
  65. package/dist/lib/error/MessageUnhandledRejectionError.js +12 -15
  66. package/dist/lib/error/index.d.ts +2 -3
  67. package/dist/lib/error/index.js +3 -4
  68. package/dist/lib/loader/AgentWorkerLoader.d.ts +7 -12
  69. package/dist/lib/loader/AgentWorkerLoader.js +18 -22
  70. package/dist/lib/loader/AppWorkerLoader.d.ts +12 -17
  71. package/dist/lib/loader/AppWorkerLoader.js +37 -35
  72. package/dist/lib/loader/EggApplicationLoader.d.ts +3 -7
  73. package/dist/lib/loader/EggApplicationLoader.js +4 -7
  74. package/dist/lib/loader/index.d.ts +3 -4
  75. package/dist/lib/loader/index.js +4 -5
  76. package/dist/lib/start.d.ts +18 -22
  77. package/dist/lib/start.js +42 -32
  78. package/dist/lib/types.d.ts +252 -230
  79. package/dist/lib/types.js +31 -14
  80. package/dist/lib/types.plugin.d.ts +12 -0
  81. package/dist/lib/types.plugin.js +14 -0
  82. package/dist/lib/utils.d.ts +2 -5
  83. package/dist/lib/utils.js +12 -12
  84. package/dist/urllib.d.ts +1 -2
  85. package/dist/urllib.js +2 -3
  86. package/package.json +31 -31
@@ -1,257 +1,377 @@
1
- import { getSourceFile } from "../lib/utils.js";
2
- import path from "node:path";
3
- import { pathToFileURL } from "node:url";
4
-
5
- //#region src/config/config.default.ts
1
+ import path from 'node:path';
2
+ import { pathToFileURL } from 'node:url';
3
+ import { defineConfigFactory } from "../index.js";
6
4
  /**
7
- * The configuration of egg application, can be access by `app.config`
8
- * @class Config
9
- * @since 1.0.0
10
- */
11
- var config_default_default = (appInfo) => {
12
- const config = {
13
- env: appInfo.env,
14
- name: appInfo.name,
15
- keys: "",
16
- cookies: {},
17
- proxy: false,
18
- maxIpsCount: 0,
19
- maxProxyCount: 0,
20
- protocolHeaders: "x-forwarded-proto",
21
- ipHeaders: "x-forwarded-for",
22
- hostHeaders: "",
23
- pkg: appInfo.pkg,
24
- baseDir: appInfo.baseDir,
25
- HOME: appInfo.HOME,
26
- rundir: path.join(appInfo.baseDir, "run"),
27
- dump: {
28
- ignore: new Set([
29
- "pass",
30
- "pwd",
31
- "passd",
32
- "passwd",
33
- "password",
34
- "keys",
35
- "masterKey",
36
- "accessKey",
37
- /secret/i
38
- ]),
39
- timing: { slowBootActionMinDuration: 5e3 }
40
- },
41
- confusedConfigurations: {
42
- bodyparser: "bodyParser",
43
- notFound: "notfound",
44
- sitefile: "siteFile",
45
- middlewares: "middleware",
46
- httpClient: "httpclient"
47
- }
48
- };
49
- /**
50
- * The options of `notfound` middleware
51
- *
52
- * It will return page or json depend on negotiation when 404,
53
- * If pageUrl is set, it will redirect to the page.
54
- *
55
- * @member Config#notfound
56
- * @property {String} pageUrl - the 404 page url
57
- */
58
- config.notfound = {
59
- enable: true,
60
- pageUrl: ""
61
- };
62
- /**
63
- * The option of `siteFile` middleware
64
- *
65
- * You can map some files using this options, it will response immediately when matching.
66
- *
67
- * @member {Object} Config#siteFile - key is path, and value is url or buffer.
68
- * @property {String} cacheControl - files cache , default is public, max-age=2592000
69
- * @example
70
- * // specific app's favicon, => '/favicon.ico': 'https://eggjs.org/favicon.ico',
71
- * config.siteFile = {
72
- * '/favicon.ico': 'https://eggjs.org/favicon.ico',
73
- * };
74
- */
75
- config.siteFile = {
76
- enable: true,
77
- "/favicon.ico": pathToFileURL(getSourceFile("config/favicon.png")),
78
- cacheControl: "public, max-age=2592000"
79
- };
80
- /**
81
- * The options of `bodyParser` middleware
82
- *
83
- * @member Config#bodyParser
84
- * @property {Boolean} enable - enable bodyParser or not, default is true
85
- * @property {String | RegExp | Function | Array} ignore - won't parse request body when url path hit ignore pattern, can not set `ignore` when `match` presented
86
- * @property {String | RegExp | Function | Array} match - will parse request body only when url path hit match pattern
87
- * @property {String} encoding - body's encoding type,default is utf8
88
- * @property {String} formLimit - limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 1mb
89
- * @property {String} jsonLimit - limit of the json body, default is 1mb
90
- * @property {String} textLimit - limit of the text body, default is 1mb
91
- * @property {Boolean} strict - when set to true, JSON parser will only accept arrays and objects. Default is true
92
- * @property {Number} queryString.arrayLimit - urlencoded body array's max length, default is 100
93
- * @property {Number} queryString.depth - urlencoded body object's max depth, default is 5
94
- * @property {Number} queryString.parameterLimit - urlencoded body maximum parameters, default is 1000
95
- */
96
- config.bodyParser = {
97
- enable: true,
98
- encoding: "utf8",
99
- formLimit: "1mb",
100
- jsonLimit: "1mb",
101
- textLimit: "1mb",
102
- strict: true,
103
- queryString: {
104
- arrayLimit: 100,
105
- depth: 5,
106
- parameterLimit: 1e3
107
- },
108
- onProtoPoisoning: "error",
109
- onerror(err, ctx) {
110
- err.message = `${err.message}, check bodyParser config`;
111
- if (ctx.status === 404) {
112
- ctx.status = 400;
113
- if (!err.status) err.status = 400;
114
- }
115
- throw err;
116
- }
117
- };
118
- /**
119
- * logger options
120
- * @member Config#logger
121
- * @property {String} dir - directory of log files
122
- * @property {String} encoding - log file encoding, defaults to utf8
123
- * @property {String} level - default log level, could be: DEBUG, INFO, WARN, ERROR or NONE, defaults to INFO in production
124
- * @property {String} consoleLevel - log level of stdout, defaults to INFO in local serverEnv, defaults to WARN in unittest, defaults to NONE elsewise
125
- * @property {Boolean} disableConsoleAfterReady - disable logger console after app ready. defaults to `false` on local and unittest env, others is `true`.
126
- * @property {Boolean} outputJSON - log as JSON or not, defaults to false
127
- * @property {Boolean} buffer - if enabled, flush logs to disk at a certain frequency to improve performance, defaults to true
128
- * @property {String} errorLogName - file name of errorLogger
129
- * @property {String} coreLogName - file name of coreLogger
130
- * @property {String} agentLogName - file name of agent worker log
131
- * @property {Object} coreLogger - custom config of coreLogger
132
- * @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
133
- * @property {Boolean} enableFastContextLogger - using the app logger instead of EggContextLogger, defaults to true
134
- */
135
- config.logger = {
136
- dir: path.join(appInfo.root, "logs", appInfo.name),
137
- encoding: "utf8",
138
- env: appInfo.env,
139
- level: "INFO",
140
- consoleLevel: "INFO",
141
- disableConsoleAfterReady: appInfo.env !== "local" && appInfo.env !== "unittest",
142
- outputJSON: false,
143
- buffer: true,
144
- appLogName: `${appInfo.name}-web.log`,
145
- coreLogName: "egg-web.log",
146
- agentLogName: "egg-agent.log",
147
- errorLogName: "common-error.log",
148
- coreLogger: {},
149
- allowDebugAtProd: false,
150
- enableFastContextLogger: true
151
- };
152
- /**
153
- * The option for httpclient
154
- * @member Config#httpclient
155
- * @property {Boolean} enableDNSCache - Enable DNS lookup from local cache or not, default is false.
156
- * @property {Boolean} dnsCacheLookupInterval - minimum interval of DNS query on the same hostname (default 10s).
157
- *
158
- * @property {Number} request.timeout - httpclient request default timeout, default is 5000 ms.
159
- *
160
- * @property {Boolean} httpAgent.keepAlive - Enable http agent keepalive or not, default is true
161
- * @property {Number} httpAgent.freeSocketTimeout - http agent socket keepalive max free time, default is 4000 ms.
162
- * @property {Number} httpAgent.maxSockets - http agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
163
- * @property {Number} httpAgent.maxFreeSockets - http agent max free socket number of one host, default is 256.
164
- *
165
- * @property {Boolean} httpsAgent.keepAlive - Enable https agent keepalive or not, default is true
166
- * @property {Number} httpsAgent.freeSocketTimeout - https agent socket keepalive max free time, default is 4000 ms.
167
- * @property {Number} httpsAgent.maxSockets - https agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
168
- * @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
169
- * @property {Boolean} useHttpClientNext - use urllib@3 HttpClient
170
- */
171
- config.httpclient = { request: { timeout: 5e3 } };
172
- /**
173
- * The options of `meta` middleware
174
- *
175
- * @member Config#meta
176
- * @property {Boolean} enable - enable meta or not, default is `true`
177
- * @property {Boolean} logging - enable logging start request, default is `false`
178
- */
179
- config.meta = {
180
- enable: true,
181
- logging: false
182
- };
183
- /**
184
- * core enable middlewares
185
- * @member {Array} Config#middleware
186
- */
187
- config.coreMiddleware = [
188
- "meta",
189
- "siteFile",
190
- "notfound",
191
- "bodyParser",
192
- "overrideMethod"
193
- ];
194
- /**
195
- * emit `startTimeout` if worker don't ready after `workerStartTimeout` ms
196
- * @member {Number} Config.workerStartTimeout
197
- */
198
- config.workerStartTimeout = 600 * 1e3;
199
- /**
200
- * server timeout in milliseconds, default to 0 (no timeout).
201
- *
202
- * for special request, just use `ctx.req.setTimeout(ms)`
203
- *
204
- * @member {Number} Config#serverTimeout
205
- * @see https://nodejs.org/api/http.html#http_server_timeout
206
- */
207
- config.serverTimeout = null;
208
- /**
209
- * The options of cluster
210
- * @member {Object} Config#cluster
211
- * @property {Object} listen - listen options, see {@link https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback}
212
- * @property {String} listen.path - set a unix sock path when server listen
213
- * @property {Number} listen.port - set a port when server listen
214
- * @property {String} listen.hostname - set a hostname binding server when server listen
215
- */
216
- config.cluster = { listen: {
217
- path: "",
218
- port: 7001,
219
- hostname: ""
220
- } };
221
- /**
222
- * @property {Number} responseTimeout - response timeout, default is 60000
223
- */
224
- config.clusterClient = {
225
- maxWaitTime: 6e4,
226
- responseTimeout: 6e4
227
- };
228
- /**
229
- * This function / async function will be called when a client error occurred and return the response.
230
- *
231
- * The arguments are `err`, `socket` and `application` which indicate current client error object, current socket
232
- * object and the application object.
233
- *
234
- * The response to be returned should include properties below:
235
- *
236
- * @member {Function} Config#onClientError
237
- * @property [body] {String|Buffer} - the response body
238
- * @property [status] {Number} - the response status code
239
- * @property [headers] {Object} - the response header key-value pairs
240
- *
241
- * @example
242
- * exports.onClientError = async (err, socket, app) => {
243
- * return {
244
- * body: 'error',
245
- * status: 400,
246
- * headers: {
247
- * 'powered-by': 'Egg.js',
248
- * }
249
- * };
250
- * }
251
- */
252
- config.onClientError = void 0;
253
- return config;
254
- };
255
-
256
- //#endregion
257
- export { config_default_default as default };
5
+ * The configuration of egg application, can be access by `app.config`
6
+ * @class Config
7
+ * @since 1.0.0
8
+ */
9
+ export default defineConfigFactory((appInfo) => {
10
+ const config = {
11
+ /**
12
+ * The environment of egg
13
+ * @member {String} Config#env
14
+ * @see {appInfo#env}
15
+ * @since 1.0.0
16
+ */
17
+ env: appInfo.env,
18
+ /**
19
+ * The name of the application
20
+ * @member {String} Config#name
21
+ * @see {appInfo#name}
22
+ * @since 1.0.0
23
+ */
24
+ name: appInfo.name,
25
+ /**
26
+ * The key that signing cookies. It can contain multiple keys separated by `,`.
27
+ * @member {String} Config#keys
28
+ * @see https://eggjs.org/core/cookie-and-session#cookie-secret-key
29
+ * @default
30
+ * @since 1.0.0
31
+ */
32
+ keys: '',
33
+ /**
34
+ * default cookie options
35
+ *
36
+ * @member Config#cookies
37
+ * @property {String} sameSite - SameSite property, defaults is ''
38
+ * @property {Boolean} httpOnly - httpOnly property, defaults is true
39
+ */
40
+ cookies: {
41
+ // httpOnly: true | false,
42
+ // sameSite: 'none|lax|strict',
43
+ },
44
+ /**
45
+ * Whether application deployed after a reverse proxy,
46
+ * when true proxy header fields will be trusted
47
+ * @member {Boolean} Config#proxy
48
+ * @default
49
+ * @since 1.0.0
50
+ */
51
+ proxy: false,
52
+ /**
53
+ *
54
+ * max ips read from proxy ip header, default to 0 (means infinity)
55
+ * to prevent users from forging client ip addresses via x-forwarded-for
56
+ * @see https://github.com/koajs/koa/blob/master/docs/api/request.md#requestips
57
+ * @member {Integer} Config#maxIpsCount
58
+ * @default
59
+ * @since 2.25.0
60
+ */
61
+ maxIpsCount: 0,
62
+ /**
63
+ * please use maxIpsCount instead
64
+ * @member {Integer} Config#maxProxyCount
65
+ * @default
66
+ * @since 2.21.0
67
+ * @deprecated
68
+ */
69
+ maxProxyCount: 0,
70
+ /**
71
+ * Detect request's protocol from specified headers, not case-sensitive.
72
+ * Only worked when config.proxy set to true.
73
+ * @member {String} Config#protocolHeaders
74
+ * @default
75
+ * @since 1.0.0
76
+ */
77
+ protocolHeaders: 'x-forwarded-proto',
78
+ /**
79
+ * Detect request' ip from specified headers, not case-sensitive.
80
+ * Only worked when config.proxy set to true.
81
+ * @member {String} Config#ipHeaders
82
+ * @default
83
+ * @since 1.0.0
84
+ */
85
+ ipHeaders: 'x-forwarded-for',
86
+ /**
87
+ * Detect request' host from specified headers, not case-sensitive.
88
+ * Only worked when config.proxy set to true.
89
+ * @member {String} Config#hostHeaders
90
+ * @default
91
+ * @since 1.0.0
92
+ */
93
+ hostHeaders: '',
94
+ /**
95
+ * package.json
96
+ * @member {Object} Config#pkg
97
+ * @see {appInfo#pkg}
98
+ * @since 1.0.0
99
+ */
100
+ pkg: appInfo.pkg,
101
+ /**
102
+ * The current directory of the application
103
+ * @member {String} Config#baseDir
104
+ * @see {appInfo#baseDir}
105
+ * @since 1.0.0
106
+ */
107
+ baseDir: appInfo.baseDir,
108
+ /**
109
+ * The current HOME directory
110
+ * @member {String} Config#HOME
111
+ * @see {appInfo#HOME}
112
+ * @since 1.0.0
113
+ */
114
+ HOME: appInfo.HOME,
115
+ /**
116
+ * The directory of server running. You can find `application_config.json` under it that is dumped from `app.config`.
117
+ * @member {String} Config#rundir
118
+ * @default
119
+ * @since 1.0.0
120
+ */
121
+ rundir: path.join(appInfo.baseDir, 'run'),
122
+ /**
123
+ * dump config
124
+ *
125
+ * It will ignore special keys when dumpConfig
126
+ *
127
+ * @member Config#dump
128
+ * @property {Set} ignore - keys to ignore
129
+ */
130
+ dump: {
131
+ ignore: new Set([
132
+ 'pass',
133
+ 'pwd',
134
+ 'passd',
135
+ 'passwd',
136
+ 'password',
137
+ 'keys',
138
+ 'masterKey',
139
+ 'accessKey',
140
+ // ignore any key contains "secret" keyword
141
+ /secret/i,
142
+ ]),
143
+ timing: {
144
+ // if boot action >= slowBootActionMinDuration, egg core will print it to warning log
145
+ slowBootActionMinDuration: 5000,
146
+ },
147
+ },
148
+ /**
149
+ * configurations are confused to users
150
+ * {
151
+ * [unexpectedKey]: [expectedKey],
152
+ * }
153
+ * @member Config#confusedConfigurations
154
+ * @type {Object}
155
+ */
156
+ confusedConfigurations: {
157
+ bodyparser: 'bodyParser',
158
+ notFound: 'notfound',
159
+ sitefile: 'siteFile',
160
+ middlewares: 'middleware',
161
+ httpClient: 'httpclient',
162
+ },
163
+ };
164
+ /**
165
+ * The options of `notfound` middleware
166
+ *
167
+ * It will return page or json depend on negotiation when 404,
168
+ * If pageUrl is set, it will redirect to the page.
169
+ *
170
+ * @member Config#notfound
171
+ * @property {String} pageUrl - the 404 page url
172
+ */
173
+ config.notfound = {
174
+ enable: true,
175
+ pageUrl: '',
176
+ };
177
+ /**
178
+ * The option of `siteFile` middleware
179
+ *
180
+ * You can map some files using this options, it will response immediately when matching.
181
+ *
182
+ * @member {Object} Config#siteFile - key is path, and value is url or buffer.
183
+ * @property {String} cacheControl - files cache control, default is `public, max-age=2592000`
184
+ * @example
185
+ * ```ts
186
+ * // specific app's favicon, => '/favicon.ico': 'https://eggjs.org/favicon.png',
187
+ * config.siteFile = {
188
+ * '/favicon.ico': 'https://eggjs.org/favicon.png',
189
+ * };
190
+ * ```
191
+ */
192
+ config.siteFile = {
193
+ enable: true,
194
+ '/favicon.ico': pathToFileURL(path.join(import.meta.dirname, 'favicon.png')),
195
+ // default cache in 30 days
196
+ cacheControl: 'public, max-age=2592000',
197
+ };
198
+ /**
199
+ * The options of `bodyParser` middleware
200
+ *
201
+ * @member Config#bodyParser
202
+ * @property {Boolean} enable - enable bodyParser or not, default is true
203
+ * @property {String | RegExp | Function | Array} ignore - won't parse request body when url path hit ignore pattern, can not set `ignore` when `match` presented
204
+ * @property {String | RegExp | Function | Array} match - will parse request body only when url path hit match pattern
205
+ * @property {String} encoding - body's encoding type,default is utf8
206
+ * @property {String} formLimit - limit of the urlencoded body. If the body ends up being larger than this limit, a 413 error code is returned. Default is 1mb
207
+ * @property {String} jsonLimit - limit of the json body, default is 1mb
208
+ * @property {String} textLimit - limit of the text body, default is 1mb
209
+ * @property {Boolean} strict - when set to true, JSON parser will only accept arrays and objects. Default is true
210
+ * @property {Number} queryString.arrayLimit - urlencoded body array's max length, default is 100
211
+ * @property {Number} queryString.depth - urlencoded body object's max depth, default is 5
212
+ * @property {Number} queryString.parameterLimit - urlencoded body maximum parameters, default is 1000
213
+ */
214
+ config.bodyParser = {
215
+ enable: true,
216
+ encoding: 'utf8',
217
+ formLimit: '1mb',
218
+ jsonLimit: '1mb',
219
+ textLimit: '1mb',
220
+ strict: true,
221
+ // @see https://github.com/hapijs/qs/blob/master/lib/parse.js#L8 for more options
222
+ queryString: {
223
+ arrayLimit: 100,
224
+ depth: 5,
225
+ parameterLimit: 1000,
226
+ },
227
+ onProtoPoisoning: 'error',
228
+ onerror(err, ctx) {
229
+ err.message = `${err.message}, check bodyParser config`;
230
+ if (ctx.status === 404) {
231
+ // set default status to 400, meaning client bad request
232
+ ctx.status = 400;
233
+ if (!err.status) {
234
+ err.status = 400;
235
+ }
236
+ }
237
+ throw err;
238
+ },
239
+ };
240
+ /**
241
+ * logger options
242
+ * @member Config#logger
243
+ * @property {String} dir - directory of log files
244
+ * @property {String} encoding - log file encoding, defaults to utf8
245
+ * @property {String} level - default log level, could be: DEBUG, INFO, WARN, ERROR or NONE, defaults to INFO in production
246
+ * @property {String} consoleLevel - log level of stdout, defaults to INFO in local serverEnv, defaults to WARN in unittest, defaults to NONE elsewise
247
+ * @property {Boolean} disableConsoleAfterReady - disable logger console after app ready. defaults to `false` on local and unittest env, others is `true`.
248
+ * @property {Boolean} outputJSON - log as JSON or not, defaults to false
249
+ * @property {Boolean} buffer - if enabled, flush logs to disk at a certain frequency to improve performance, defaults to true
250
+ * @property {String} errorLogName - file name of errorLogger
251
+ * @property {String} coreLogName - file name of coreLogger
252
+ * @property {String} agentLogName - file name of agent worker log
253
+ * @property {Object} coreLogger - custom config of coreLogger
254
+ * @property {Boolean} allowDebugAtProd - allow debug log at prod, defaults to false
255
+ * @property {Boolean} enableFastContextLogger - using the app logger instead of EggContextLogger, defaults to true
256
+ */
257
+ config.logger = {
258
+ dir: path.join(appInfo.root, 'logs', appInfo.name),
259
+ encoding: 'utf8',
260
+ env: appInfo.env,
261
+ level: 'INFO',
262
+ consoleLevel: 'INFO',
263
+ disableConsoleAfterReady: appInfo.env !== 'local' && appInfo.env !== 'unittest',
264
+ outputJSON: false,
265
+ buffer: true,
266
+ appLogName: `${appInfo.name}-web.log`,
267
+ coreLogName: 'egg-web.log',
268
+ agentLogName: 'egg-agent.log',
269
+ errorLogName: 'common-error.log',
270
+ coreLogger: {},
271
+ allowDebugAtProd: false,
272
+ enableFastContextLogger: true,
273
+ };
274
+ /**
275
+ * The option for httpclient
276
+ * @member Config#httpclient
277
+ * @property {Boolean} enableDNSCache - Enable DNS lookup from local cache or not, default is false.
278
+ * @property {Boolean} dnsCacheLookupInterval - minimum interval of DNS query on the same hostname (default 10s).
279
+ *
280
+ * @property {Number} request.timeout - httpclient request default timeout, default is 5000 ms.
281
+ *
282
+ * @property {Boolean} httpAgent.keepAlive - Enable http agent keepalive or not, default is true
283
+ * @property {Number} httpAgent.freeSocketTimeout - http agent socket keepalive max free time, default is 4000 ms.
284
+ * @property {Number} httpAgent.maxSockets - http agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
285
+ * @property {Number} httpAgent.maxFreeSockets - http agent max free socket number of one host, default is 256.
286
+ *
287
+ * @property {Boolean} httpsAgent.keepAlive - Enable https agent keepalive or not, default is true
288
+ * @property {Number} httpsAgent.freeSocketTimeout - https agent socket keepalive max free time, default is 4000 ms.
289
+ * @property {Number} httpsAgent.maxSockets - https agent max socket number of one host, default is `Number.MAX_SAFE_INTEGER` @ses https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
290
+ * @property {Number} httpsAgent.maxFreeSockets - https agent max free socket number of one host, default is 256.
291
+ * @property {Boolean} useHttpClientNext - use urllib@3 HttpClient
292
+ */
293
+ config.httpclient = {
294
+ request: {
295
+ timeout: 5000,
296
+ },
297
+ };
298
+ /**
299
+ * The options of `meta` middleware
300
+ *
301
+ * @member Config#meta
302
+ * @property {Boolean} enable - enable meta or not, default is `true`
303
+ * @property {Boolean} logging - enable logging start request, default is `false`
304
+ */
305
+ config.meta = {
306
+ enable: true,
307
+ logging: false,
308
+ };
309
+ /**
310
+ * core enable middlewares
311
+ * @member {Array} Config#middleware
312
+ */
313
+ config.coreMiddleware = ['meta', 'siteFile', 'notfound', 'bodyParser', 'overrideMethod'];
314
+ /**
315
+ * emit `startTimeout` if worker don't ready after `workerStartTimeout` ms
316
+ * @member {Number} Config.workerStartTimeout
317
+ */
318
+ config.workerStartTimeout = 10 * 60 * 1000;
319
+ /**
320
+ * server timeout in milliseconds, default to 0 (no timeout).
321
+ *
322
+ * for special request, just use `ctx.req.setTimeout(ms)`
323
+ *
324
+ * @member {Number} Config#serverTimeout
325
+ * @see https://nodejs.org/api/http.html#http_server_timeout
326
+ */
327
+ config.serverTimeout = null;
328
+ /**
329
+ * The options of cluster
330
+ * @member {Object} Config#cluster
331
+ * @property {Object} listen - listen options, see {@link https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback}
332
+ * @property {String} listen.path - set a unix sock path when server listen
333
+ * @property {Number} listen.port - set a port when server listen
334
+ * @property {String} listen.hostname - set a hostname binding server when server listen
335
+ */
336
+ config.cluster = {
337
+ listen: {
338
+ path: '',
339
+ port: 7001,
340
+ hostname: '',
341
+ },
342
+ };
343
+ /**
344
+ * @property {Number} responseTimeout - response timeout, default is 60000
345
+ */
346
+ config.clusterClient = {
347
+ maxWaitTime: 60000,
348
+ responseTimeout: 60000,
349
+ };
350
+ /**
351
+ * This function / async function will be called when a client error occurred and return the response.
352
+ *
353
+ * The arguments are `err`, `socket` and `application` which indicate current client error object, current socket
354
+ * object and the application object.
355
+ *
356
+ * The response to be returned should include properties below:
357
+ *
358
+ * @member {Function} Config#onClientError
359
+ * @property [body] {String|Buffer} - the response body
360
+ * @property [status] {Number} - the response status code
361
+ * @property [headers] {Object} - the response header key-value pairs
362
+ *
363
+ * @example
364
+ * exports.onClientError = async (err, socket, app) => {
365
+ * return {
366
+ * body: 'error',
367
+ * status: 400,
368
+ * headers: {
369
+ * 'powered-by': 'Egg.js',
370
+ * }
371
+ * };
372
+ * }
373
+ */
374
+ config.onClientError = undefined;
375
+ return config;
376
+ });
377
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmRlZmF1bHQuanMi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