soajs.controller 4.2.20 → 4.2.31
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/.dockerignore +74 -0
- package/.travis.yml +1 -1
- package/Dockerfile +1 -1
- package/lib/http.js +1 -1
- package/lib/request.js +381 -0
- package/modules/registry/local.js +65 -0
- package/mw/awareness/custom.js +26 -18
- package/mw/awarenessEnv/custom.js +40 -18
- package/mw/gotoService/index.js +17 -16
- package/mw/gotoService/lib/preRedirect.js +10 -14
- package/mw/gotoService/proxyRequest.js +62 -59
- package/mw/gotoService/redirectToService.js +170 -189
- package/mw/gotoService/simpleRTS.js +40 -39
- package/mw/lastSeen/index.js +52 -22
- package/mw/mt/utils.js +58 -58
- package/mw/response/index.js +7 -3
- package/package.json +2 -2
- package/profiles/solo.js +50 -0
- package/release +18 -0
- package/server/controller.js +4 -5
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
const get = (p, o) => p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o);
|
|
12
12
|
|
|
13
|
-
const
|
|
13
|
+
const { httpRequestLight, proxyRequestMonitor } = require("../../lib/request.js");
|
|
14
14
|
|
|
15
15
|
module.exports = (configuration) => {
|
|
16
16
|
|
|
@@ -26,178 +26,163 @@ module.exports = (configuration) => {
|
|
|
26
26
|
*/
|
|
27
27
|
return (req, res) => {
|
|
28
28
|
preRedirect(req, res, core, function (obj) {
|
|
29
|
-
let
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
let log_monitor = (doc) => {
|
|
43
|
-
let soamonitor = "soamonitor";
|
|
44
|
-
let soamonitorVersion = "1";
|
|
45
|
-
let port = get(["registry", "services", "soamonitor", "port"], req.soajs);
|
|
46
|
-
if (!port) {
|
|
47
|
-
port = "4050";
|
|
48
|
-
}
|
|
49
|
-
let api = "/monitor/item";
|
|
29
|
+
let log_monitor_triggered = false;
|
|
30
|
+
let log_monitor = (doc) => {
|
|
31
|
+
if (log_monitor_triggered) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
log_monitor_triggered = true;
|
|
35
|
+
let soamonitor = "soamonitor";
|
|
36
|
+
let soamonitorVersion = "1";
|
|
37
|
+
let port = get(["registry", "services", "soamonitor", "port"], req.soajs);
|
|
38
|
+
if (!port) {
|
|
39
|
+
port = "4050";
|
|
40
|
+
}
|
|
41
|
+
let api = "/monitor/item";
|
|
50
42
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
43
|
+
req.soajs.awareness.getHost(soamonitor, soamonitorVersion, function (host) {
|
|
44
|
+
if (!host) {
|
|
45
|
+
req.soajs.log.debug('Unable to find any healthy host for service ' + soamonitor);
|
|
46
|
+
} else {
|
|
47
|
+
if (doc && doc.body) {
|
|
48
|
+
doc.body = doc.body.toString();
|
|
49
|
+
}
|
|
50
|
+
if (doc && doc.response) {
|
|
51
|
+
doc.response = doc.response.toString();
|
|
52
|
+
}
|
|
53
|
+
let uri = "http://" + host + ":" + port + api;
|
|
54
|
+
let options = {
|
|
55
|
+
"method": "POST",
|
|
56
|
+
"uri": uri,
|
|
57
|
+
"data": doc,
|
|
58
|
+
"json": true
|
|
59
|
+
};
|
|
60
|
+
if (req.headers && req.headers.soajsinjectobj) {
|
|
61
|
+
options.headers = { "soajsinjectobj": req.headers.soajsinjectobj };
|
|
62
|
+
}
|
|
63
|
+
httpRequestLight(options)
|
|
64
|
+
.then((body) => {
|
|
74
65
|
if (body && !body.result) {
|
|
75
|
-
req.soajs.log.
|
|
66
|
+
req.soajs.log.debug(body);
|
|
76
67
|
}
|
|
68
|
+
})
|
|
69
|
+
.catch((error) => {
|
|
70
|
+
req.soajs.log.debug('Unable register monitor: ' + error.message);
|
|
77
71
|
});
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
let monitor = get(["registry", "custom", "gateway", "value", "gotoService", "monitor"], req.soajs);
|
|
82
|
-
let monitoObj = {
|
|
83
|
-
"time": {}
|
|
84
|
-
};
|
|
85
|
-
let monitor_service_blacklist = false;
|
|
86
|
-
if (monitor && monitor.blacklist) {
|
|
87
|
-
if (Array.isArray(monitor.blacklist) && monitor.blacklist.length > 0) {
|
|
88
|
-
if (monitor.blacklist.includes(req.soajs.controller.serviceParams.name)) {
|
|
89
|
-
monitor_service_blacklist = true;
|
|
90
|
-
}
|
|
91
72
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
let monitor = get(["registry", "custom", "gateway", "value", "gotoService", "monitor"], req.soajs);
|
|
77
|
+
let monitoObj = {
|
|
78
|
+
"time": {}
|
|
79
|
+
};
|
|
80
|
+
let monitor_service_blacklist = false;
|
|
81
|
+
if (monitor && monitor.blacklist) {
|
|
82
|
+
if (Array.isArray(monitor.blacklist) && monitor.blacklist.length > 0) {
|
|
83
|
+
if (monitor.blacklist.includes(req.soajs.controller.serviceParams.name)) {
|
|
95
84
|
monitor_service_blacklist = true;
|
|
96
|
-
if (monitor.whitelist.includes(req.soajs.controller.serviceParams.name)) {
|
|
97
|
-
monitor_service_blacklist = false;
|
|
98
|
-
}
|
|
99
85
|
}
|
|
100
86
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (monitor && !monitor_service_blacklist && monitor.req_info) {
|
|
109
|
-
monitoObj.port = req.soajs.controller.serviceParams.registry.port;
|
|
110
|
-
monitoObj.url = req.soajs.controller.serviceParams.url;
|
|
111
|
-
monitoObj.host = req.host;
|
|
112
|
-
}
|
|
113
|
-
if (monitor && !monitor_service_blacklist && monitor.req_header) {
|
|
114
|
-
monitoObj.headers = req.headers;
|
|
115
|
-
}
|
|
116
|
-
if (monitor && !monitor_service_blacklist && monitor.req_query) {
|
|
117
|
-
monitoObj.query = req.query;
|
|
87
|
+
}
|
|
88
|
+
if (monitor && monitor.whitelist) {
|
|
89
|
+
if (Array.isArray(monitor.whitelist) && monitor.whitelist.length > 0) {
|
|
90
|
+
monitor_service_blacklist = true;
|
|
91
|
+
if (monitor.whitelist.includes(req.soajs.controller.serviceParams.name)) {
|
|
92
|
+
monitor_service_blacklist = false;
|
|
93
|
+
}
|
|
118
94
|
}
|
|
95
|
+
}
|
|
96
|
+
if (monitor && !monitor_service_blacklist) {
|
|
97
|
+
monitoObj.name = req.soajs.controller.serviceParams.name;
|
|
98
|
+
monitoObj.version = req.soajs.controller.serviceParams.version;
|
|
99
|
+
monitoObj.api = req.soajs.controller.serviceParams.parsedUrl.pathname;
|
|
100
|
+
monitoObj.method = req.method;
|
|
101
|
+
monitoObj.time.req_start = new Date().getTime();
|
|
102
|
+
}
|
|
103
|
+
if (monitor && !monitor_service_blacklist && monitor.req_info) {
|
|
104
|
+
monitoObj.port = req.soajs.controller.serviceParams.registry.port;
|
|
105
|
+
monitoObj.url = req.soajs.controller.serviceParams.url;
|
|
106
|
+
monitoObj.host = req.host;
|
|
107
|
+
}
|
|
108
|
+
if (monitor && !monitor_service_blacklist && monitor.req_header) {
|
|
109
|
+
monitoObj.headers = req.headers;
|
|
110
|
+
}
|
|
111
|
+
if (monitor && !monitor_service_blacklist && monitor.req_query) {
|
|
112
|
+
monitoObj.query = req.query;
|
|
113
|
+
}
|
|
119
114
|
|
|
120
|
-
|
|
121
|
-
req.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
req.
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
115
|
+
if (monitor && !monitor_service_blacklist && monitor.req_body &&
|
|
116
|
+
(req.method === 'POST' || req.method === 'PUT' || req.method === 'PATCH' || req.method === 'DELETE')) {
|
|
117
|
+
let allowedContentType = false;
|
|
118
|
+
let isStream = false;
|
|
119
|
+
req.on("data", (chunk) => {
|
|
120
|
+
let resContentType = req.headers['content-type'];
|
|
121
|
+
if (resContentType) {
|
|
122
|
+
if (!allowedContentType) {
|
|
123
|
+
allowedContentType = resContentType.match(/application\/json|text\/plain/i);
|
|
124
|
+
}
|
|
125
|
+
if (!isStream) {
|
|
126
|
+
isStream = resContentType.match(/stream/i);
|
|
127
|
+
}
|
|
132
128
|
}
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
129
|
+
if (!isStream && allowedContentType) {
|
|
130
|
+
if (!monitoObj.body) {
|
|
131
|
+
monitoObj.time.req_body_start = new Date().getTime();
|
|
132
|
+
monitoObj.body = chunk;
|
|
133
|
+
} else {
|
|
134
|
+
monitoObj.body += chunk;
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
monitoObj.body = "{\"contentType\": \"is stream or not allowed\", \"value': \"" + resContentType + "\"}";
|
|
136
138
|
}
|
|
137
139
|
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if (
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if (!allowedContentType) {
|
|
148
|
-
allowedContentType = resContentType.match(/application\/json|text\/plain/i);
|
|
149
|
-
}
|
|
150
|
-
if (!isStream) {
|
|
151
|
-
isStream = resContentType.match(/stream/i);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (!isStream && allowedContentType) {
|
|
155
|
-
if (!monitoObj.body) {
|
|
156
|
-
monitoObj.time.req_body_start = new Date().getTime();
|
|
157
|
-
monitoObj.body = chunk;
|
|
158
|
-
} else {
|
|
159
|
-
monitoObj.body += chunk;
|
|
160
|
-
}
|
|
161
|
-
} else {
|
|
162
|
-
monitoObj.body = "{\"contentType\": \"is stream or not allowed\", \"value': \"" + resContentType + "\"}";
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
req.on("end", () => {
|
|
166
|
-
let resContentType = req.headers['content-length'];
|
|
167
|
-
if (resContentType) {
|
|
168
|
-
if (!allowedContentType) {
|
|
169
|
-
allowedContentType = resContentType.match(/application\/json|text\/plain/i);
|
|
170
|
-
}
|
|
171
|
-
if (!isStream) {
|
|
172
|
-
isStream = resContentType.match(/stream/i);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (!isStream) {
|
|
176
|
-
if (req.soajs.controller.redirectedRequest) {
|
|
177
|
-
req.soajs.controller.redirectedRequest.end();
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (!isStream && allowedContentType) {
|
|
181
|
-
monitoObj.time.req_body_end = new Date().getTime();
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
} else {
|
|
185
|
-
req.pipe(req.soajs.controller.redirectedRequest);
|
|
140
|
+
req.on("end", () => {
|
|
141
|
+
let resContentType = req.headers['content-length'];
|
|
142
|
+
if (resContentType) {
|
|
143
|
+
if (!allowedContentType) {
|
|
144
|
+
allowedContentType = resContentType.match(/application\/json|text\/plain/i);
|
|
145
|
+
}
|
|
146
|
+
if (!isStream) {
|
|
147
|
+
isStream = resContentType.match(/stream/i);
|
|
148
|
+
}
|
|
186
149
|
}
|
|
150
|
+
if (!isStream && allowedContentType) {
|
|
151
|
+
monitoObj.time.req_body_end = new Date().getTime();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let restServiceParams = req.soajs.controller.serviceParams;
|
|
157
|
+
let requestOptions = {};
|
|
158
|
+
try {
|
|
159
|
+
const urlObj = new URL(obj.uri);
|
|
160
|
+
requestOptions = {
|
|
161
|
+
"hostname": urlObj.hostname,
|
|
162
|
+
"port": urlObj.port,
|
|
163
|
+
"path": urlObj.pathname + urlObj.search,
|
|
164
|
+
"method": req.method.toUpperCase(),
|
|
165
|
+
'headers': req.headers
|
|
166
|
+
};
|
|
167
|
+
if (obj.config.authorization) {
|
|
168
|
+
isRequestAuthorized(req, core, requestOptions);
|
|
187
169
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
170
|
+
} catch (e) {
|
|
171
|
+
req.soajs.log.error(e.message + ' @catch with [' + restServiceParams.name + (restServiceParams.version ? ('@' + restServiceParams.version) : '') + ']');
|
|
172
|
+
if (!req.soajs.controller.monitorEndingReq) {
|
|
173
|
+
return req.soajs.controllerResponse(core.error.getError(135));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
let allowedContentType = false;
|
|
178
|
+
let isStream = false;
|
|
179
|
+
let resContentType = "";
|
|
180
|
+
const extraOptions = {};
|
|
181
|
+
|
|
182
|
+
if (monitor && !monitor_service_blacklist && monitor.req_response) {
|
|
183
|
+
extraOptions.events = {
|
|
184
|
+
"response": (_resContentType) => {
|
|
185
|
+
resContentType = _resContentType;
|
|
201
186
|
if (resContentType) {
|
|
202
187
|
if (!allowedContentType) {
|
|
203
188
|
allowedContentType = resContentType.match(/application\/json|text\/plain/i);
|
|
@@ -206,6 +191,9 @@ module.exports = (configuration) => {
|
|
|
206
191
|
isStream = resContentType.match(/stream/i);
|
|
207
192
|
}
|
|
208
193
|
}
|
|
194
|
+
monitoObj.time.res_start = new Date().getTime();
|
|
195
|
+
},
|
|
196
|
+
"data": (chunk) => {
|
|
209
197
|
if (!isStream && allowedContentType) {
|
|
210
198
|
if (!monitoObj.response) {
|
|
211
199
|
monitoObj.response = chunk;
|
|
@@ -215,41 +203,34 @@ module.exports = (configuration) => {
|
|
|
215
203
|
} else {
|
|
216
204
|
monitoObj.response = "{\"contentType\": \"is stream or not allowed\", \"value': \"" + resContentType + "\"}";
|
|
217
205
|
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
206
|
+
},
|
|
207
|
+
"fetchProxReq": (proxyReq) => {
|
|
208
|
+
req.soajs.controller.redirectedRequest = proxyReq;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
proxyRequestMonitor(req, res, requestOptions, extraOptions)
|
|
214
|
+
.then(() => {
|
|
215
|
+
if (monitor && !monitor_service_blacklist && monitor.req_response) {
|
|
229
216
|
monitoObj.time.res_end = new Date().getTime();
|
|
230
217
|
log_monitor(monitoObj);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
218
|
+
}
|
|
219
|
+
})
|
|
220
|
+
.catch((err) => {
|
|
221
|
+
req.soajs.log.error(err.message + ' with [' + restServiceParams.name + (restServiceParams.version ? ('@' + restServiceParams.version) : '') + ']');
|
|
222
|
+
// if (req.soajs.controller.redirectedRequest) {
|
|
223
|
+
// req.soajs.controller.redirectedRequest.destroy();
|
|
224
|
+
// req.soajs.controller.redirectedRequest = null;
|
|
225
|
+
// }
|
|
226
|
+
if (!req.soajs.controller.monitorEndingReq) {
|
|
227
|
+
req.soajs.controllerResponse(core.error.getError(135));
|
|
228
|
+
}
|
|
229
|
+
if (monitor && !monitor_service_blacklist && monitor.req_response) {
|
|
236
230
|
monitoObj.time.res_end = new Date().getTime();
|
|
237
231
|
log_monitor(monitoObj);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
req.soajs.controller.redirectedRequest.pipe(res);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
} catch (e) {
|
|
244
|
-
req.soajs.log.error(e.message + ' @catch with [' + restServiceParams.name + (restServiceParams.version ? ('@' + restServiceParams.version) : '') + ']');
|
|
245
|
-
if (req.soajs.controller.redirectedRequest) {
|
|
246
|
-
req.soajs.controller.redirectedRequest.destroy();
|
|
247
|
-
req.soajs.controller.redirectedRequest = null;
|
|
248
|
-
}
|
|
249
|
-
if (!req.soajs.controller.monitorEndingReq) {
|
|
250
|
-
return req.soajs.controllerResponse(core.error.getError(135));
|
|
251
|
-
}
|
|
252
|
-
}
|
|
232
|
+
}
|
|
233
|
+
});
|
|
253
234
|
});
|
|
254
235
|
};
|
|
255
236
|
};
|
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
* found in the LICENSE file at the root of this repository
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const url = require('url');
|
|
12
|
-
let http = require('http');
|
|
11
|
+
// const url = require('url');
|
|
12
|
+
// let http = require('http');
|
|
13
|
+
const { proxyRequest } = require("../../lib/request.js");
|
|
13
14
|
|
|
14
15
|
module.exports = (configuration) => {
|
|
15
|
-
|
|
16
|
+
|
|
16
17
|
let core = configuration.core;
|
|
17
18
|
let isRequestAuthorized = require("./lib/isRequestAuthorized.js");
|
|
18
19
|
let preRedirect = require("./lib/preRedirect.js");
|
|
19
|
-
|
|
20
|
+
|
|
20
21
|
/**
|
|
21
22
|
*
|
|
22
23
|
* @param req
|
|
@@ -25,48 +26,48 @@ module.exports = (configuration) => {
|
|
|
25
26
|
*/
|
|
26
27
|
return (req, res) => {
|
|
27
28
|
preRedirect(req, res, core, function (obj) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
let requestOptions = url.parse(obj.uri);
|
|
31
|
-
requestOptions.headers = req.headers;
|
|
32
|
-
requestOptions.method = req.method;
|
|
33
|
-
requestOptions.agent = false;
|
|
34
|
-
requestOptions.headers.host = requestOptions.host;
|
|
35
|
-
|
|
36
|
-
if (obj.config.authorization) {
|
|
37
|
-
isRequestAuthorized(req, core, requestOptions);
|
|
38
|
-
}
|
|
29
|
+
let requestConfig = {};
|
|
39
30
|
try {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
req.soajs.controller.redirectedRequest = null;
|
|
53
|
-
}
|
|
54
|
-
if (!req.soajs.controller.monitorEndingReq) {
|
|
55
|
-
return req.soajs.controllerResponse(core.error.getError(135));
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
req.pipe(req.soajs.controller.redirectedRequest, {end: true});
|
|
59
|
-
// req.resume();
|
|
31
|
+
const urlObj = new URL(obj.uri);
|
|
32
|
+
requestConfig = {
|
|
33
|
+
"hostname": urlObj.hostname,
|
|
34
|
+
"port": urlObj.port,
|
|
35
|
+
"path": urlObj.pathname + urlObj.search,
|
|
36
|
+
"method": req.method.toUpperCase(),
|
|
37
|
+
'headers': req.headers
|
|
38
|
+
};
|
|
39
|
+
requestConfig.headers.host = urlObj.hostname;
|
|
40
|
+
if (obj.config.authorization) {
|
|
41
|
+
isRequestAuthorized(req, core, requestConfig);
|
|
42
|
+
}
|
|
60
43
|
} catch (e) {
|
|
61
44
|
req.soajs.log.error(e.message + " @catch");
|
|
62
|
-
if (req.soajs.controller.redirectedRequest) {
|
|
63
|
-
req.soajs.controller.redirectedRequest.destroy();
|
|
64
|
-
req.soajs.controller.redirectedRequest = null;
|
|
65
|
-
}
|
|
66
45
|
if (!req.soajs.controller.monitorEndingReq) {
|
|
67
46
|
return req.soajs.controllerResponse(core.error.getError(135));
|
|
68
47
|
}
|
|
69
48
|
}
|
|
49
|
+
const extraOptions = {
|
|
50
|
+
"resHEaders": {
|
|
51
|
+
"access-control-allow-origin": "*"
|
|
52
|
+
},
|
|
53
|
+
"fetchProxReq": (proxyReq) => {
|
|
54
|
+
req.soajs.controller.redirectedRequest = proxyReq;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
proxyRequest(req, res, requestConfig, extraOptions)
|
|
59
|
+
.then(() => {
|
|
60
|
+
})
|
|
61
|
+
.catch((err) => {
|
|
62
|
+
req.soajs.log.error(err.code, err.message);
|
|
63
|
+
// if (req.soajs.controller.redirectedRequest) {
|
|
64
|
+
// req.soajs.controller.redirectedRequest.destroy();
|
|
65
|
+
// req.soajs.controller.redirectedRequest = null;
|
|
66
|
+
// }
|
|
67
|
+
if (!req.soajs.controller.monitorEndingReq) {
|
|
68
|
+
return req.soajs.controllerResponse(core.error.getError(135));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
70
71
|
});
|
|
71
72
|
};
|
|
72
73
|
};
|
package/mw/lastSeen/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* found in the LICENSE file at the root of this repository
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const { httpRequest } = require("../../lib/request.js");
|
|
12
12
|
const get = (p, o) => p.reduce((xs, x) => (xs && xs[x]) ? xs[x] : null, o);
|
|
13
13
|
|
|
14
14
|
/**
|
|
@@ -45,32 +45,62 @@ module.exports = () => {
|
|
|
45
45
|
item.port = req.soajs.registry.services[item.name].port;
|
|
46
46
|
|
|
47
47
|
let options = {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
"uri": "http://" + item.host + ":" + item.port + item.api,
|
|
49
|
+
"json": true,
|
|
50
|
+
"method": "POST"
|
|
51
51
|
};
|
|
52
52
|
if (req.headers && req.headers.soajsinjectobj) {
|
|
53
53
|
options.headers = { "soajsinjectobj": req.headers.soajsinjectobj };
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (body.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
55
|
+
httpRequest(options)
|
|
56
|
+
.then(() => { })
|
|
57
|
+
.catch(({ error, body }) => {
|
|
58
|
+
if (error) {
|
|
59
|
+
req.soajs.log.debug("lastSeen failed for [" + item.name + "@" + item.version + " " + item.api + "]");
|
|
60
|
+
req.soajs.log.debug("lastSeen " + error.message);
|
|
61
|
+
} else if (!body.result) {
|
|
62
|
+
let errorMsg = "";
|
|
63
|
+
if (body.errors && body.errors && body.errors.details && body.errors.details.length > 0) {
|
|
64
|
+
body.errors.details.forEach((detail) => {
|
|
65
|
+
if (errorMsg === "") {
|
|
66
|
+
errorMsg += detail.message;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
errorMsg += " - " + detail.message;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
req.soajs.log.debug("lastSeen", errorMsg);
|
|
70
74
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// let options = {
|
|
78
|
+
// method: "post",
|
|
79
|
+
// uri: "http://" + item.host + ":" + item.port + item.api,
|
|
80
|
+
// json: true
|
|
81
|
+
// };
|
|
82
|
+
// if (req.headers && req.headers.soajsinjectobj) {
|
|
83
|
+
// options.headers = { "soajsinjectobj": req.headers.soajsinjectobj };
|
|
84
|
+
// }
|
|
85
|
+
// request(options, (error, response, body) => {
|
|
86
|
+
// if (error) {
|
|
87
|
+
// req.soajs.log.debug("lastSeen failed for [" + item.name + "@" + item.version + " " + item.api + "]");
|
|
88
|
+
// req.soajs.log.debug("lastSeen " + error.message);
|
|
89
|
+
// } else if (!body.result) {
|
|
90
|
+
// let errorMsg = "";
|
|
91
|
+
// if (body.errors && body.errors && body.errors.details && body.errors.details.length > 0) {
|
|
92
|
+
// body.errors.details.forEach((detail) => {
|
|
93
|
+
// if (errorMsg === "") {
|
|
94
|
+
// errorMsg += detail.message;
|
|
95
|
+
// }
|
|
96
|
+
// else {
|
|
97
|
+
// errorMsg += " - " + detail.message;
|
|
98
|
+
// }
|
|
99
|
+
// });
|
|
100
|
+
// }
|
|
101
|
+
// req.soajs.log.debug("lastSeen", errorMsg);
|
|
102
|
+
// }
|
|
103
|
+
// });
|
|
74
104
|
} else {
|
|
75
105
|
req.soajs.log.debug("lastSeen failed with no host for [" + item.name + "@" + item.version + " " + item.api + "]");
|
|
76
106
|
}
|