@be-link/ecommerce-product-service-node-sdk 0.1.14 → 0.1.15
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/package.json +1 -1
- package/utils/http.js +19 -0
package/package.json
CHANGED
package/utils/http.js
CHANGED
|
@@ -42,6 +42,23 @@ const uuid_1 = require("uuid");
|
|
|
42
42
|
const axios_retry_1 = __importDefault(require("axios-retry"));
|
|
43
43
|
const request_context_1 = require("@fastify/request-context");
|
|
44
44
|
const safe_stable_stringify_1 = __importDefault(require("safe-stable-stringify"));
|
|
45
|
+
const http_1 = __importDefault(require("http"));
|
|
46
|
+
const https_1 = __importDefault(require("https"));
|
|
47
|
+
// 配置连接池
|
|
48
|
+
const httpAgent = new http_1.default.Agent({
|
|
49
|
+
keepAlive: true,
|
|
50
|
+
keepAliveMsecs: 30000, // 保持连接30秒
|
|
51
|
+
maxSockets: 100, // 每个主机最大并发连接数
|
|
52
|
+
maxFreeSockets: 10, // 空闲连接池大小
|
|
53
|
+
timeout: 60000, // socket 超时时间
|
|
54
|
+
});
|
|
55
|
+
const httpsAgent = new https_1.default.Agent({
|
|
56
|
+
keepAlive: true,
|
|
57
|
+
keepAliveMsecs: 30000,
|
|
58
|
+
maxSockets: 100,
|
|
59
|
+
maxFreeSockets: 10,
|
|
60
|
+
timeout: 60000,
|
|
61
|
+
});
|
|
45
62
|
(0, axios_retry_1.default)(axios_1.default, {
|
|
46
63
|
retries: 1,
|
|
47
64
|
retryCondition(error) {
|
|
@@ -70,6 +87,8 @@ async function callApi(url, request) {
|
|
|
70
87
|
'x-belink-pandora-roleid': pandoraRoleId,
|
|
71
88
|
},
|
|
72
89
|
timeout: 3000,
|
|
90
|
+
httpAgent,
|
|
91
|
+
httpsAgent,
|
|
73
92
|
});
|
|
74
93
|
const responseData = response.data;
|
|
75
94
|
return responseData.data;
|