@resolveio/server-lib 12.4.2 → 12.4.3
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/managers/method.manager.js +33 -37
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +90 -95
- package/managers/mongo.manager.js.map +1 -1
- package/managers/subscription.manager.js +86 -100
- package/managers/subscription.manager.js.map +1 -1
- package/package.json +1 -1
- package/server-app.d.ts +1 -0
- package/server-app.js +139 -126
- package/server-app.js.map +1 -1
package/server-app.js
CHANGED
|
@@ -74,6 +74,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
74
74
|
this._msgQueueRunning = false;
|
|
75
75
|
this.sesMail = false;
|
|
76
76
|
this.standardProgram = false;
|
|
77
|
+
this._rebootFlag = false;
|
|
77
78
|
this.LOGGER = 'ERROR'; //ERROR / DEBUG
|
|
78
79
|
this._clientRoutes = [];
|
|
79
80
|
this._lastErrorMsg = null;
|
|
@@ -172,16 +173,26 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
172
173
|
}); });
|
|
173
174
|
//PM2 wants to reboot/restart
|
|
174
175
|
process.on('SIGINT', function (err) {
|
|
176
|
+
_this._rebootFlag = true;
|
|
175
177
|
var interval = setInterval(function () {
|
|
176
178
|
if (!_this._monitorManagerFunction.getActiveMonitorFunctions().length &&
|
|
177
|
-
_this._monitorManagerFunction.getLastCompletedMonitorFunction()
|
|
178
|
-
|
|
179
|
+
(!_this._monitorManagerFunction.getLastCompletedMonitorFunction() ||
|
|
180
|
+
_this._monitorManagerFunction.getLastCompletedMonitorFunction() &&
|
|
181
|
+
Date.now() >= _this._monitorManagerFunction.getLastCompletedMonitorFunction().endTime.getTime() + 2500) &&
|
|
179
182
|
!_this._msgQueue.length &&
|
|
180
183
|
!_this._msgQueueRunning &&
|
|
181
184
|
!_this._offlineUpdates.length) {
|
|
182
185
|
clearInterval(interval);
|
|
183
186
|
process.exit(err ? 1 : 0);
|
|
184
187
|
}
|
|
188
|
+
else {
|
|
189
|
+
_this.getWSList().forEach(function (ws) {
|
|
190
|
+
if (!_this._msgQueue.some(function (a) { return a.ws['id_socket'] === ws['id_socket']; }) &&
|
|
191
|
+
!_this._offlineUpdates.some(function (a) { return a['id_socket'] === ws['id_socket']; })) {
|
|
192
|
+
_this.unsubscribeWS(ws);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
185
196
|
}, 100);
|
|
186
197
|
});
|
|
187
198
|
if (this.LOGGER === 'DEBUG') {
|
|
@@ -278,53 +289,58 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
278
289
|
var infoData, token;
|
|
279
290
|
var _this = this;
|
|
280
291
|
return __generator(this, function (_a) {
|
|
281
|
-
if (this.
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
infoData = info.req.headers['sec-websocket-protocol'].split(/,/);
|
|
285
|
-
if (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {
|
|
286
|
-
cb(false, 401, 'Unauthorized');
|
|
292
|
+
if (this._rebootFlag) {
|
|
293
|
+
cb(false, 409, 'Unable To Process');
|
|
287
294
|
}
|
|
288
295
|
else {
|
|
289
|
-
|
|
290
|
-
|
|
296
|
+
if (this.LOGGER === 'DEBUG') {
|
|
297
|
+
console.log('Verify Client', info, cb);
|
|
298
|
+
}
|
|
299
|
+
infoData = info.req.headers['sec-websocket-protocol'].split(/,/);
|
|
300
|
+
if (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {
|
|
291
301
|
cb(false, 401, 'Unauthorized');
|
|
292
302
|
}
|
|
293
303
|
else {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
304
|
+
token = infoData[0];
|
|
305
|
+
if (!token) {
|
|
306
|
+
cb(false, 401, 'Unauthorized');
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
jwt.verify(token, this._serverConfig['JWT_SECRET'], function (err, decoded) { return __awaiter(_this, void 0, void 0, function () {
|
|
310
|
+
var user, err_1;
|
|
311
|
+
return __generator(this, function (_a) {
|
|
312
|
+
switch (_a.label) {
|
|
313
|
+
case 0:
|
|
314
|
+
if (!err) return [3 /*break*/, 1];
|
|
315
|
+
cb(false, 401, 'Unauthorized');
|
|
316
|
+
return [3 /*break*/, 5];
|
|
317
|
+
case 1:
|
|
318
|
+
info.req['id_user'] = decoded['id_user'];
|
|
319
|
+
_a.label = 2;
|
|
320
|
+
case 2:
|
|
321
|
+
_a.trys.push([2, 4, , 5]);
|
|
322
|
+
return [4 /*yield*/, user_collection_1.Users.findById(decoded['id_user'])];
|
|
323
|
+
case 3:
|
|
324
|
+
user = _a.sent();
|
|
325
|
+
if (user) {
|
|
326
|
+
info.req['user'] = user.fullname;
|
|
327
|
+
info.req['user_readonly'] = user.readonly || false;
|
|
328
|
+
info.req['doc_user'] = user;
|
|
329
|
+
cb(true);
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
332
|
+
cb(false);
|
|
333
|
+
}
|
|
334
|
+
return [3 /*break*/, 5];
|
|
335
|
+
case 4:
|
|
336
|
+
err_1 = _a.sent();
|
|
317
337
|
cb(false);
|
|
318
|
-
|
|
319
|
-
return [
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
case 5: return [2 /*return*/];
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
}); });
|
|
338
|
+
return [3 /*break*/, 5];
|
|
339
|
+
case 5: return [2 /*return*/];
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}); });
|
|
343
|
+
}
|
|
328
344
|
}
|
|
329
345
|
}
|
|
330
346
|
return [2 /*return*/];
|
|
@@ -393,7 +409,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
393
409
|
});
|
|
394
410
|
// On data received (message)
|
|
395
411
|
ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
396
|
-
var parseErrorFound, socketData, messageRoute_1, messageDate, messageId, type, subType, pub, serverRes, i, update, data, serverResMethod, updateRoute, updateDate, updateMessageId, updateType, method, methodLatencyId, err_2;
|
|
412
|
+
var parseErrorFound, socketData, messageRoute_1, messageDate, messageId, type, subType, pub, serverRes, offlineUpdates, i, update, data, serverResMethod, updateRoute, updateDate, updateMessageId, updateType, method, methodLatencyId, err_2;
|
|
397
413
|
var _a;
|
|
398
414
|
var _this = this;
|
|
399
415
|
return __generator(this, function (_b) {
|
|
@@ -465,12 +481,13 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
465
481
|
}
|
|
466
482
|
});
|
|
467
483
|
}
|
|
468
|
-
this._offlineUpdates
|
|
484
|
+
this._offlineUpdates.push(ws);
|
|
485
|
+
offlineUpdates = socketData[4];
|
|
469
486
|
i = 0;
|
|
470
487
|
_b.label = 2;
|
|
471
488
|
case 2:
|
|
472
|
-
if (!(i <
|
|
473
|
-
update =
|
|
489
|
+
if (!(i < offlineUpdates.length)) return [3 /*break*/, 9];
|
|
490
|
+
update = offlineUpdates[i];
|
|
474
491
|
data = update.data;
|
|
475
492
|
serverResMethod = {
|
|
476
493
|
messageId: update.data[2],
|
|
@@ -540,7 +557,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
540
557
|
i++;
|
|
541
558
|
return [3 /*break*/, 2];
|
|
542
559
|
case 9:
|
|
543
|
-
this._offlineUpdates
|
|
560
|
+
this._offlineUpdates.splice(this._offlineUpdates.map(function (a) { return a['id_socket']; }).indexOf(ws['id_socket']), 1);
|
|
544
561
|
return [3 /*break*/, 11];
|
|
545
562
|
case 10:
|
|
546
563
|
this._msgQueue.splice(0, 0, {
|
|
@@ -588,92 +605,88 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
588
605
|
});
|
|
589
606
|
}, 20000);
|
|
590
607
|
setInterval(function () {
|
|
608
|
+
var _a;
|
|
591
609
|
if (!_this._msgQueueRunning) {
|
|
592
610
|
if (_this._msgQueue.length) {
|
|
593
611
|
_this._msgQueueRunning = true;
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
if (
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
id_user: ws['id_user'] || '',
|
|
628
|
-
user: ws['user'] || '',
|
|
629
|
-
messageId: messageId,
|
|
630
|
-
route: messageRoute
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
var serverRes = {
|
|
612
|
+
_this._debugMsgQueue += 1;
|
|
613
|
+
var msg = _this._msgQueue[_this._msgQueue.length - 1];
|
|
614
|
+
var data = msg.data;
|
|
615
|
+
var ws_1 = msg.ws;
|
|
616
|
+
var messageRoute = data.shift();
|
|
617
|
+
var messageDate = data.shift();
|
|
618
|
+
var messageId = data.shift();
|
|
619
|
+
var type = data.shift();
|
|
620
|
+
// Method call
|
|
621
|
+
if (type === 'method') {
|
|
622
|
+
var method = data.shift();
|
|
623
|
+
if (ws_1['user_readonly']) {
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
var methodLatencyId = mongo_manager_1.objectIdHexString();
|
|
627
|
+
log_method_latency_collection_1.LogMethodLatencies.create({
|
|
628
|
+
_id: methodLatencyId,
|
|
629
|
+
__v: 0,
|
|
630
|
+
date_start: new Date(),
|
|
631
|
+
date_end: null,
|
|
632
|
+
latency_ms: 0,
|
|
633
|
+
method: method
|
|
634
|
+
});
|
|
635
|
+
if (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers') {
|
|
636
|
+
log_collection_1.Logs.insertOne({
|
|
637
|
+
_id: mongo_manager_1.objectIdHexString(),
|
|
638
|
+
type: 'client-request',
|
|
639
|
+
collection: '',
|
|
640
|
+
id_document: '',
|
|
641
|
+
payload: common_1.getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',
|
|
642
|
+
method: method,
|
|
643
|
+
id_user: ws_1['id_user'] || '',
|
|
644
|
+
user: ws_1['user'] || '',
|
|
634
645
|
messageId: messageId,
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
};
|
|
638
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
639
|
-
ws.send(JSON.stringify(serverRes), function (error) {
|
|
640
|
-
if (error) {
|
|
641
|
-
console.log('Error on WS: ', error);
|
|
642
|
-
_this.unsubscribeWS(ws);
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
|
-
}
|
|
646
|
-
if (_this._methodManager._methods[method]) {
|
|
647
|
-
(_a = _this._methodManager).callMethod.apply(_a, __spreadArrays([methodLatencyId, ws, messageDate, messageId, method], data));
|
|
648
|
-
}
|
|
649
|
-
else {
|
|
650
|
-
console.log('Could not find method: ' + method);
|
|
651
|
-
}
|
|
646
|
+
route: messageRoute
|
|
647
|
+
});
|
|
652
648
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
ws.send(JSON.stringify(res.response), function (error) {
|
|
664
|
-
if (error) {
|
|
665
|
-
console.log('Error on WS: ', error);
|
|
666
|
-
_this.unsubscribeWS(ws);
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
}
|
|
649
|
+
var serverRes = {
|
|
650
|
+
messageId: messageId,
|
|
651
|
+
hasError: false,
|
|
652
|
+
data: 'ACK'
|
|
653
|
+
};
|
|
654
|
+
if (ws_1 && ws_1.readyState === ws_1.OPEN) {
|
|
655
|
+
ws_1.send(JSON.stringify(serverRes), function (error) {
|
|
656
|
+
if (error) {
|
|
657
|
+
console.log('Error on WS: ', error);
|
|
658
|
+
_this.unsubscribeWS(ws_1);
|
|
670
659
|
}
|
|
671
|
-
}
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
if (_this._methodManager._methods[method]) {
|
|
663
|
+
(_a = _this._methodManager).callMethod.apply(_a, __spreadArrays([methodLatencyId, ws_1, messageDate, messageId, method], data));
|
|
664
|
+
}
|
|
665
|
+
else {
|
|
666
|
+
console.log('Could not find method: ' + method);
|
|
672
667
|
}
|
|
673
|
-
};
|
|
674
|
-
for (var i = _this._msgQueue.length - 1; i >= 0; i--) {
|
|
675
|
-
_loop_1(i);
|
|
676
668
|
}
|
|
669
|
+
else if (type === 'methodResponse') {
|
|
670
|
+
var method = data.shift();
|
|
671
|
+
method_response_collection_1.MethodResponses.findOne({ $and: [
|
|
672
|
+
{ id_user: ws_1['id_user'] },
|
|
673
|
+
{ message_id: messageId },
|
|
674
|
+
{ method: method },
|
|
675
|
+
{ date: messageDate }
|
|
676
|
+
] }).then(function (res) {
|
|
677
|
+
if (res) {
|
|
678
|
+
if (ws_1 && ws_1.readyState === ws_1.OPEN) {
|
|
679
|
+
ws_1.send(JSON.stringify(res.response), function (error) {
|
|
680
|
+
if (error) {
|
|
681
|
+
console.log('Error on WS: ', error);
|
|
682
|
+
_this.unsubscribeWS(ws_1);
|
|
683
|
+
}
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}, function (err) { });
|
|
688
|
+
}
|
|
689
|
+
_this._msgQueue.splice(_this._msgQueue.length - 1, 1);
|
|
677
690
|
_this._msgQueueRunning = false;
|
|
678
691
|
}
|
|
679
692
|
}
|
package/server-app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/server-app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA4C;AAC5C,iCAAmC;AACnC,wCAA0C;AAC1C,kDAAoD;AACpD,8BAAgC;AAChC,kCAAoC;AACpC,6BAAoC;AACpC,uDAAuD;AACvD,+BAAiC;AAEjC,wCAAqE;AAErE,0DAA6D;AAC7D,wDAAsD;AACtD,4DAA0D;AAC1D,wEAAsE;AACtE,8DAAoF;AAIpF,uFAA2E;AAC3E,+DAAoD;AACpD,6FAAiF;AACjF,iEAAsD;AAEtD,oCAA8C;AAC9C,oCAA8C;AAC9C,wCAAkD;AAClD,iCAA0C;AAE1C;IA4BC,6BAAY,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe;QAAvF,iBAqKC;QA1LO,oBAAe,GAAG,EAAE,CAAC;QACrB,cAAS,GAAG,EAAE,CAAC;QACf,qBAAgB,GAAG,KAAK,CAAC;QAC1B,YAAO,GAAG,KAAK,CAAC;QACf,oBAAe,GAAG,KAAK,CAAC;QAExB,WAAM,GAAG,OAAO,CAAC,CAAC,eAAe;QAOjC,kBAAa,GAAa,EAAE,CAA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C,EAAE;gCAA1C,CAAC;qBAyFT;oBAED,KAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC;iBAC9B;aACD;QACF,CAAC,EAAE,EAAE,CAAC,CAAC;IACR,CAAC;IAEM,2CAAa,GAApB,UAAqB,EAAa;QACjC,IAAI,IAAI,CAAC,oBAAoB,CAAC,cAAc,EAAE,EAAE;YAC/C,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;SAC/E;QACD,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;IAEM,oCAAM,GAAb;QACC,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,6CAAe,GAAtB;QACC,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;IACF,0BAAC;AAAD,CA/qBA,AA+qBC,IAAA","file":"server-app.js","sourcesContent":["import { createServer, Server } from 'http';\nimport * as express from 'express';\nimport * as bodyParser from 'body-parser';\nimport * as xmlParser from 'express-xml-bodyparser';\nimport * as WebSocket from 'ws';\nimport * as jwt from 'jsonwebtoken';\nimport { v4 as uuidv4 } from 'uuid';\n// import * as SegfaultHandler from 'segfault-handler';\nimport * as moment from 'moment';\n\nimport { dateReviver, getBinarySize, deepCopy } from './util/common';\n\nimport { objectIdHexString } from './managers/mongo.manager';\nimport { CronManager } from './managers/cron.manager';\nimport { MethodManager } from './managers/method.manager';\nimport { SubscriptionManager } from './managers/subscription.manager';\nimport { MonitorManager, MonitorManagerFunction } from './managers/monitor.manager';\n\nimport { ServerResponseModel } from './models/server-response.model';\n\nimport { MethodResponses } from './collections/method-response.collection';\nimport { Logs } from './collections/log.collection';\nimport { LogMethodLatencies } from './collections/log-method-latency.collection';\nimport { Users } from './collections/user.collection';\n\nimport { setupHomeRoutes } from './http/home';\nimport { setupAuthRoutes } from './http/auth';\nimport { setupHealthRoutes } from './http/health';\nimport { ResolveIOServer } from './index';\n\nexport default class ResolveIOMainServer {\n\tprivate _app: express.Application;\n\tprivate _server: Server;\n\tprivate _port: string | number;\n\tprivate _wss: WebSocket.Server;\n\tprivate _serverConfig;\n\tprivate _clientDir;\n\tprivate _offlineUpdates = [];\n\tprivate _msgQueue = [];\n\tprivate _msgQueueRunning = false;\n\tpublic sesMail = false;\n\tprivate standardProgram = false;\n\n\tprivate LOGGER = 'ERROR'; //ERROR / DEBUG\n\n\tprivate _monitorManager: MonitorManager;\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\tprivate _subscriptionManager: SubscriptionManager;\n\tprivate _methodManager: MethodManager;\n\tprivate _cronManager: CronManager;\n\tprivate _clientRoutes: string[] = [];\n\n\tprivate _serverStartTime: Date;\n\tprivate _lastErrorMsg: Date = null;\n\n\tprivate _debugMsgRecv = 0;\n\tprivate _debugMsgQueue = 0;\n\n\tconstructor(mainServer, serverConfig, clientRoutes, clientDir, sesMail, standardProgram) {\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._clientRoutes = clientRoutes;\n\t\tthis._clientDir = clientDir;\n\t\tthis.sesMail = sesMail;\n\t\tthis.standardProgram = standardProgram;\n\n\t\tthis._serverStartTime = new Date();\n\t\tthis._lastErrorMsg = null;\n\t\tthis._monitorManager = new MonitorManager(mainServer, serverConfig);\n\t\tthis._monitorManagerFunction = new MonitorManagerFunction();\n\n\t\tsetInterval(() => {\n\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Queue Length', this._msgQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Recv Hits', this._debugMsgRecv);\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Queue Hits', this._debugMsgQueue);\n\t\t\t}\n\n\t\t\tthis._debugMsgQueue = 0;\n\t\t\tthis._debugMsgRecv = 0;\n\t\t}, 60000);\n\n\t\tprocess.on('unhandledRejection', async (error, rej) => {\n\t\t\tconsole.error(new Date(), 'Unhandled Rejection at Promise', [error, rej]);\n\n\t\t\tlet diffTimeSec = moment().diff(this._serverStartTime, 'seconds');\n\n\t\t\tif (error && error['name'] === 'MongoError' && error['message'] === 'not master') {\n\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t}, 60000);\n\n\t\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t}\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\telse if (error && error['name'] === 'MongoError' && error['message'] === 'not master and slaveOk=false') {\n\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t}, 60000);\n\n\t\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t}\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\telse if (error) {\n\t\t\t\tif (error['name'] !== 'StatusError' && error['message'] !== '') {\n\t\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t\t}, 60000);\n\n\t\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tprocess.on('uncaughtException', async error => {\n\t\t\tconsole.error(error, 'Uncaught Exception thrown');\n\n\t\t\tlet diffTimeSec = moment().diff(this._serverStartTime, 'seconds');\n\n\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t}, 60000);\n\t\t\t\t\n\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Exception - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t}\n\t\t});\n\n\t\t//PM2 wants to reboot/restart\n\t\tprocess.on('SIGINT', err => {\n\t\t\tlet interval = setInterval(() => {\n\t\t\t\tif (\n\t\t\t\t\t!this._monitorManagerFunction.getActiveMonitorFunctions().length && \n\t\t\t\t\tthis._monitorManagerFunction.getLastCompletedMonitorFunction() && \n\t\t\t\t\tDate.now() >= this._monitorManagerFunction.getLastCompletedMonitorFunction().endTime.getTime() + 2500 &&\n\t\t\t\t\t!this._msgQueue.length &&\n\t\t\t\t\t!this._msgQueueRunning &&\n\t\t\t\t\t!this._offlineUpdates.length\n\t\t\t\t) {\n\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\tprocess.exit(err ? 1 : 0);\n\t\t\t\t}\n\t\t\t}, 100);\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Starting ResolveIO Server');\n\t\t}\n\n\t\t// Start express app\n\t\tthis._app = express();\n\n\t\t// Use body parser for http call (login)\n\t\tthis._app.use(bodyParser.json({limit: '50mb', reviver: dateReviver}));\n\t\tthis._app.use(bodyParser.urlencoded({limit: '50mb', extended: true, parameterLimit: 1000000 }));\n\t\tthis._app.use(xmlParser());\n\t\t\n\t\t// Set port\n\t\tthis._port = process.env.PORT || serverConfig['PORT'];\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup ports');\n\t\t}\n\n\t\t// Create http server and websock server\n\t\tthis.createServer();\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Create server');\n\t\t}\n\t\t\n\t\t// Set CORS\n\t\tthis._app.use(function (req, res, next) {\n\n\t\t\t// Website you wish to allow to connect\n\t\t\t// res.setHeader('Access-Control-Allow-Origin', serverConfig['ROOT_URL']);\n\t\t\tres.setHeader('Access-Control-Allow-Origin', '*');\n\t\t\n\t\t\t// Request methods you wish to allow\n\t\t\t// res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');\n\t\t\tres.setHeader('Access-Control-Allow-Methods', 'GET, POST');\n\t\t\n\t\t\t// Request headers you wish to allow\n\t\t\tres.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');\n\t\t\n\t\t\t// Set to true if you need the website to include cookies in the requests sent\n\t\t\t// to the API (e.g. in case you use sessions)\n\t\t\tres.setHeader('Access-Control-Allow-Credentials', 'false');\n\t\t\n\t\t\t// Pass to next layer of middleware\n\t\t\tnext();\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup cors');\n\t\t}\n\n\t\t// Set up http login route\n\t\tsetupAuthRoutes(this, this._app, serverConfig);\n\t\tsetupHealthRoutes(this._app, serverConfig);\n\n\t\tif (serverConfig['CLIENT_NAME'] === 'ResolveIO' || this.standardProgram) {\n\t\t\tsetupHomeRoutes(this, this._app, serverConfig);\n\t\t}\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup express routes');\n\t\t}\n\t}\n\n\tpublic getWS(id_ws: string) {\n\t\treturn Array.from(this._wss.clients).filter(a => a['id_socket'] === id_ws)[0];\n\t}\n\n\tpublic getWSList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_socket']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getWSUserList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_user']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getHTTPServer() {\n\t\treturn this._server;\n\t}\n\n\tpublic getCronManager() {\n\t\treturn this._cronManager;\n\t}\n\n\tpublic getMethodManager() {\n\t\treturn this._methodManager;\n\t}\n\n\tpublic getSubscriptionManager() {\n\t\treturn this._subscriptionManager;\n\t}\n\n\tpublic getMonitorManager() {\n\t\treturn this._monitorManager;\n\t}\n\n\tprivate createServer(): void {\n\t\t// Start express server\n\t\tthis._server = createServer(this._app);\n\t\tthis._server.keepAliveTimeout = 65000;\n\t\tthis._server.headersTimeout = 66000; // This should be bigger than `keepAliveTimeout + your server's expected response time`\n\n\t\t// Start websocket server\n\t\t// Verify client with token before opening socket\n\t\tthis._wss = new WebSocket.Server({ \n\t\t\tserver: this._server,\n\t\t\tverifyClient: async (info, cb) => {\n\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\tconsole.log('Verify Client', info, cb);\n\t\t\t\t}\n\n\t\t\t\tlet infoData = (<string>info.req.headers['sec-websocket-protocol']).split(/,/);\n\n\t\t\t\tif (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet token = infoData[0];\n\t\t\t\t\tif (!token) {\n\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tjwt.verify(token, this._serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tinfo.req['id_user'] = decoded['id_user'];\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tlet user = await Users.findById(decoded['id_user']);\n\t\t\t\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\t\t\t\tinfo.req['user'] = user.fullname;\n\t\t\t\t\t\t\t\t\t\tinfo.req['user_readonly'] = user.readonly || false;\n\t\t\t\t\t\t\t\t\t\tinfo.req['doc_user'] = user;\n\t\t\t\t\t\t\t\t\t\tcb(true);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Start MongoDB Connection\n\t\tthis.setUpMongo();\n\t}\n\n\tprivate setUpMongo() {\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Start Managers');\n\t\t}\n\n\t\t// Start Managers\n\t\tthis._subscriptionManager = new SubscriptionManager(this, this._wss, this._serverConfig, this._monitorManagerFunction);\n\t\tthis._methodManager = new MethodManager(this, this._serverConfig, this._clientDir, this._monitorManagerFunction);\n\t\tthis._cronManager = new CronManager(this);\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('End Managers');\n\t\t}\n\n\t\tthis.listen();\n\t}\n\n\t// Listen to port for websocket\n\tprivate listen(): void {\n\t\tthis._server.listen(this._port, () => {\n\t\t\tconsole.log('Running server on port %s', this._port);\n\t\t});\n\n\t\t// On websocket connection (already verified)\n\t\tthis._wss.on('connection', (ws, req) => {\n\n\t\t\t// Get user from token\n\t\t\tws['id_user'] = req['id_user'];\n\t\t\tws['user'] = req['user'];\n\t\t\tws['user_readonly'] = req['user_readonly'];\n\t\t\tws['doc_user'] = req['doc_user'];\n\n\t\t\tif (ws['user'] !== 'Admin' && this._serverConfig['CLIENT_NAME'] !== 'ResolveIO') {\n\t\t\t\tthis.getMethodManager().callMethodInternal.call(this.getMethodManager(), 'supportCreateBillingUser', {\n\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tclient: ResolveIOServer.getClientName()\n\t\t\t\t});\n\t\t\t}\n\t\t\t\n\t\t\tlet idSocket = '';\n\n\t\t\twhile (!idSocket || Array.from(this._wss.clients).some(a => a['id_socket'] === idSocket)) {\n\t\t\t\tidSocket = uuidv4();\n\t\t\t}\n\n\t\t\tws['id_socket'] = idSocket;\n\t\t\tws['retryCnt'] = 0;\n\n\t\t\tthis._subscriptionManager.createLoggedInUser(idSocket).then(() => {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\tws.ping(() => {});\n\t\t\t\t}, 5000);\n\t\t\t});\n\n\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\tconsole.log('Connection from: ' + req['user']);\n\t\t\t}\n\t\t\t\n\t\t\t// Use for keeping connection alive (ping/pong)\n\t\t\tws['isAlive'] = true;\n\t\t\tws.on('pong', () => {\n\t\t\t\tws['isAlive'] = true;\n\t\t\t\tws['pongTime'] = new Date();\n\t\t\t\tws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();\n\t\t\t\tthis._subscriptionManager.loggedInLatency(ws);\n\t\t\t});\n\n\t\t\t// On data received (message)\n\t\t\tws.on('message', async (message: string) => {\n\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\tconsole.log('Message from: ' + ws['user'], message);\n\t\t\t\t}\n\n\t\t\t\tthis._debugMsgRecv += 1;\n\n\t\t\t\tlet parseErrorFound = false;\n\n\t\t\t\tlet socketData = [];\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tsocketData = JSON.parse(message, dateReviver);\n\t\t\t\t}\n\t\t\t\tcatch(e) {\n\t\t\t\t\tconsole.log('Error - JSON.parse', message);\n\t\t\t\t\t\n\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - JSON Parse Error - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([message, e]));\n\n\t\t\t\t\tparseErrorFound = true;\n\t\t\t\t}\n\n\t\t\t\tif (!parseErrorFound) {\n\t\t\t\t\tif (socketData[0] === 'ping') {\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send('pong', (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Pong');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageRoute = socketData[0];\n\n\t\t\t\t\tif (this._clientRoutes.some(a => messageRoute.includes(a)) && !ws['doc_user'].roles.groups.some(a => a.views.some(b => messageRoute.includes(b))) && !ws['doc_user'].roles.super_admin) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageDate = socketData[1];\n\t\t\t\t\tlet messageId = socketData[2]\n\t\t\t\t\tlet type = socketData[3]\n\n\t\t\t\t\tif (type === 'subscription') {\n\t\t\t\t\t\tlet subType = socketData[4];\n\t\t\t\t\t\tlet pub = socketData[5];\n\t\t\n\t\t\t\t\t\t// Subscribe\n\t\t\t\t\t\tif (subType === 'sub') {\n\t\t\t\t\t\t\tthis._subscriptionManager.subscribe(messageRoute, messageDate, ws, messageId, pub, socketData.slice(6));\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Unsubscribe\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._subscriptionManager.unsubscribe(messageRoute, messageDate, ws, messageId, pub, socketData.slice(6));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if (type === 'offline') {\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Offline Ack Main');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis._offlineUpdates = socketData[4];\n\n\t\t\t\t\t\tfor (let i = 0; i < this._offlineUpdates.length; i++) {\n\t\t\t\t\t\t\tlet update = this._offlineUpdates[i];\n\t\t\t\t\t\t\tlet data = update.data;\n\n\t\t\t\t\t\t\tlet serverResMethod: ServerResponseModel = {\n\t\t\t\t\t\t\t\tmessageId: update.data[2],\n\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t\t};\n\t\t\t\n\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(serverResMethod), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Offline Ack Each');\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlet updateRoute = data.shift();\n\t\t\t\t\t\t\tlet updateDate = data.shift();\n\t\t\t\t\t\t\tlet updateMessageId = data.shift();\n\t\t\t\t\t\t\tlet updateType = data.shift();\n\t\t\t\t\t\t\tlet method = data.shift();\n\t\t\t\t\t\t\tlet methodLatencyId = objectIdHexString();\n\n\t\t\t\t\t\t\tLogMethodLatencies.create({\n\t\t\t\t\t\t\t\t_id: methodLatencyId,\n\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t\t});\n\t\t\t\n\t\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers') {\n\t\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\t\troute: messageRoute\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tawait this._methodManager.callMethodInternal.call(Object.assign({}, this._methodManager, {id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket']}), method, ...data);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Offline Error', JSON.stringify(err, null, 2));\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (method === 'updateDocumentOffline' || method === 'updateDocumentPropsOffline') {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(data[0]);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tconsole.log('Offline - Could not find method: ' + method);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis._offlineUpdates = [];\n\t\t\t\t\t}\n\t\t\t\t\telse { //methods\n\t\t\t\t\t\tthis._msgQueue.splice(0, 0, {\n\t\t\t\t\t\t\tws: ws,\n\t\t\t\t\t\t\tdata: socketData\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('close', () => {\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\tconsole.log(new Date(), 'Server App', 'WS Close');\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('error', error => {\n\t\t\t\tconsole.log(new Date(), ws['user'], ws['id_socket'], 'WS Error');\n\t\t\t\t\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t});\n\t\t});\n\n\t\t// Keep alive timer to ping/pong\n\t\tsetInterval(() => {\n\t\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\t\tif (ws['pingTime'] && Date.now() - ws['pingTime'].getTime() >= 20000) {\n\t\t\t\t\tif (ws['isAlive'] === false) {\n\t\t\t\t\t\tws['retryCnt']++;\n\n\t\t\t\t\t\tif (ws['retryCnt'] >= 3) {\n\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\tconsole.log(new Date(), ws['user'], ws['id_socket'], 'Ping Retry', ws['retryCnt'], ws['pingTime'], ws['pongTime']);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tws['retryCnt'] = 0;\n\t\t\t\t\t\tws['isAlive'] = false;\n\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}, 20000);\n\n\t\tsetInterval(() => {\n\t\t\tif (!this._msgQueueRunning) {\t\t\t\t\n\t\t\t\tif (this._msgQueue.length) {\n\t\t\t\t\tthis._msgQueueRunning = true;\n\t\t\t\t\tfor (let i = this._msgQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tthis._debugMsgQueue += 1;\n\n\t\t\t\t\t\tlet msg = this._msgQueue.pop();\n\t\t\t\t\t\tlet data = msg.data;\n\t\t\t\t\t\tlet ws = msg.ws;\n\t\t\t\n\t\t\t\t\t\tlet messageRoute: string = data.shift();\n\t\t\t\t\t\tlet messageDate: Date = data.shift();\n\t\t\t\t\t\tlet messageId: number = data.shift();\n\t\t\t\t\t\tlet type: string = data.shift();\n\t\t\t\n\t\t\t\t\t\t// Method call\n\t\t\t\t\t\tif (type === 'method') {\n\t\t\t\t\t\t\tlet method = data.shift();\n\n\t\t\t\t\t\t\tif (ws['user_readonly']) {\n\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlet methodLatencyId = objectIdHexString();\n\n\t\t\t\t\t\t\tLogMethodLatencies.create({\n\t\t\t\t\t\t\t\t_id: methodLatencyId,\n\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t\t});\n\t\t\t\n\t\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers') {\n\t\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\t\troute: messageRoute\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\n\t\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t\t};\n\t\t\t\n\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\n\t\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\t\tthis._methodManager.callMethod(methodLatencyId, ws, messageDate, messageId, method, ...data);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tconsole.log('Could not find method: ' + method);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if (type === 'methodResponse') {\n\t\t\t\t\t\t\tlet method = data.shift();\n\t\t\t\n\t\t\t\t\t\t\tMethodResponses.findOne({$and: [\n\t\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t\t]}).then(res => {\n\t\t\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\t\tws.send(JSON.stringify(res.response), (error) => {\n\t\t\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}, err => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tthis._msgQueueRunning = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}, 50);\n\t}\n\n\tpublic unsubscribeWS(ws: WebSocket) {\n\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\tconsole.log(new Date(), 'Server App', 'Unsub WS', ws['user'], ws['id_socket']);\n\t\t}\n\t\tthis._subscriptionManager.unsubscribeAll(ws);\n\t}\n\n\tpublic getApp() {\n\t\treturn this._app;\n\t}\n\n\tpublic getServerConfig() {\n\t\treturn this._serverConfig;\n\t}\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/server-app.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6BAA4C;AAC5C,iCAAmC;AACnC,wCAA0C;AAC1C,kDAAoD;AACpD,8BAAgC;AAChC,kCAAoC;AACpC,6BAAoC;AACpC,uDAAuD;AACvD,+BAAiC;AAEjC,wCAAqE;AAErE,0DAA6D;AAC7D,wDAAsD;AACtD,4DAA0D;AAC1D,wEAAsE;AACtE,8DAAoF;AAIpF,uFAA2E;AAC3E,+DAAoD;AACpD,6FAAiF;AACjF,iEAAsD;AAEtD,oCAA8C;AAC9C,oCAA8C;AAC9C,wCAAkD;AAClD,iCAA0C;AAE1C;IA6BC,6BAAY,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe;QAAvF,iBAkLC;QAxMO,oBAAe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C9B;aACD;QACF,CAAC,EAAE,EAAE,CAAC,CAAC;IACR,CAAC;IAEM,2CAAa,GAApB,UAAqB,EAAa;QACjC,IAAI,IAAI,CAAC,oBAAoB,CAAC,cAAc,EAAE,EAAE;YAC/C,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;SAC/E;QACD,IAAI,CAAC,oBAAoB,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAC9C,CAAC;IAEM,oCAAM,GAAb;QACC,OAAO,IAAI,CAAC,IAAI,CAAC;IAClB,CAAC;IAEM,6CAAe,GAAtB;QACC,OAAO,IAAI,CAAC,aAAa,CAAC;IAC3B,CAAC;IACF,0BAAC;AAAD,CAlsBA,AAksBC,IAAA","file":"server-app.js","sourcesContent":["import { createServer, Server } from 'http';\nimport * as express from 'express';\nimport * as bodyParser from 'body-parser';\nimport * as xmlParser from 'express-xml-bodyparser';\nimport * as WebSocket from 'ws';\nimport * as jwt from 'jsonwebtoken';\nimport { v4 as uuidv4 } from 'uuid';\n// import * as SegfaultHandler from 'segfault-handler';\nimport * as moment from 'moment';\n\nimport { dateReviver, getBinarySize, deepCopy } from './util/common';\n\nimport { objectIdHexString } from './managers/mongo.manager';\nimport { CronManager } from './managers/cron.manager';\nimport { MethodManager } from './managers/method.manager';\nimport { SubscriptionManager } from './managers/subscription.manager';\nimport { MonitorManager, MonitorManagerFunction } from './managers/monitor.manager';\n\nimport { ServerResponseModel } from './models/server-response.model';\n\nimport { MethodResponses } from './collections/method-response.collection';\nimport { Logs } from './collections/log.collection';\nimport { LogMethodLatencies } from './collections/log-method-latency.collection';\nimport { Users } from './collections/user.collection';\n\nimport { setupHomeRoutes } from './http/home';\nimport { setupAuthRoutes } from './http/auth';\nimport { setupHealthRoutes } from './http/health';\nimport { ResolveIOServer } from './index';\n\nexport default class ResolveIOMainServer {\n\tprivate _app: express.Application;\n\tprivate _server: Server;\n\tprivate _port: string | number;\n\tprivate _wss: WebSocket.Server;\n\tprivate _serverConfig;\n\tprivate _clientDir;\n\tprivate _offlineUpdates = [];\n\tprivate _msgQueue = [];\n\tprivate _msgQueueRunning = false;\n\tpublic sesMail = false;\n\tprivate standardProgram = false;\n\tprivate _rebootFlag = false;\n\n\tprivate LOGGER = 'ERROR'; //ERROR / DEBUG\n\n\tprivate _monitorManager: MonitorManager;\n\tprivate _monitorManagerFunction: MonitorManagerFunction;\n\tprivate _subscriptionManager: SubscriptionManager;\n\tprivate _methodManager: MethodManager;\n\tprivate _cronManager: CronManager;\n\tprivate _clientRoutes: string[] = [];\n\n\tprivate _serverStartTime: Date;\n\tprivate _lastErrorMsg: Date = null;\n\n\tprivate _debugMsgRecv = 0;\n\tprivate _debugMsgQueue = 0;\n\n\tconstructor(mainServer, serverConfig, clientRoutes, clientDir, sesMail, standardProgram) {\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._clientRoutes = clientRoutes;\n\t\tthis._clientDir = clientDir;\n\t\tthis.sesMail = sesMail;\n\t\tthis.standardProgram = standardProgram;\n\n\t\tthis._serverStartTime = new Date();\n\t\tthis._lastErrorMsg = null;\n\t\tthis._monitorManager = new MonitorManager(mainServer, serverConfig);\n\t\tthis._monitorManagerFunction = new MonitorManagerFunction();\n\n\t\tsetInterval(() => {\n\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Queue Length', this._msgQueue.length);\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Recv Hits', this._debugMsgRecv);\n\t\t\t\tconsole.log(new Date(), 'Server App', 'Msg Queue Hits', this._debugMsgQueue);\n\t\t\t}\n\n\t\t\tthis._debugMsgQueue = 0;\n\t\t\tthis._debugMsgRecv = 0;\n\t\t}, 60000);\n\n\t\tprocess.on('unhandledRejection', async (error, rej) => {\n\t\t\tconsole.error(new Date(), 'Unhandled Rejection at Promise', [error, rej]);\n\n\t\t\tlet diffTimeSec = moment().diff(this._serverStartTime, 'seconds');\n\n\t\t\tif (error && error['name'] === 'MongoError' && error['message'] === 'not master') {\n\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t}, 60000);\n\n\t\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t}\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\telse if (error && error['name'] === 'MongoError' && error['message'] === 'not master and slaveOk=false') {\n\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t}, 60000);\n\n\t\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - Quitting NodeJS - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t}\n\n\t\t\t\tprocess.exit(1);\n\t\t\t}\n\t\t\telse if (error) {\n\t\t\t\tif (error['name'] !== 'StatusError' && error['message'] !== '') {\n\t\t\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t\t\t}, 60000);\n\n\t\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Rejection - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tprocess.on('uncaughtException', async error => {\n\t\t\tconsole.error(error, 'Uncaught Exception thrown');\n\n\t\t\tlet diffTimeSec = moment().diff(this._serverStartTime, 'seconds');\n\n\t\t\tif (diffTimeSec > 60 && !this._lastErrorMsg) {\n\t\t\t\tthis._lastErrorMsg = new Date();\n\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tthis._lastErrorMsg = null;\n\t\t\t\t}, 60000);\n\t\t\t\t\n\t\t\t\tawait this._methodManager.sendEmail('dev@resolveio.com', 'SERVER - Unhandled Exception - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([error['name'], error['message'], error['stack']], null, 2));\n\t\t\t}\n\t\t});\n\n\t\t//PM2 wants to reboot/restart\n\t\tprocess.on('SIGINT', err => {\n\t\t\tthis._rebootFlag = true;\n\t\t\t\n\t\t\tlet interval = setInterval(() => {\n\t\t\t\tif (\n\t\t\t\t\t!this._monitorManagerFunction.getActiveMonitorFunctions().length && \n\t\t\t\t\t(!this._monitorManagerFunction.getLastCompletedMonitorFunction() ||\n\t\t\t\t\tthis._monitorManagerFunction.getLastCompletedMonitorFunction() && \n\t\t\t\t\tDate.now() >= this._monitorManagerFunction.getLastCompletedMonitorFunction().endTime.getTime() + 2500) &&\n\t\t\t\t\t!this._msgQueue.length &&\n\t\t\t\t\t!this._msgQueueRunning &&\n\t\t\t\t\t!this._offlineUpdates.length\n\t\t\t\t) {\n\t\t\t\t\tclearInterval(interval);\n\t\t\t\t\tprocess.exit(err ? 1 : 0);\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthis.getWSList().forEach(ws => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t!this._msgQueue.some(a => a.ws['id_socket'] === ws['id_socket']) &&\n\t\t\t\t\t\t\t!this._offlineUpdates.some(a => a['id_socket'] === ws['id_socket'])\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}, 100);\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Starting ResolveIO Server');\n\t\t}\n\n\t\t// Start express app\n\t\tthis._app = express();\n\n\t\t// Use body parser for http call (login)\n\t\tthis._app.use(bodyParser.json({limit: '50mb', reviver: dateReviver}));\n\t\tthis._app.use(bodyParser.urlencoded({limit: '50mb', extended: true, parameterLimit: 1000000 }));\n\t\tthis._app.use(xmlParser());\n\t\t\n\t\t// Set port\n\t\tthis._port = process.env.PORT || serverConfig['PORT'];\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup ports');\n\t\t}\n\n\t\t// Create http server and websock server\n\t\tthis.createServer();\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Create server');\n\t\t}\n\t\t\n\t\t// Set CORS\n\t\tthis._app.use(function (req, res, next) {\n\n\t\t\t// Website you wish to allow to connect\n\t\t\t// res.setHeader('Access-Control-Allow-Origin', serverConfig['ROOT_URL']);\n\t\t\tres.setHeader('Access-Control-Allow-Origin', '*');\n\t\t\n\t\t\t// Request methods you wish to allow\n\t\t\t// res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');\n\t\t\tres.setHeader('Access-Control-Allow-Methods', 'GET, POST');\n\t\t\n\t\t\t// Request headers you wish to allow\n\t\t\tres.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');\n\t\t\n\t\t\t// Set to true if you need the website to include cookies in the requests sent\n\t\t\t// to the API (e.g. in case you use sessions)\n\t\t\tres.setHeader('Access-Control-Allow-Credentials', 'false');\n\t\t\n\t\t\t// Pass to next layer of middleware\n\t\t\tnext();\n\t\t});\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup cors');\n\t\t}\n\n\t\t// Set up http login route\n\t\tsetupAuthRoutes(this, this._app, serverConfig);\n\t\tsetupHealthRoutes(this._app, serverConfig);\n\n\t\tif (serverConfig['CLIENT_NAME'] === 'ResolveIO' || this.standardProgram) {\n\t\t\tsetupHomeRoutes(this, this._app, serverConfig);\n\t\t}\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Setup express routes');\n\t\t}\n\t}\n\n\tpublic getWS(id_ws: string) {\n\t\treturn Array.from(this._wss.clients).filter(a => a['id_socket'] === id_ws)[0];\n\t}\n\n\tpublic getWSList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_socket']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getWSUserList() {\n\t\tlet res = [];\n\n\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\tres.push(ws['id_user']);\n\t\t});\n\n\t\treturn res;\n\t}\n\n\tpublic getHTTPServer() {\n\t\treturn this._server;\n\t}\n\n\tpublic getCronManager() {\n\t\treturn this._cronManager;\n\t}\n\n\tpublic getMethodManager() {\n\t\treturn this._methodManager;\n\t}\n\n\tpublic getSubscriptionManager() {\n\t\treturn this._subscriptionManager;\n\t}\n\n\tpublic getMonitorManager() {\n\t\treturn this._monitorManager;\n\t}\n\n\tprivate createServer(): void {\n\t\t// Start express server\n\t\tthis._server = createServer(this._app);\n\t\tthis._server.keepAliveTimeout = 65000;\n\t\tthis._server.headersTimeout = 66000; // This should be bigger than `keepAliveTimeout + your server's expected response time`\n\n\t\t// Start websocket server\n\t\t// Verify client with token before opening socket\n\t\tthis._wss = new WebSocket.Server({ \n\t\t\tserver: this._server,\n\t\t\tverifyClient: async (info, cb) => {\n\t\t\t\tif (this._rebootFlag) {\n\t\t\t\t\tcb(false, 409, 'Unable To Process');\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\t\tconsole.log('Verify Client', info, cb);\n\t\t\t\t\t}\n\n\t\t\t\t\tlet infoData = (<string>info.req.headers['sec-websocket-protocol']).split(/,/);\n\n\t\t\t\t\tif (info.origin !== this._serverConfig['ROOT_URL'] && info.origin !== this._serverConfig['SEC_ROOT_URL'] && info.origin !== this._serverConfig['RESOLVEIO_URL'] && info.origin !== this._serverConfig['RESOLVEIO_SECONDARY_URL']) {\n\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tlet token = infoData[0];\n\t\t\t\t\t\tif (!token) {\n\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tjwt.verify(token, this._serverConfig['JWT_SECRET'], async (err, decoded) => {\n\t\t\t\t\t\t\t\tif (err) {\n\t\t\t\t\t\t\t\t\tcb(false, 401, 'Unauthorized');\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\tinfo.req['id_user'] = decoded['id_user'];\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tlet user = await Users.findById(decoded['id_user']);\n\t\t\t\t\t\t\t\t\t\tif (user) {\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user'] = user.fullname;\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['user_readonly'] = user.readonly || false;\n\t\t\t\t\t\t\t\t\t\t\tinfo.req['doc_user'] = user;\n\t\t\t\t\t\t\t\t\t\t\tcb(true);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\t\tcb(false);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// Start MongoDB Connection\n\t\tthis.setUpMongo();\n\t}\n\n\tprivate setUpMongo() {\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('Start Managers');\n\t\t}\n\n\t\t// Start Managers\n\t\tthis._subscriptionManager = new SubscriptionManager(this, this._wss, this._serverConfig, this._monitorManagerFunction);\n\t\tthis._methodManager = new MethodManager(this, this._serverConfig, this._clientDir, this._monitorManagerFunction);\n\t\tthis._cronManager = new CronManager(this);\n\n\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\tconsole.log('End Managers');\n\t\t}\n\n\t\tthis.listen();\n\t}\n\n\t// Listen to port for websocket\n\tprivate listen(): void {\n\t\tthis._server.listen(this._port, () => {\n\t\t\tconsole.log('Running server on port %s', this._port);\n\t\t});\n\n\t\t// On websocket connection (already verified)\n\t\tthis._wss.on('connection', (ws, req) => {\n\n\t\t\t// Get user from token\n\t\t\tws['id_user'] = req['id_user'];\n\t\t\tws['user'] = req['user'];\n\t\t\tws['user_readonly'] = req['user_readonly'];\n\t\t\tws['doc_user'] = req['doc_user'];\n\n\t\t\tif (ws['user'] !== 'Admin' && this._serverConfig['CLIENT_NAME'] !== 'ResolveIO') {\n\t\t\t\tthis.getMethodManager().callMethodInternal.call(this.getMethodManager(), 'supportCreateBillingUser', {\n\t\t\t\t\tid_user: ws['id_user'],\n\t\t\t\t\tuser: ws['user'],\n\t\t\t\t\tdate: new Date(),\n\t\t\t\t\tclient: ResolveIOServer.getClientName()\n\t\t\t\t});\n\t\t\t}\n\t\t\t\n\t\t\tlet idSocket = '';\n\n\t\t\twhile (!idSocket || Array.from(this._wss.clients).some(a => a['id_socket'] === idSocket)) {\n\t\t\t\tidSocket = uuidv4();\n\t\t\t}\n\n\t\t\tws['id_socket'] = idSocket;\n\t\t\tws['retryCnt'] = 0;\n\n\t\t\tthis._subscriptionManager.createLoggedInUser(idSocket).then(() => {\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\tws.ping(() => {});\n\t\t\t\t}, 5000);\n\t\t\t});\n\n\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\tconsole.log('Connection from: ' + req['user']);\n\t\t\t}\n\t\t\t\n\t\t\t// Use for keeping connection alive (ping/pong)\n\t\t\tws['isAlive'] = true;\n\t\t\tws.on('pong', () => {\n\t\t\t\tws['isAlive'] = true;\n\t\t\t\tws['pongTime'] = new Date();\n\t\t\t\tws['latency'] = moment.duration(moment(ws['pongTime']).diff(ws['pingTime'])).asMilliseconds();\n\t\t\t\tthis._subscriptionManager.loggedInLatency(ws);\n\t\t\t});\n\n\t\t\t// On data received (message)\n\t\t\tws.on('message', async (message: string) => {\n\t\t\t\tif (this.LOGGER === 'DEBUG') {\n\t\t\t\t\tconsole.log('Message from: ' + ws['user'], message);\n\t\t\t\t}\n\n\t\t\t\tthis._debugMsgRecv += 1;\n\n\t\t\t\tlet parseErrorFound = false;\n\n\t\t\t\tlet socketData = [];\n\t\t\t\t\n\t\t\t\ttry {\n\t\t\t\t\tsocketData = JSON.parse(message, dateReviver);\n\t\t\t\t}\n\t\t\t\tcatch(e) {\n\t\t\t\t\tconsole.log('Error - JSON.parse', message);\n\t\t\t\t\t\n\t\t\t\t\tthis._methodManager.sendEmail('dev@resolveio.com', 'SERVER - JSON Parse Error - ' + this._serverConfig['CLIENT_NAME'], JSON.stringify([message, e]));\n\n\t\t\t\t\tparseErrorFound = true;\n\t\t\t\t}\n\n\t\t\t\tif (!parseErrorFound) {\n\t\t\t\t\tif (socketData[0] === 'ping') {\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send('pong', (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Pong');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageRoute = socketData[0];\n\n\t\t\t\t\tif (this._clientRoutes.some(a => messageRoute.includes(a)) && !ws['doc_user'].roles.groups.some(a => a.views.some(b => messageRoute.includes(b))) && !ws['doc_user'].roles.super_admin) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet messageDate = socketData[1];\n\t\t\t\t\tlet messageId = socketData[2]\n\t\t\t\t\tlet type = socketData[3]\n\n\t\t\t\t\tif (type === 'subscription') {\n\t\t\t\t\t\tlet subType = socketData[4];\n\t\t\t\t\t\tlet pub = socketData[5];\n\t\t\n\t\t\t\t\t\t// Subscribe\n\t\t\t\t\t\tif (subType === 'sub') {\n\t\t\t\t\t\t\tthis._subscriptionManager.subscribe(messageRoute, messageDate, ws, messageId, pub, socketData.slice(6));\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Unsubscribe\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tthis._subscriptionManager.unsubscribe(messageRoute, messageDate, ws, messageId, pub, socketData.slice(6));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if (type === 'offline') {\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Offline Ack Main');\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis._offlineUpdates.push(ws);\n\t\t\t\t\t\tlet offlineUpdates = socketData[4];\n\n\t\t\t\t\t\tfor (let i = 0; i < offlineUpdates.length; i++) {\n\t\t\t\t\t\t\tlet update = offlineUpdates[i];\n\t\t\t\t\t\t\tlet data = update.data;\n\n\t\t\t\t\t\t\tlet serverResMethod: ServerResponseModel = {\n\t\t\t\t\t\t\t\tmessageId: update.data[2],\n\t\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t\t};\n\t\t\t\n\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(serverResMethod), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Server App', 'Error WS Offline Ack Each');\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tlet updateRoute = data.shift();\n\t\t\t\t\t\t\tlet updateDate = data.shift();\n\t\t\t\t\t\t\tlet updateMessageId = data.shift();\n\t\t\t\t\t\t\tlet updateType = data.shift();\n\t\t\t\t\t\t\tlet method = data.shift();\n\t\t\t\t\t\t\tlet methodLatencyId = objectIdHexString();\n\n\t\t\t\t\t\t\tLogMethodLatencies.create({\n\t\t\t\t\t\t\t\t_id: methodLatencyId,\n\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t\t});\n\t\t\t\n\t\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers') {\n\t\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\t\troute: messageRoute\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tawait this._methodManager.callMethodInternal.call(Object.assign({}, this._methodManager, {id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket']}), method, ...data);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcatch (err) {\n\t\t\t\t\t\t\t\t\tconsole.log(new Date(), 'Offline Error', JSON.stringify(err, null, 2));\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (method === 'updateDocumentOffline' || method === 'updateDocumentPropsOffline') {\n\t\t\t\t\t\t\t\t\tResolveIOServer.getMongoManager().invalidateQueryCache(data[0]);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tconsole.log('Offline - Could not find method: ' + method);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tthis._offlineUpdates.splice(this._offlineUpdates.map(a => a['id_socket']).indexOf(ws['id_socket']), 1);\n\t\t\t\t\t}\n\t\t\t\t\telse { //methods\n\t\t\t\t\t\tthis._msgQueue.splice(0, 0, {\n\t\t\t\t\t\t\tws: ws,\n\t\t\t\t\t\t\tdata: socketData\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('close', () => {\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\t\t\tconsole.log(new Date(), 'Server App', 'WS Close');\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tws.on('error', error => {\n\t\t\t\tconsole.log(new Date(), ws['user'], ws['id_socket'], 'WS Error');\n\t\t\t\t\n\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t});\n\t\t});\n\n\t\t// Keep alive timer to ping/pong\n\t\tsetInterval(() => {\n\t\t\tthis._wss.clients.forEach((ws: WebSocket) => {\n\t\t\t\tif (ws['pingTime'] && Date.now() - ws['pingTime'].getTime() >= 20000) {\n\t\t\t\t\tif (ws['isAlive'] === false) {\n\t\t\t\t\t\tws['retryCnt']++;\n\n\t\t\t\t\t\tif (ws['retryCnt'] >= 3) {\n\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\tconsole.log(new Date(), ws['user'], ws['id_socket'], 'Ping Retry', ws['retryCnt'], ws['pingTime'], ws['pongTime']);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tws['retryCnt'] = 0;\n\t\t\t\t\t\tws['isAlive'] = false;\n\t\t\t\t\t\tws['pingTime'] = new Date();\n\t\t\t\t\t\tws.ping(() => {});\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\t\t}, 20000);\n\n\t\tsetInterval(() => {\n\t\t\tif (!this._msgQueueRunning) {\t\t\t\t\n\t\t\t\tif (this._msgQueue.length) {\n\t\t\t\t\tthis._msgQueueRunning = true;\n\t\t\t\t\tthis._debugMsgQueue += 1;\n\n\t\t\t\t\tlet msg = this._msgQueue[this._msgQueue.length - 1];\n\t\t\t\t\tlet data = msg.data;\n\t\t\t\t\tlet ws = msg.ws;\n\t\t\n\t\t\t\t\tlet messageRoute: string = data.shift();\n\t\t\t\t\tlet messageDate: Date = data.shift();\n\t\t\t\t\tlet messageId: number = data.shift();\n\t\t\t\t\tlet type: string = data.shift();\n\t\t\n\t\t\t\t\t// Method call\n\t\t\t\t\tif (type === 'method') {\n\t\t\t\t\t\tlet method = data.shift();\n\n\t\t\t\t\t\tif (ws['user_readonly']) {\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tlet methodLatencyId = objectIdHexString();\n\n\t\t\t\t\t\tLogMethodLatencies.create({\n\t\t\t\t\t\t\t_id: methodLatencyId,\n\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\tdate_start: new Date(),\n\t\t\t\t\t\t\tdate_end: null,\n\t\t\t\t\t\t\tlatency_ms: 0,\n\t\t\t\t\t\t\tmethod: method\n\t\t\t\t\t\t});\n\t\t\n\t\t\t\t\t\tif (method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers') {\n\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\ttype: 'client-request',\n\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify(data)) < 200000 ? JSON.stringify(data, null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\tmethod: method,\n\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\t\troute: messageRoute\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tlet serverRes: ServerResponseModel = {\n\t\t\t\t\t\t\tmessageId: messageId,\n\t\t\t\t\t\t\thasError: false,\n\t\t\t\t\t\t\tdata: 'ACK'\n\t\t\t\t\t\t};\n\t\t\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tws.send(JSON.stringify(serverRes), (error) => {\n\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\n\t\t\t\t\t\tif (this._methodManager._methods[method]) {\n\t\t\t\t\t\t\tthis._methodManager.callMethod(methodLatencyId, ws, messageDate, messageId, method, ...data);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tconsole.log('Could not find method: ' + method);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse if (type === 'methodResponse') {\n\t\t\t\t\t\tlet method = data.shift();\n\t\t\n\t\t\t\t\t\tMethodResponses.findOne({$and: [\n\t\t\t\t\t\t\t{id_user: ws['id_user']}, \n\t\t\t\t\t\t\t{message_id: messageId},\n\t\t\t\t\t\t\t{method: method},\n\t\t\t\t\t\t\t{date: messageDate}\n\t\t\t\t\t\t]}).then(res => {\n\t\t\t\t\t\t\tif (res) {\n\t\t\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\t\t\tws.send(JSON.stringify(res.response), (error) => {\n\t\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\t\tthis.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}, err => {});\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\t\tthis._msgQueue.splice(this._msgQueue.length - 1, 1);\n\t\t\t\t\tthis._msgQueueRunning = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}, 50);\n\t}\n\n\tpublic unsubscribeWS(ws: WebSocket) {\n\t\tif (this._subscriptionManager.getEnableDebug()) {\n\t\t\tconsole.log(new Date(), 'Server App', 'Unsub WS', ws['user'], ws['id_socket']);\n\t\t}\n\t\tthis._subscriptionManager.unsubscribeAll(ws);\n\t}\n\n\tpublic getApp() {\n\t\treturn this._app;\n\t}\n\n\tpublic getServerConfig() {\n\t\treturn this._serverConfig;\n\t}\n}"]}
|