soajs.controller 4.2.37 → 4.2.39
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 +1 -0
- package/lib/request.js +44 -13
- package/mw/awareness/ha.js +1 -1
- package/mw/gotoService/proxyRequest.js +4 -4
- package/mw/gotoService/redirectToService.js +4 -4
- package/mw/gotoService/simpleRTS.js +4 -4
- package/mw/mt/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,6 +38,7 @@ Enabling CORS allows different domains to communicate with SOAJS via its gateway
|
|
|
38
38
|
More information on the Controller is available on the website section [Controller](https://soajsorg.atlassian.net/wiki/x/loAwb)
|
|
39
39
|
|
|
40
40
|
|
|
41
|
+
|
|
41
42
|
### License
|
|
42
43
|
*Copyright SOAJS All Rights Reserved.*
|
|
43
44
|
|
package/lib/request.js
CHANGED
|
@@ -18,6 +18,7 @@ function checkStatus(uri) {
|
|
|
18
18
|
const req = http.get(uri, (res) => {
|
|
19
19
|
if (res.statusCode === 200) {
|
|
20
20
|
onResponse = true;
|
|
21
|
+
res.resume();
|
|
21
22
|
resolve(res.statusCode === 200); // Resolve with true if 200, false otherwise
|
|
22
23
|
}
|
|
23
24
|
// res.on('data', () => { }); // Consume data to avoid issues (important!)
|
|
@@ -28,12 +29,12 @@ function checkStatus(uri) {
|
|
|
28
29
|
return reject(err);
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
|
-
res.on('close', () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
});
|
|
32
|
+
// res.on('close', () => {
|
|
33
|
+
// if (!onResponse) {
|
|
34
|
+
// onResponse = true;
|
|
35
|
+
// return reject(new Error("Closed"));
|
|
36
|
+
// }
|
|
37
|
+
// });
|
|
37
38
|
});
|
|
38
39
|
|
|
39
40
|
req.on('error', (err) => {
|
|
@@ -42,19 +43,26 @@ function checkStatus(uri) {
|
|
|
42
43
|
return reject(err);
|
|
43
44
|
}
|
|
44
45
|
});
|
|
45
|
-
req.on('close', () => {
|
|
46
|
+
// req.on('close', () => {
|
|
47
|
+
// if (!onResponse) {
|
|
48
|
+
// onResponse = true;
|
|
49
|
+
// return reject(new Error("Closed"));
|
|
50
|
+
// }
|
|
51
|
+
// });
|
|
52
|
+
|
|
53
|
+
req.setTimeout(5000, () => {
|
|
54
|
+
req.destroy();
|
|
46
55
|
if (!onResponse) {
|
|
47
56
|
onResponse = true;
|
|
48
|
-
return reject(new Error(
|
|
57
|
+
return reject(new Error('Request timed out'));
|
|
49
58
|
}
|
|
50
59
|
});
|
|
51
60
|
|
|
52
|
-
|
|
53
61
|
req.end();
|
|
54
62
|
});
|
|
55
63
|
}
|
|
56
64
|
|
|
57
|
-
function httpRequestLight({ uri, data = null, method = 'GET', headers = null, json = true }) {
|
|
65
|
+
function httpRequestLight({ uri, data = null, method = 'GET', headers = null, json = true, timeout = 8000 }) {
|
|
58
66
|
return new Promise((resolve, reject) => {
|
|
59
67
|
let onResponse = false;
|
|
60
68
|
let options = {};
|
|
@@ -96,6 +104,8 @@ function httpRequestLight({ uri, data = null, method = 'GET', headers = null, js
|
|
|
96
104
|
|
|
97
105
|
req.on('response', (res) => { // Listen for the 'response' event
|
|
98
106
|
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
107
|
+
onResponse = true;
|
|
108
|
+
res.resume();
|
|
99
109
|
return reject(new Error(`Status Code: ${res.statusCode}`));
|
|
100
110
|
}
|
|
101
111
|
|
|
@@ -106,7 +116,6 @@ function httpRequestLight({ uri, data = null, method = 'GET', headers = null, js
|
|
|
106
116
|
});
|
|
107
117
|
|
|
108
118
|
res.on('end', () => {
|
|
109
|
-
|
|
110
119
|
if (!onResponse) {
|
|
111
120
|
onResponse = true;
|
|
112
121
|
try {
|
|
@@ -145,6 +154,17 @@ function httpRequestLight({ uri, data = null, method = 'GET', headers = null, js
|
|
|
145
154
|
}
|
|
146
155
|
});
|
|
147
156
|
|
|
157
|
+
// Handle request timeout
|
|
158
|
+
req.on('timeout', () => {
|
|
159
|
+
req.destroy(); // IMPORTANT: Forcefully end the request
|
|
160
|
+
if (!onResponse) {
|
|
161
|
+
onResponse = true;
|
|
162
|
+
return reject(new Error('Request timed out'));
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
// Set the timeout on the request
|
|
166
|
+
req.setTimeout(timeout);
|
|
167
|
+
|
|
148
168
|
if (data) {
|
|
149
169
|
req.write(requestDataString);
|
|
150
170
|
}
|
|
@@ -153,7 +173,7 @@ function httpRequestLight({ uri, data = null, method = 'GET', headers = null, js
|
|
|
153
173
|
});
|
|
154
174
|
}
|
|
155
175
|
|
|
156
|
-
function httpRequest({ uri, data = null, body = null, qs = null, method = 'GET', headers = null, json = true }) {
|
|
176
|
+
function httpRequest({ uri, data = null, body = null, qs = null, method = 'GET', headers = null, json = true, timeout = 8000 }) {
|
|
157
177
|
return new Promise((resolve, reject) => {
|
|
158
178
|
data = data || body; // to be compatible with request package
|
|
159
179
|
|
|
@@ -270,6 +290,17 @@ function httpRequest({ uri, data = null, body = null, qs = null, method = 'GET',
|
|
|
270
290
|
}
|
|
271
291
|
});
|
|
272
292
|
|
|
293
|
+
// Handle request timeout
|
|
294
|
+
req.on('timeout', () => {
|
|
295
|
+
req.destroy(); // IMPORTANT: Forcefully end the request
|
|
296
|
+
if (!onResponse) {
|
|
297
|
+
onResponse = true;
|
|
298
|
+
return reject(new Error('Request timed out'));
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
// Set the timeout on the request
|
|
302
|
+
req.setTimeout(timeout);
|
|
303
|
+
|
|
273
304
|
if (data) {
|
|
274
305
|
req.write(requestDataString);
|
|
275
306
|
}
|
|
@@ -288,7 +319,7 @@ function proxyRequest(req, res, options, extraOptions = {}) {
|
|
|
288
319
|
} else {
|
|
289
320
|
proxyReq = http.request(options);
|
|
290
321
|
}
|
|
291
|
-
|
|
322
|
+
|
|
292
323
|
if (extraOptions && extraOptions.fetchProxReq) {
|
|
293
324
|
extraOptions.fetchProxReq(proxyReq);
|
|
294
325
|
}
|
package/mw/awareness/ha.js
CHANGED
|
@@ -240,7 +240,7 @@ let ha = {
|
|
|
240
240
|
return cb(hostname);
|
|
241
241
|
} else {
|
|
242
242
|
if (process.env.SOAJS_DEPLOY_HA === 'kubernetes' && serviceName && version) {
|
|
243
|
-
serviceName += "-v" + version + "-service";
|
|
243
|
+
// serviceName += "-v" + version + "-service";
|
|
244
244
|
return cb(env + "-" + serviceName + "-v" + version + "-service");
|
|
245
245
|
} else {
|
|
246
246
|
lib.getHostFromAPI(serviceName, version, cb);
|
|
@@ -79,10 +79,10 @@ module.exports = (configuration) => {
|
|
|
79
79
|
.then(() => { })
|
|
80
80
|
.catch((error) => {
|
|
81
81
|
req.soajs.log.error(error.message);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
if (req.soajs.controller.redirectedRequest) {
|
|
83
|
+
req.soajs.controller.redirectedRequest.destroy();
|
|
84
|
+
req.soajs.controller.redirectedRequest = null;
|
|
85
|
+
}
|
|
86
86
|
return req.soajs.controllerResponse(core.error.getError(135));
|
|
87
87
|
});
|
|
88
88
|
};
|
|
@@ -220,10 +220,10 @@ module.exports = (configuration) => {
|
|
|
220
220
|
})
|
|
221
221
|
.catch((err) => {
|
|
222
222
|
req.soajs.log.error(err.message + ' with [' + restServiceParams.name + (restServiceParams.version ? ('@' + restServiceParams.version) : '') + ']');
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
223
|
+
if (req.soajs.controller.redirectedRequest) {
|
|
224
|
+
req.soajs.controller.redirectedRequest.destroy();
|
|
225
|
+
req.soajs.controller.redirectedRequest = null;
|
|
226
|
+
}
|
|
227
227
|
if (!req.soajs.controller.monitorEndingReq) {
|
|
228
228
|
req.soajs.controllerResponse(core.error.getError(135));
|
|
229
229
|
}
|
|
@@ -60,10 +60,10 @@ module.exports = (configuration) => {
|
|
|
60
60
|
})
|
|
61
61
|
.catch((err) => {
|
|
62
62
|
req.soajs.log.error(err.code, err.message);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
if (req.soajs.controller.redirectedRequest) {
|
|
64
|
+
req.soajs.controller.redirectedRequest.destroy();
|
|
65
|
+
req.soajs.controller.redirectedRequest = null;
|
|
66
|
+
}
|
|
67
67
|
if (!req.soajs.controller.monitorEndingReq) {
|
|
68
68
|
return req.soajs.controllerResponse(core.error.getError(135));
|
|
69
69
|
}
|
package/mw/mt/index.js
CHANGED
|
@@ -325,6 +325,7 @@ module.exports = (configuration) => {
|
|
|
325
325
|
injectObj.awareness.interConnect.push(item);
|
|
326
326
|
} else {
|
|
327
327
|
req.soajs.log.debug(serviceName + " interConnect failed to fetch latestVersion for [" + item.name + "]");
|
|
328
|
+
injectObj.awareness.interConnect.push(item);
|
|
328
329
|
}
|
|
329
330
|
return callback();
|
|
330
331
|
});
|