ee-core 2.9.2 → 2.10.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/LICENSE +21 -21
- package/README.md +65 -65
- package/addon/index.js +34 -34
- package/addon/window/index.js +98 -98
- package/bin/tools.js +8 -8
- package/config/cache.js +41 -38
- package/config/config.default.js +331 -330
- package/config/index.js +86 -73
- package/const/channel.js +17 -17
- package/const/index.js +8 -8
- package/controller/baseContextClass.js +34 -34
- package/controller/index.js +34 -34
- package/core/index.js +10 -10
- package/core/lib/ee.js +216 -216
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +435 -435
- package/core/lib/loader/file_loader.js +326 -326
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +130 -130
- package/core/lib/loader/mixin/controller.js +125 -125
- package/core/lib/loader/mixin/service.js +28 -28
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/function.js +30 -30
- package/core/lib/utils/index.js +133 -133
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/cross/index.js +183 -183
- package/cross/spawnProcess.js +183 -183
- package/ee/appLoader.js +48 -48
- package/ee/application.js +99 -99
- package/ee/baseApp.js +103 -102
- package/ee/eeApp.js +408 -408
- package/ee/index.js +57 -57
- package/electron/app/index.js +64 -58
- package/electron/index.js +19 -19
- package/electron/window/index.js +73 -73
- package/electron/window/winState.js +186 -186
- package/exception/index.js +112 -112
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.js +13 -13
- package/httpclient/index.js +161 -161
- package/index.js +54 -54
- package/jobs/baseJobClass.js +16 -16
- package/jobs/child/app.js +58 -65
- package/jobs/child/forkProcess.js +145 -145
- package/jobs/child/index.js +82 -82
- package/jobs/child-pool/index.js +213 -213
- package/jobs/index.js +8 -8
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.js +31 -31
- package/jobs/renderer/index.js +141 -141
- package/jobs/renderer/loadView.js +40 -40
- package/jobs/unification.js +63 -63
- package/loader/index.js +172 -172
- package/log/index.js +68 -68
- package/log/logger.js +86 -80
- package/main/index.js +56 -56
- package/message/childMessage.js +54 -54
- package/message/index.js +18 -18
- package/old-utils/index.js +91 -91
- package/package.json +38 -38
- package/ps/index.js +371 -371
- package/services/baseContextClass.js +34 -34
- package/services/index.js +40 -40
- package/socket/httpServer.js +147 -147
- package/socket/index.js +81 -81
- package/socket/io.js +27 -27
- package/socket/ipcServer.js +112 -112
- package/socket/socketServer.js +69 -67
- package/storage/index.js +38 -38
- package/storage/jsondb/adapters/Base.js +23 -23
- package/storage/jsondb/adapters/FileSync.js +64 -52
- package/storage/jsondb/main.js +55 -42
- package/storage/jsondbStorage.js +195 -195
- package/storage/sqliteStorage.js +123 -123
- package/utils/co.js +237 -237
- package/utils/copyto.js +160 -160
- package/utils/depd/index.js +538 -538
- package/utils/depd/lib/browser/index.js +77 -77
- package/utils/extend.js +73 -73
- package/utils/get-port/index.d.ts +64 -64
- package/utils/get-port/index.js +148 -148
- package/utils/helper.js +220 -220
- package/utils/index.js +160 -160
- package/utils/ip.js +261 -261
- package/utils/is.js +145 -145
- package/utils/json.js +72 -72
- package/utils/pargv.js +263 -263
- package/utils/time/index.js +19 -19
- package/utils/time/ms.js +162 -162
- package/utils/wrap.js +35 -35
package/html/boot.html
CHANGED
|
@@ -1,98 +1,98 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0" />
|
|
7
|
-
<style>
|
|
8
|
-
#loadingPage {
|
|
9
|
-
background-color: #dedede;
|
|
10
|
-
font-size: 12px;
|
|
11
|
-
}
|
|
12
|
-
.base {
|
|
13
|
-
left: 50%;
|
|
14
|
-
position: absolute;
|
|
15
|
-
top: 50%;
|
|
16
|
-
transform: translate(-50%, -50%);
|
|
17
|
-
}
|
|
18
|
-
.desc {
|
|
19
|
-
margin: 0, 0, 20px, 0;
|
|
20
|
-
}
|
|
21
|
-
.loading,
|
|
22
|
-
.loading > div {
|
|
23
|
-
position: relative;
|
|
24
|
-
box-sizing: border-box;
|
|
25
|
-
}
|
|
26
|
-
.loading {
|
|
27
|
-
display: block;
|
|
28
|
-
font-size: 0;
|
|
29
|
-
color: #06b359;
|
|
30
|
-
}
|
|
31
|
-
.loading.la-dark {
|
|
32
|
-
color: #07C160;
|
|
33
|
-
}
|
|
34
|
-
.loading > div {
|
|
35
|
-
display: inline-block;
|
|
36
|
-
float: none;
|
|
37
|
-
background-color: currentColor;
|
|
38
|
-
border: 0 solid currentColor;
|
|
39
|
-
}
|
|
40
|
-
.loading {
|
|
41
|
-
width: 92px;
|
|
42
|
-
height: 92px;
|
|
43
|
-
}
|
|
44
|
-
.loading > div {
|
|
45
|
-
position: absolute;
|
|
46
|
-
top: 50%;
|
|
47
|
-
left: 50%;
|
|
48
|
-
background: transparent;
|
|
49
|
-
border-style: solid;
|
|
50
|
-
border-width: 2px;
|
|
51
|
-
border-radius: 100%;
|
|
52
|
-
animation: ball-clip-rotate-multiple-rotate 1s ease-in-out infinite;
|
|
53
|
-
}
|
|
54
|
-
.loading > div:first-child {
|
|
55
|
-
position: absolute;
|
|
56
|
-
width: 92px;
|
|
57
|
-
height: 92px;
|
|
58
|
-
border-right-color: transparent;
|
|
59
|
-
border-left-color: transparent;
|
|
60
|
-
}
|
|
61
|
-
.loading > div:last-child {
|
|
62
|
-
width: 16px;
|
|
63
|
-
height: 16px;
|
|
64
|
-
border-top-color: transparent;
|
|
65
|
-
border-bottom-color: transparent;
|
|
66
|
-
animation-duration: 0.5s;
|
|
67
|
-
animation-direction: reverse;
|
|
68
|
-
}
|
|
69
|
-
@keyframes ball-clip-rotate-multiple-rotate {
|
|
70
|
-
0% {
|
|
71
|
-
transform: translate(-50%, -50%) rotate(0deg);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
50% {
|
|
75
|
-
transform: translate(-50%, -50%) rotate(180deg);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
100% {
|
|
79
|
-
transform: translate(-50%, -50%) rotate(360deg);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
</style>
|
|
83
|
-
</head>
|
|
84
|
-
<body>
|
|
85
|
-
<div id="boot">
|
|
86
|
-
<div class='base'>
|
|
87
|
-
<!-- Booting the frontend service ... -->
|
|
88
|
-
<!-- <div class='desc'>
|
|
89
|
-
Booting frontend
|
|
90
|
-
</div> -->
|
|
91
|
-
<div class="loading">
|
|
92
|
-
<div></div>
|
|
93
|
-
<div></div>
|
|
94
|
-
</div>
|
|
95
|
-
</div>
|
|
96
|
-
</div>
|
|
97
|
-
</body>
|
|
98
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0" />
|
|
7
|
+
<style>
|
|
8
|
+
#loadingPage {
|
|
9
|
+
background-color: #dedede;
|
|
10
|
+
font-size: 12px;
|
|
11
|
+
}
|
|
12
|
+
.base {
|
|
13
|
+
left: 50%;
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 50%;
|
|
16
|
+
transform: translate(-50%, -50%);
|
|
17
|
+
}
|
|
18
|
+
.desc {
|
|
19
|
+
margin: 0, 0, 20px, 0;
|
|
20
|
+
}
|
|
21
|
+
.loading,
|
|
22
|
+
.loading > div {
|
|
23
|
+
position: relative;
|
|
24
|
+
box-sizing: border-box;
|
|
25
|
+
}
|
|
26
|
+
.loading {
|
|
27
|
+
display: block;
|
|
28
|
+
font-size: 0;
|
|
29
|
+
color: #06b359;
|
|
30
|
+
}
|
|
31
|
+
.loading.la-dark {
|
|
32
|
+
color: #07C160;
|
|
33
|
+
}
|
|
34
|
+
.loading > div {
|
|
35
|
+
display: inline-block;
|
|
36
|
+
float: none;
|
|
37
|
+
background-color: currentColor;
|
|
38
|
+
border: 0 solid currentColor;
|
|
39
|
+
}
|
|
40
|
+
.loading {
|
|
41
|
+
width: 92px;
|
|
42
|
+
height: 92px;
|
|
43
|
+
}
|
|
44
|
+
.loading > div {
|
|
45
|
+
position: absolute;
|
|
46
|
+
top: 50%;
|
|
47
|
+
left: 50%;
|
|
48
|
+
background: transparent;
|
|
49
|
+
border-style: solid;
|
|
50
|
+
border-width: 2px;
|
|
51
|
+
border-radius: 100%;
|
|
52
|
+
animation: ball-clip-rotate-multiple-rotate 1s ease-in-out infinite;
|
|
53
|
+
}
|
|
54
|
+
.loading > div:first-child {
|
|
55
|
+
position: absolute;
|
|
56
|
+
width: 92px;
|
|
57
|
+
height: 92px;
|
|
58
|
+
border-right-color: transparent;
|
|
59
|
+
border-left-color: transparent;
|
|
60
|
+
}
|
|
61
|
+
.loading > div:last-child {
|
|
62
|
+
width: 16px;
|
|
63
|
+
height: 16px;
|
|
64
|
+
border-top-color: transparent;
|
|
65
|
+
border-bottom-color: transparent;
|
|
66
|
+
animation-duration: 0.5s;
|
|
67
|
+
animation-direction: reverse;
|
|
68
|
+
}
|
|
69
|
+
@keyframes ball-clip-rotate-multiple-rotate {
|
|
70
|
+
0% {
|
|
71
|
+
transform: translate(-50%, -50%) rotate(0deg);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
50% {
|
|
75
|
+
transform: translate(-50%, -50%) rotate(180deg);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
100% {
|
|
79
|
+
transform: translate(-50%, -50%) rotate(360deg);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
</style>
|
|
83
|
+
</head>
|
|
84
|
+
<body>
|
|
85
|
+
<div id="boot">
|
|
86
|
+
<div class='base'>
|
|
87
|
+
<!-- Booting the frontend service ... -->
|
|
88
|
+
<!-- <div class='desc'>
|
|
89
|
+
Booting frontend
|
|
90
|
+
</div> -->
|
|
91
|
+
<div class="loading">
|
|
92
|
+
<div></div>
|
|
93
|
+
<div></div>
|
|
94
|
+
</div>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
</body>
|
|
98
|
+
</html>
|
package/html/cross-failure.html
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0" />
|
|
7
|
-
<title>Booting failure</title>
|
|
8
|
-
<style>
|
|
9
|
-
#failure {
|
|
10
|
-
background-color: #dedede;
|
|
11
|
-
font-size: 14px;
|
|
12
|
-
}
|
|
13
|
-
.base {
|
|
14
|
-
position: absolute;
|
|
15
|
-
top: 50%;
|
|
16
|
-
left: 50%;
|
|
17
|
-
transform: translate(-50%, -50%);
|
|
18
|
-
}
|
|
19
|
-
</style>
|
|
20
|
-
</head>
|
|
21
|
-
<body>
|
|
22
|
-
<div id="failure">
|
|
23
|
-
<div class='base'>
|
|
24
|
-
Startup failed, please check cross service is runing !
|
|
25
|
-
</div>
|
|
26
|
-
</div>
|
|
27
|
-
</body>
|
|
28
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0" />
|
|
7
|
+
<title>Booting failure</title>
|
|
8
|
+
<style>
|
|
9
|
+
#failure {
|
|
10
|
+
background-color: #dedede;
|
|
11
|
+
font-size: 14px;
|
|
12
|
+
}
|
|
13
|
+
.base {
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 50%;
|
|
16
|
+
left: 50%;
|
|
17
|
+
transform: translate(-50%, -50%);
|
|
18
|
+
}
|
|
19
|
+
</style>
|
|
20
|
+
</head>
|
|
21
|
+
<body>
|
|
22
|
+
<div id="failure">
|
|
23
|
+
<div class='base'>
|
|
24
|
+
Startup failed, please check cross service is runing !
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|
package/html/failure.html
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="zh-CN">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0" />
|
|
7
|
-
<title>Booting failure</title>
|
|
8
|
-
<style>
|
|
9
|
-
#failure {
|
|
10
|
-
background-color: #dedede;
|
|
11
|
-
font-size: 14px;
|
|
12
|
-
}
|
|
13
|
-
.base {
|
|
14
|
-
position: absolute;
|
|
15
|
-
top: 50%;
|
|
16
|
-
left: 50%;
|
|
17
|
-
transform: translate(-50%, -50%);
|
|
18
|
-
}
|
|
19
|
-
</style>
|
|
20
|
-
</head>
|
|
21
|
-
<body>
|
|
22
|
-
<div id="failure">
|
|
23
|
-
<div class='base'>
|
|
24
|
-
Startup failed, please check frontend service is runing !
|
|
25
|
-
</div>
|
|
26
|
-
</div>
|
|
27
|
-
</body>
|
|
28
|
-
</html>
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0" />
|
|
7
|
+
<title>Booting failure</title>
|
|
8
|
+
<style>
|
|
9
|
+
#failure {
|
|
10
|
+
background-color: #dedede;
|
|
11
|
+
font-size: 14px;
|
|
12
|
+
}
|
|
13
|
+
.base {
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 50%;
|
|
16
|
+
left: 50%;
|
|
17
|
+
transform: translate(-50%, -50%);
|
|
18
|
+
}
|
|
19
|
+
</style>
|
|
20
|
+
</head>
|
|
21
|
+
<body>
|
|
22
|
+
<div id="failure">
|
|
23
|
+
<div class='base'>
|
|
24
|
+
Startup failed, please check frontend service is runing !
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</body>
|
|
28
|
+
</html>
|
package/html/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Html
|
|
5
|
-
*/
|
|
6
|
-
const Html = {
|
|
7
|
-
getFilepath(name){
|
|
8
|
-
const pagePath = path.join(__dirname, name);
|
|
9
|
-
return pagePath;
|
|
10
|
-
},
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
1
|
+
const path = require('path');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Html
|
|
5
|
+
*/
|
|
6
|
+
const Html = {
|
|
7
|
+
getFilepath(name){
|
|
8
|
+
const pagePath = path.join(__dirname, name);
|
|
9
|
+
return pagePath;
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
14
|
module.exports = Html;
|
package/httpclient/index.js
CHANGED
|
@@ -1,161 +1,161 @@
|
|
|
1
|
-
const Agent = require('agentkeepalive');
|
|
2
|
-
const HttpsAgent = require('agentkeepalive').HttpsAgent;
|
|
3
|
-
const urllib = require('urllib');
|
|
4
|
-
const { FrameworkBaseError } = require('egg-errors');
|
|
5
|
-
const Conf = require('../config');
|
|
6
|
-
const Log = require('../log');
|
|
7
|
-
const Time = require('../utils/time');
|
|
8
|
-
|
|
9
|
-
class HttpClientError extends FrameworkBaseError {
|
|
10
|
-
get module() {
|
|
11
|
-
return 'httpclient';
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
class HttpClient extends urllib.HttpClient2 {
|
|
16
|
-
constructor(options = {}) {
|
|
17
|
-
|
|
18
|
-
if (Object.keys(options).length == 0) {
|
|
19
|
-
options = Conf.getValue('httpclient');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const config = Object.assign({
|
|
23
|
-
enableDNSCache: false,
|
|
24
|
-
dnsCacheLookupInterval: 10000,
|
|
25
|
-
dnsCacheMaxLength: 1000,
|
|
26
|
-
request: {
|
|
27
|
-
timeout: 5000,
|
|
28
|
-
},
|
|
29
|
-
httpAgent: {
|
|
30
|
-
keepAlive: true,
|
|
31
|
-
freeSocketTimeout: 4000,
|
|
32
|
-
maxSockets: Number.MAX_SAFE_INTEGER,
|
|
33
|
-
maxFreeSockets: 256,
|
|
34
|
-
},
|
|
35
|
-
httpsAgent: {
|
|
36
|
-
keepAlive: true,
|
|
37
|
-
freeSocketTimeout: 4000,
|
|
38
|
-
maxSockets: Number.MAX_SAFE_INTEGER,
|
|
39
|
-
maxFreeSockets: 256,
|
|
40
|
-
},
|
|
41
|
-
}, options);
|
|
42
|
-
|
|
43
|
-
normalizeConfig(config);
|
|
44
|
-
|
|
45
|
-
super({
|
|
46
|
-
defaultArgs: config.request,
|
|
47
|
-
agent: new Agent(config.httpAgent),
|
|
48
|
-
httpsAgent: new HttpsAgent(config.httpsAgent),
|
|
49
|
-
});
|
|
50
|
-
this.config = config;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
request(url, args, callback) {
|
|
54
|
-
if (typeof args === 'function') {
|
|
55
|
-
callback = args;
|
|
56
|
-
args = null;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
args = args || {};
|
|
60
|
-
|
|
61
|
-
// the callback style
|
|
62
|
-
if (callback) {
|
|
63
|
-
//this.app.deprecate('[httpclient] We now support async for this function, so callback isn\'t recommended.');
|
|
64
|
-
super.request(url, args)
|
|
65
|
-
.then(result => process.nextTick(() => callback(null, result.data, result.res)))
|
|
66
|
-
.catch(err => process.nextTick(() => callback(err)));
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// the Promise style
|
|
71
|
-
return super.request(url, args)
|
|
72
|
-
.catch(err => {
|
|
73
|
-
if (err.code === 'ENETUNREACH') {
|
|
74
|
-
throw HttpClientError.create(err.message, err.code);
|
|
75
|
-
}
|
|
76
|
-
throw err;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
curl(url, args, callback) {
|
|
81
|
-
return this.request(url, args, callback);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
requestThunk(url, args) {
|
|
85
|
-
//this.app.deprecate('[httpclient] Please use `request()` instead of `requestThunk()`');
|
|
86
|
-
return callback => {
|
|
87
|
-
this.request(url, args, (err, data, res) => {
|
|
88
|
-
if (err) {
|
|
89
|
-
return callback(err);
|
|
90
|
-
}
|
|
91
|
-
callback(null, {
|
|
92
|
-
data,
|
|
93
|
-
status: res.status,
|
|
94
|
-
headers: res.headers,
|
|
95
|
-
res,
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function normalizeConfig(httpConfig) {
|
|
103
|
-
const config = httpConfig;
|
|
104
|
-
|
|
105
|
-
// compatibility
|
|
106
|
-
if (typeof config.keepAlive === 'boolean') {
|
|
107
|
-
config.httpAgent.keepAlive = config.keepAlive;
|
|
108
|
-
config.httpsAgent.keepAlive = config.keepAlive;
|
|
109
|
-
}
|
|
110
|
-
if (config.timeout) {
|
|
111
|
-
config.timeout = Time.ms(config.timeout);
|
|
112
|
-
config.httpAgent.timeout = config.timeout;
|
|
113
|
-
config.httpsAgent.timeout = config.timeout;
|
|
114
|
-
}
|
|
115
|
-
// compatibility httpclient.freeSocketKeepAliveTimeout => httpclient.freeSocketTimeout
|
|
116
|
-
if (config.freeSocketKeepAliveTimeout && !config.freeSocketTimeout) {
|
|
117
|
-
config.freeSocketTimeout = config.freeSocketKeepAliveTimeout;
|
|
118
|
-
delete config.freeSocketKeepAliveTimeout;
|
|
119
|
-
}
|
|
120
|
-
if (config.freeSocketTimeout) {
|
|
121
|
-
config.freeSocketTimeout = Time.ms(config.freeSocketTimeout);
|
|
122
|
-
config.httpAgent.freeSocketTimeout = config.freeSocketTimeout;
|
|
123
|
-
config.httpsAgent.freeSocketTimeout = config.freeSocketTimeout;
|
|
124
|
-
} else {
|
|
125
|
-
// compatibility agent.freeSocketKeepAliveTimeout
|
|
126
|
-
if (config.httpAgent.freeSocketKeepAliveTimeout && !config.httpAgent.freeSocketTimeout) {
|
|
127
|
-
config.httpAgent.freeSocketTimeout = config.httpAgent.freeSocketKeepAliveTimeout;
|
|
128
|
-
delete config.httpAgent.freeSocketKeepAliveTimeout;
|
|
129
|
-
}
|
|
130
|
-
if (config.httpsAgent.freeSocketKeepAliveTimeout && !config.httpsAgent.freeSocketTimeout) {
|
|
131
|
-
config.httpsAgent.freeSocketTimeout = config.httpsAgent.freeSocketKeepAliveTimeout;
|
|
132
|
-
delete config.httpsAgent.freeSocketKeepAliveTimeout;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (typeof config.maxSockets === 'number') {
|
|
137
|
-
config.httpAgent.maxSockets = config.maxSockets;
|
|
138
|
-
config.httpsAgent.maxSockets = config.maxSockets;
|
|
139
|
-
}
|
|
140
|
-
if (typeof config.maxFreeSockets === 'number') {
|
|
141
|
-
config.httpAgent.maxFreeSockets = config.maxFreeSockets;
|
|
142
|
-
config.httpsAgent.maxFreeSockets = config.maxFreeSockets;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (config.httpAgent.timeout < 30000) {
|
|
146
|
-
Log.coreLogger.warn('[ee-core] [httpclient] config.httpclient.httpAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
|
|
147
|
-
config.httpAgent.timeout);
|
|
148
|
-
config.httpAgent.timeout = 30000;
|
|
149
|
-
}
|
|
150
|
-
if (config.httpsAgent.timeout < 30000) {
|
|
151
|
-
Log.coreLogger.warn('[ee-core] [httpclient] config.httpclient.httpsAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
|
|
152
|
-
config.httpsAgent.timeout);
|
|
153
|
-
config.httpsAgent.timeout = 30000;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (typeof config.request.timeout === 'string') {
|
|
157
|
-
config.request.timeout = Time.ms(config.request.timeout);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
module.exports = HttpClient;
|
|
1
|
+
const Agent = require('agentkeepalive');
|
|
2
|
+
const HttpsAgent = require('agentkeepalive').HttpsAgent;
|
|
3
|
+
const urllib = require('urllib');
|
|
4
|
+
const { FrameworkBaseError } = require('egg-errors');
|
|
5
|
+
const Conf = require('../config/cache');
|
|
6
|
+
const Log = require('../log');
|
|
7
|
+
const Time = require('../utils/time');
|
|
8
|
+
|
|
9
|
+
class HttpClientError extends FrameworkBaseError {
|
|
10
|
+
get module() {
|
|
11
|
+
return 'httpclient';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class HttpClient extends urllib.HttpClient2 {
|
|
16
|
+
constructor(options = {}) {
|
|
17
|
+
|
|
18
|
+
if (Object.keys(options).length == 0) {
|
|
19
|
+
options = Conf.getValue('httpclient');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const config = Object.assign({
|
|
23
|
+
enableDNSCache: false,
|
|
24
|
+
dnsCacheLookupInterval: 10000,
|
|
25
|
+
dnsCacheMaxLength: 1000,
|
|
26
|
+
request: {
|
|
27
|
+
timeout: 5000,
|
|
28
|
+
},
|
|
29
|
+
httpAgent: {
|
|
30
|
+
keepAlive: true,
|
|
31
|
+
freeSocketTimeout: 4000,
|
|
32
|
+
maxSockets: Number.MAX_SAFE_INTEGER,
|
|
33
|
+
maxFreeSockets: 256,
|
|
34
|
+
},
|
|
35
|
+
httpsAgent: {
|
|
36
|
+
keepAlive: true,
|
|
37
|
+
freeSocketTimeout: 4000,
|
|
38
|
+
maxSockets: Number.MAX_SAFE_INTEGER,
|
|
39
|
+
maxFreeSockets: 256,
|
|
40
|
+
},
|
|
41
|
+
}, options);
|
|
42
|
+
|
|
43
|
+
normalizeConfig(config);
|
|
44
|
+
|
|
45
|
+
super({
|
|
46
|
+
defaultArgs: config.request,
|
|
47
|
+
agent: new Agent(config.httpAgent),
|
|
48
|
+
httpsAgent: new HttpsAgent(config.httpsAgent),
|
|
49
|
+
});
|
|
50
|
+
this.config = config;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
request(url, args, callback) {
|
|
54
|
+
if (typeof args === 'function') {
|
|
55
|
+
callback = args;
|
|
56
|
+
args = null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
args = args || {};
|
|
60
|
+
|
|
61
|
+
// the callback style
|
|
62
|
+
if (callback) {
|
|
63
|
+
//this.app.deprecate('[httpclient] We now support async for this function, so callback isn\'t recommended.');
|
|
64
|
+
super.request(url, args)
|
|
65
|
+
.then(result => process.nextTick(() => callback(null, result.data, result.res)))
|
|
66
|
+
.catch(err => process.nextTick(() => callback(err)));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// the Promise style
|
|
71
|
+
return super.request(url, args)
|
|
72
|
+
.catch(err => {
|
|
73
|
+
if (err.code === 'ENETUNREACH') {
|
|
74
|
+
throw HttpClientError.create(err.message, err.code);
|
|
75
|
+
}
|
|
76
|
+
throw err;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
curl(url, args, callback) {
|
|
81
|
+
return this.request(url, args, callback);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
requestThunk(url, args) {
|
|
85
|
+
//this.app.deprecate('[httpclient] Please use `request()` instead of `requestThunk()`');
|
|
86
|
+
return callback => {
|
|
87
|
+
this.request(url, args, (err, data, res) => {
|
|
88
|
+
if (err) {
|
|
89
|
+
return callback(err);
|
|
90
|
+
}
|
|
91
|
+
callback(null, {
|
|
92
|
+
data,
|
|
93
|
+
status: res.status,
|
|
94
|
+
headers: res.headers,
|
|
95
|
+
res,
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function normalizeConfig(httpConfig) {
|
|
103
|
+
const config = httpConfig;
|
|
104
|
+
|
|
105
|
+
// compatibility
|
|
106
|
+
if (typeof config.keepAlive === 'boolean') {
|
|
107
|
+
config.httpAgent.keepAlive = config.keepAlive;
|
|
108
|
+
config.httpsAgent.keepAlive = config.keepAlive;
|
|
109
|
+
}
|
|
110
|
+
if (config.timeout) {
|
|
111
|
+
config.timeout = Time.ms(config.timeout);
|
|
112
|
+
config.httpAgent.timeout = config.timeout;
|
|
113
|
+
config.httpsAgent.timeout = config.timeout;
|
|
114
|
+
}
|
|
115
|
+
// compatibility httpclient.freeSocketKeepAliveTimeout => httpclient.freeSocketTimeout
|
|
116
|
+
if (config.freeSocketKeepAliveTimeout && !config.freeSocketTimeout) {
|
|
117
|
+
config.freeSocketTimeout = config.freeSocketKeepAliveTimeout;
|
|
118
|
+
delete config.freeSocketKeepAliveTimeout;
|
|
119
|
+
}
|
|
120
|
+
if (config.freeSocketTimeout) {
|
|
121
|
+
config.freeSocketTimeout = Time.ms(config.freeSocketTimeout);
|
|
122
|
+
config.httpAgent.freeSocketTimeout = config.freeSocketTimeout;
|
|
123
|
+
config.httpsAgent.freeSocketTimeout = config.freeSocketTimeout;
|
|
124
|
+
} else {
|
|
125
|
+
// compatibility agent.freeSocketKeepAliveTimeout
|
|
126
|
+
if (config.httpAgent.freeSocketKeepAliveTimeout && !config.httpAgent.freeSocketTimeout) {
|
|
127
|
+
config.httpAgent.freeSocketTimeout = config.httpAgent.freeSocketKeepAliveTimeout;
|
|
128
|
+
delete config.httpAgent.freeSocketKeepAliveTimeout;
|
|
129
|
+
}
|
|
130
|
+
if (config.httpsAgent.freeSocketKeepAliveTimeout && !config.httpsAgent.freeSocketTimeout) {
|
|
131
|
+
config.httpsAgent.freeSocketTimeout = config.httpsAgent.freeSocketKeepAliveTimeout;
|
|
132
|
+
delete config.httpsAgent.freeSocketKeepAliveTimeout;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (typeof config.maxSockets === 'number') {
|
|
137
|
+
config.httpAgent.maxSockets = config.maxSockets;
|
|
138
|
+
config.httpsAgent.maxSockets = config.maxSockets;
|
|
139
|
+
}
|
|
140
|
+
if (typeof config.maxFreeSockets === 'number') {
|
|
141
|
+
config.httpAgent.maxFreeSockets = config.maxFreeSockets;
|
|
142
|
+
config.httpsAgent.maxFreeSockets = config.maxFreeSockets;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (config.httpAgent.timeout < 30000) {
|
|
146
|
+
Log.coreLogger.warn('[ee-core] [httpclient] config.httpclient.httpAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
|
|
147
|
+
config.httpAgent.timeout);
|
|
148
|
+
config.httpAgent.timeout = 30000;
|
|
149
|
+
}
|
|
150
|
+
if (config.httpsAgent.timeout < 30000) {
|
|
151
|
+
Log.coreLogger.warn('[ee-core] [httpclient] config.httpclient.httpsAgent.timeout(%s) can\'t below 30000, auto reset to 30000',
|
|
152
|
+
config.httpsAgent.timeout);
|
|
153
|
+
config.httpsAgent.timeout = 30000;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
if (typeof config.request.timeout === 'string') {
|
|
157
|
+
config.request.timeout = Time.ms(config.request.timeout);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
module.exports = HttpClient;
|