@futdevpro/nts-dynamo 1.9.31 → 1.9.33
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/build/_models/control-models/endpoint-params.control-model.js +1 -1
- package/build/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/build/_models/interfaces/global-service-settings.interface.d.ts +2 -1
- package/build/_models/interfaces/global-service-settings.interface.d.ts.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.d.ts +1 -0
- package/build/_modules/socket/_services/app-extended.server.d.ts.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.js +125 -96
- package/build/_modules/socket/_services/app-extended.server.js.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.spec.js +2 -0
- package/build/_modules/socket/_services/app-extended.server.spec.js.map +1 -1
- package/build/_services/core/email.service.d.ts +3 -1
- package/build/_services/core/email.service.d.ts.map +1 -1
- package/build/_services/core/email.service.js +48 -27
- package/build/_services/core/email.service.js.map +1 -1
- package/build/_services/core/global.service.d.ts +4 -0
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +67 -14
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +352 -291
- package/build/_services/server/app.server.js.map +1 -1
- package/package.json +2 -2
- package/src/_models/control-models/endpoint-params.control-model.ts +1 -1
- package/src/_models/interfaces/global-service-settings.interface.ts +3 -1
- package/src/_modules/socket/_services/app-extended.server.spec.ts +5 -0
- package/src/_modules/socket/_services/app-extended.server.ts +165 -124
- package/src/_services/core/email.service.ts +71 -40
- package/src/_services/core/global.service.ts +82 -24
- package/src/_services/server/app.server.ts +479 -402
|
@@ -228,7 +228,7 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
|
|
|
228
228
|
constructor(extended) {
|
|
229
229
|
super();
|
|
230
230
|
process.on('unhandledRejection', (reason, p_passWhatIsThis) => {
|
|
231
|
-
fsm_dynamo_1.DyFM_Log.H_error('Unhandled Rejection: ', p_passWhatIsThis
|
|
231
|
+
fsm_dynamo_1.DyFM_Log.H_error('Unhandled Rejection: ', p_passWhatIsThis?.toString()?.split('at')?.[0], '\n Rejection reason:', reason?.toString()?.split('at')?.[0], '\n\n Stack:', reason?.stack?.replaceAll?.('\n at', '\n at'));
|
|
232
232
|
try {
|
|
233
233
|
global_service_1.DyNTS_GlobalService.globalErrorHandler?.(new fsm_dynamo_1.DyFM_Error({
|
|
234
234
|
errorCode: 'NTS-AS0-BASE-UR',
|
|
@@ -337,193 +337,212 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
|
|
|
337
337
|
});
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
|
+
// eslint-disable-next-line max-lines-per-function
|
|
340
341
|
async ready(timeout = 4 * fsm_dynamo_1.second) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
342
|
+
try {
|
|
343
|
+
if (this.fnLogs)
|
|
344
|
+
fsm_dynamo_1.DyFM_Log.log('\nfn:. ready');
|
|
345
|
+
await (0, fsm_dynamo_1.DyFM_delay)(100);
|
|
346
|
+
let ready = false;
|
|
347
|
+
const start = +new Date();
|
|
348
|
+
if (this.constructErrors.length) {
|
|
349
|
+
if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
350
|
+
fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 1)`, `\n construct ERRORS:`, this.constructErrors);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 1)`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
|
|
354
|
+
if (error instanceof fsm_dynamo_1.DyFM_Error) {
|
|
355
|
+
return error.getErrorSimplified();
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
return error;
|
|
359
|
+
}
|
|
360
|
+
}));
|
|
361
|
+
}
|
|
362
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
363
|
+
...this._getDefaultErrorSettings('ready', new Error(`${this._params.name} start failed.`)),
|
|
364
|
+
errorCode: 'NTS-AS0-R01',
|
|
365
|
+
additionalContent: this.constructErrors.length === 1 ?
|
|
366
|
+
this.constructErrors[0] :
|
|
367
|
+
{ errors: this.constructErrors },
|
|
368
|
+
});
|
|
348
369
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
}
|
|
370
|
+
while (!ready && +new Date() - start < timeout) {
|
|
371
|
+
if (this.systemControls.app.init) {
|
|
372
|
+
ready = (this.systemControls.mongoose.getReady() &&
|
|
373
|
+
this.systemControls.httpServer.getReady() &&
|
|
374
|
+
this.systemControls.httpsServer.getReady());
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
fsm_dynamo_1.DyFM_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
|
|
378
|
+
}
|
|
379
|
+
if (!ready) {
|
|
380
|
+
await (0, fsm_dynamo_1.DyFM_wait)(100);
|
|
381
|
+
}
|
|
358
382
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
{
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
383
|
+
if (timeout < +new Date() - start) {
|
|
384
|
+
if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
385
|
+
fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. TIMEOUT`, `\n construct ERRORS:`, this.constructErrors);
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
388
|
+
fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. TIMEOUT`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
|
|
389
|
+
if (error instanceof fsm_dynamo_1.DyFM_Error) {
|
|
390
|
+
return error.getErrorSimplified();
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
return error;
|
|
394
|
+
}
|
|
395
|
+
}));
|
|
396
|
+
}
|
|
397
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
398
|
+
...this._getDefaultErrorSettings('ready', new Error(`${this._params.name} start failed. TIMEOUT`)),
|
|
399
|
+
errorCode: 'NTS-AS0-R02',
|
|
400
|
+
additionalContent: {
|
|
401
|
+
constructErrors: this.constructErrors,
|
|
402
|
+
systemControls: this.systemControls,
|
|
403
|
+
systemReadies: {
|
|
404
|
+
mongoose: this.systemControls.mongoose.getReady(),
|
|
405
|
+
httpServer: this.systemControls.httpServer.getReady(),
|
|
406
|
+
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
407
|
+
},
|
|
408
|
+
},
|
|
409
|
+
});
|
|
372
410
|
}
|
|
373
|
-
|
|
374
|
-
|
|
411
|
+
if (this.constructErrors.length) {
|
|
412
|
+
if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
413
|
+
fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 2)`, `\n construct ERRORS:`, this.constructErrors);
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 2)`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
|
|
417
|
+
if (error instanceof fsm_dynamo_1.DyFM_Error) {
|
|
418
|
+
return error.getErrorSimplified();
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
return error;
|
|
422
|
+
}
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
426
|
+
...this._getDefaultErrorSettings('ready', new Error(`${this._params.name} start failed.`)),
|
|
427
|
+
errorCode: 'NTS-AS0-R03',
|
|
428
|
+
additionalContent: this.constructErrors,
|
|
429
|
+
});
|
|
375
430
|
}
|
|
376
|
-
if (
|
|
377
|
-
|
|
431
|
+
if (ready) {
|
|
432
|
+
this.systemControls.app.started = true;
|
|
433
|
+
if (this.fnLogs && this.deepLog)
|
|
434
|
+
fsm_dynamo_1.DyFM_Log.log('\nfn:. ready: return');
|
|
435
|
+
return;
|
|
378
436
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
if (
|
|
382
|
-
|
|
437
|
+
this.systemControls.app.started = false;
|
|
438
|
+
let msg = `${this._params.name} start failed. UNKNOWN`;
|
|
439
|
+
if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
|
|
440
|
+
msg += `\nMongoose start failed.`;
|
|
383
441
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
else {
|
|
390
|
-
return error;
|
|
391
|
-
}
|
|
392
|
-
}));
|
|
442
|
+
if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
|
|
443
|
+
msg += `\nHTTP Server start failed.`;
|
|
444
|
+
}
|
|
445
|
+
if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
|
|
446
|
+
msg += `\nHTTPS Server start failed.`;
|
|
393
447
|
}
|
|
448
|
+
fsm_dynamo_1.DyFM_Log.error(msg, this.constructErrors);
|
|
394
449
|
throw new fsm_dynamo_1.DyFM_Error({
|
|
395
|
-
...this._getDefaultErrorSettings('ready', new Error(
|
|
396
|
-
errorCode: 'NTS-AS0-
|
|
450
|
+
...this._getDefaultErrorSettings('ready', new Error(msg)),
|
|
451
|
+
errorCode: 'NTS-AS0-R04',
|
|
397
452
|
additionalContent: {
|
|
398
453
|
constructErrors: this.constructErrors,
|
|
399
454
|
systemControls: this.systemControls,
|
|
400
455
|
systemReadies: {
|
|
456
|
+
app: this.systemControls.app.getReady(),
|
|
401
457
|
mongoose: this.systemControls.mongoose.getReady(),
|
|
402
458
|
httpServer: this.systemControls.httpServer.getReady(),
|
|
403
459
|
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
404
460
|
},
|
|
405
461
|
},
|
|
462
|
+
error: this.constructErrors?.[0] ?? new Error(),
|
|
406
463
|
});
|
|
407
464
|
}
|
|
408
|
-
|
|
409
|
-
if (global_settings_const_1.DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
410
|
-
fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 2)`, `\n construct ERRORS:`, this.constructErrors);
|
|
411
|
-
}
|
|
412
|
-
else {
|
|
413
|
-
fsm_dynamo_1.DyFM_Log.H_error(`${this._params.name} start failed. (ready check 2)`, `\n construct ERRORS:`, this.constructErrors.map((error) => {
|
|
414
|
-
if (error instanceof fsm_dynamo_1.DyFM_Error) {
|
|
415
|
-
return error.getErrorSimplified();
|
|
416
|
-
}
|
|
417
|
-
else {
|
|
418
|
-
return error;
|
|
419
|
-
}
|
|
420
|
-
}));
|
|
421
|
-
}
|
|
465
|
+
catch (error) {
|
|
422
466
|
throw new fsm_dynamo_1.DyFM_Error({
|
|
423
|
-
...this._getDefaultErrorSettings('ready',
|
|
424
|
-
errorCode: 'NTS-AS0-
|
|
425
|
-
additionalContent: this.constructErrors,
|
|
467
|
+
...this._getDefaultErrorSettings('ready', error),
|
|
468
|
+
errorCode: 'NTS-AS0-READY0',
|
|
426
469
|
});
|
|
427
470
|
}
|
|
428
|
-
if (ready) {
|
|
429
|
-
this.systemControls.app.started = true;
|
|
430
|
-
if (this.fnLogs && this.deepLog)
|
|
431
|
-
fsm_dynamo_1.DyFM_Log.log('\nfn:. ready: return');
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
this.systemControls.app.started = false;
|
|
435
|
-
let msg = `${this._params.name} start failed. UNKNOWN`;
|
|
436
|
-
if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
|
|
437
|
-
msg += `\nMongoose start failed.`;
|
|
438
|
-
}
|
|
439
|
-
if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
|
|
440
|
-
msg += `\nHTTP Server start failed.`;
|
|
441
|
-
}
|
|
442
|
-
if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
|
|
443
|
-
msg += `\nHTTPS Server start failed.`;
|
|
444
|
-
}
|
|
445
|
-
fsm_dynamo_1.DyFM_Log.error(msg, this.constructErrors);
|
|
446
|
-
throw new fsm_dynamo_1.DyFM_Error({
|
|
447
|
-
...this._getDefaultErrorSettings('ready', new Error(msg)),
|
|
448
|
-
errorCode: 'NTS-AS0-R04',
|
|
449
|
-
additionalContent: {
|
|
450
|
-
constructErrors: this.constructErrors,
|
|
451
|
-
systemControls: this.systemControls,
|
|
452
|
-
systemReadies: {
|
|
453
|
-
app: this.systemControls.app.getReady(),
|
|
454
|
-
mongoose: this.systemControls.mongoose.getReady(),
|
|
455
|
-
httpServer: this.systemControls.httpServer.getReady(),
|
|
456
|
-
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
error: this.constructErrors?.[0] ?? new Error(),
|
|
460
|
-
});
|
|
461
471
|
}
|
|
462
472
|
async stop(dontLog) {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
if (this.
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
!this.
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
this.systemControls.mongoose.started = false;
|
|
476
|
-
if (this.mongoose) {
|
|
477
|
-
await fsm_dynamo_1.DyFM_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
|
|
478
|
-
await this.mongoose.deleteModel(modelName);
|
|
479
|
-
});
|
|
480
|
-
const disconnect = new Promise((resolve) => {
|
|
481
|
-
this.mongoose.connection.on('disconnecting', () => {
|
|
482
|
-
resolve();
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
await this.mongoose.disconnect();
|
|
486
|
-
await this.mongoose.connection.close();
|
|
487
|
-
await disconnect;
|
|
488
|
-
while (this.mongoose.connection.readyState !== 0 &&
|
|
489
|
-
!this.constructErrors.length) {
|
|
490
|
-
fsm_dynamo_1.DyFM_Log.warn(`\nMongoose still not disconnected....`);
|
|
473
|
+
try {
|
|
474
|
+
fsm_dynamo_1.DyFM_Log.info('\nstopping server...\n');
|
|
475
|
+
await this.ready();
|
|
476
|
+
if (this.started) {
|
|
477
|
+
if (this.systemControls.mongoose.init) {
|
|
478
|
+
fsm_dynamo_1.DyFM_Log.info(`\nstopping Mongoose....`);
|
|
479
|
+
let tryCount = 0;
|
|
480
|
+
while (!this.systemControls.mongoose.started &&
|
|
481
|
+
!this.constructErrors.length &&
|
|
482
|
+
tryCount++ < 10) {
|
|
483
|
+
fsm_dynamo_1.DyFM_Log.warn(`Mongoose not even started yet....`);
|
|
491
484
|
await (0, fsm_dynamo_1.DyFM_wait)(fsm_dynamo_1.second);
|
|
492
485
|
}
|
|
486
|
+
this.systemControls.mongoose.started = false;
|
|
487
|
+
if (this.mongoose) {
|
|
488
|
+
await fsm_dynamo_1.DyFM_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
|
|
489
|
+
this.mongoose.deleteModel(modelName);
|
|
490
|
+
});
|
|
491
|
+
const disconnect = new Promise((resolve) => {
|
|
492
|
+
this.mongoose.connection.on('disconnecting', () => {
|
|
493
|
+
resolve();
|
|
494
|
+
});
|
|
495
|
+
});
|
|
496
|
+
await this.mongoose.disconnect();
|
|
497
|
+
await this.mongoose.connection.close();
|
|
498
|
+
await disconnect;
|
|
499
|
+
while (this.mongoose.connection.readyState !== 0 &&
|
|
500
|
+
!this.constructErrors.length) {
|
|
501
|
+
fsm_dynamo_1.DyFM_Log.warn(`\nMongoose still not disconnected....`);
|
|
502
|
+
await (0, fsm_dynamo_1.DyFM_wait)(fsm_dynamo_1.second);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
fsm_dynamo_1.DyFM_Log.error(`\nMongoose not found.`);
|
|
507
|
+
}
|
|
508
|
+
this.systemControls.mongoose.init = false;
|
|
493
509
|
}
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
else {
|
|
507
|
-
fsm_dynamo_1.DyFM_Log.error(`\nHTTP Server not found.`);
|
|
510
|
+
if (this.systemControls.httpServer.init) {
|
|
511
|
+
this.systemControls.httpServer.started = false;
|
|
512
|
+
if (this.httpServer) {
|
|
513
|
+
await new Promise((resolve) => {
|
|
514
|
+
this.httpServer.close(resolve);
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
fsm_dynamo_1.DyFM_Log.error(`\nHTTP Server not found.`);
|
|
519
|
+
}
|
|
520
|
+
this.systemControls.httpServer.init = false;
|
|
508
521
|
}
|
|
509
|
-
this.systemControls.
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
522
|
+
if (this.systemControls.httpsServer.init) {
|
|
523
|
+
this.systemControls.httpsServer.started = false;
|
|
524
|
+
if (this.httpsServer) {
|
|
525
|
+
await new Promise((resolve) => {
|
|
526
|
+
this.httpsServer.close(resolve);
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
else {
|
|
530
|
+
fsm_dynamo_1.DyFM_Log.error(`\nHTTPS Server not found.`);
|
|
531
|
+
}
|
|
532
|
+
this.systemControls.httpsServer.init = false;
|
|
517
533
|
}
|
|
518
|
-
|
|
519
|
-
|
|
534
|
+
await (0, fsm_dynamo_1.DyFM_wait)(fsm_dynamo_1.second);
|
|
535
|
+
if (!dontLog) {
|
|
536
|
+
fsm_dynamo_1.DyFM_Log.H_log(`${this._params.name} stopped successfully.`);
|
|
520
537
|
}
|
|
521
|
-
this.systemControls.httpsServer.init = false;
|
|
522
|
-
}
|
|
523
|
-
if (!dontLog) {
|
|
524
|
-
fsm_dynamo_1.DyFM_Log.H_log(`${this._params.name} stopped successfully.`);
|
|
525
538
|
}
|
|
526
539
|
}
|
|
540
|
+
catch (error) {
|
|
541
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
542
|
+
...this._getDefaultErrorSettings('stop', error),
|
|
543
|
+
errorCode: 'NTS-AS0-STOP0',
|
|
544
|
+
});
|
|
545
|
+
}
|
|
527
546
|
}
|
|
528
547
|
/**
|
|
529
548
|
*
|
|
@@ -531,44 +550,60 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
|
|
|
531
550
|
async startDB() {
|
|
532
551
|
if (this.fnLogs && this.deepLog)
|
|
533
552
|
fsm_dynamo_1.DyFM_Log.log('\nfn:. startDB');
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
.
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
this.
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
553
|
+
try {
|
|
554
|
+
await new Promise((resolve, reject) => {
|
|
555
|
+
this.systemControls.mongoose.init = true;
|
|
556
|
+
this.mongoose.connection
|
|
557
|
+
.once('open', () => {
|
|
558
|
+
this.systemControls.mongoose.started = true;
|
|
559
|
+
fsm_dynamo_1.DyFM_Log.success('\nConnected to MongoDB\n');
|
|
560
|
+
resolve();
|
|
561
|
+
})
|
|
562
|
+
.on('error', (error) => {
|
|
563
|
+
if (!this.systemControls.mongoose.started) {
|
|
564
|
+
this.constructErrors.push(error);
|
|
565
|
+
if (this.debugLog)
|
|
566
|
+
fsm_dynamo_1.DyFM_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
|
|
567
|
+
const d_error = new fsm_dynamo_1.DyFM_Error({
|
|
568
|
+
...this._getDefaultErrorSettings('startDB', error),
|
|
569
|
+
errorCode: 'NTS-AS0-SDB1',
|
|
570
|
+
message: `Unable to start connection to MongoDB server, ERROR: ${error}`,
|
|
571
|
+
});
|
|
572
|
+
global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
573
|
+
reject(d_error);
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
if (this.debugLog)
|
|
577
|
+
fsm_dynamo_1.DyFM_Log.error('\nMongoDB ERROR: ', error);
|
|
578
|
+
const d_error = new fsm_dynamo_1.DyFM_Error({
|
|
579
|
+
...this._getDefaultErrorSettings('mongoose.connection.on(error)', error),
|
|
580
|
+
errorCode: 'NTS-AS0-SDB2',
|
|
581
|
+
message: `MongoDB ERROR: ${error}`,
|
|
582
|
+
level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
|
|
583
|
+
});
|
|
584
|
+
global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
try {
|
|
588
|
+
this.mongoose.connect(this._params.dbUri, {
|
|
589
|
+
useNewUrlParser: true,
|
|
590
|
+
useUnifiedTopology: true,
|
|
551
591
|
});
|
|
552
|
-
global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
553
|
-
reject(d_error);
|
|
554
592
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
...this._getDefaultErrorSettings('mongoose.connection.on(error)', error),
|
|
560
|
-
errorCode: 'NTS-AS0-SDB2',
|
|
561
|
-
message: `MongoDB ERROR: ${error}`,
|
|
562
|
-
level: fsm_dynamo_1.DyFM_ErrorLevel.critical,
|
|
593
|
+
catch (error) {
|
|
594
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
595
|
+
...this._getDefaultErrorSettings('startDB', error),
|
|
596
|
+
errorCode: 'NTS-AS0-SDB3',
|
|
563
597
|
});
|
|
564
|
-
global_service_1.DyNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
565
598
|
}
|
|
566
599
|
});
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
600
|
+
}
|
|
601
|
+
catch (error) {
|
|
602
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
603
|
+
...this._getDefaultErrorSettings('startDB', error),
|
|
604
|
+
errorCode: 'NTS-AS0-SDB0',
|
|
570
605
|
});
|
|
571
|
-
}
|
|
606
|
+
}
|
|
572
607
|
}
|
|
573
608
|
/**
|
|
574
609
|
*
|
|
@@ -576,64 +611,72 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
|
|
|
576
611
|
async initExpresses() {
|
|
577
612
|
if (this.fnLogs && this.deepLog)
|
|
578
613
|
fsm_dynamo_1.DyFM_Log.log('\nfn:. initExpresses');
|
|
579
|
-
|
|
580
|
-
if (
|
|
581
|
-
|
|
582
|
-
`\
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
614
|
+
try {
|
|
615
|
+
if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
|
|
616
|
+
if (!this._portSettings.httpPort) {
|
|
617
|
+
let errorMsg = `\nYou have open routes, but httpPort is not set!` +
|
|
618
|
+
`\nsecurity: ${this._security}` +
|
|
619
|
+
`\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
|
|
620
|
+
errorMsg += '\n\nThe routes setted to use open server:';
|
|
621
|
+
this._routingModules.forEach((module) => {
|
|
622
|
+
if (module.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
|
|
623
|
+
errorMsg += `\n ${module.route} (security: ${module.security})`;
|
|
624
|
+
errorMsg += `\n subroutes using open sever:`;
|
|
625
|
+
module.endpoints.forEach((endpoint) => {
|
|
626
|
+
if (endpoint.security != route_security_enum_1.DyNTS_RouteSecurity.secure) {
|
|
627
|
+
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
const error = new Error('Open routes cannot be established!');
|
|
633
|
+
const errorStack = error.stack.split('\n');
|
|
634
|
+
errorStack.splice(1, 2);
|
|
635
|
+
error.stack = errorStack.join('\n');
|
|
636
|
+
fsm_dynamo_1.DyFM_Log.error(errorMsg);
|
|
637
|
+
throw error;
|
|
638
|
+
}
|
|
639
|
+
await this.initOpenExpress();
|
|
602
640
|
}
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
641
|
+
if (this._security && this._security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
|
|
642
|
+
if (!this._cert || !this._portSettings.httpsPort) {
|
|
643
|
+
let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
|
|
644
|
+
`\nsecurity: ${this._security}` +
|
|
645
|
+
`\nset...` +
|
|
646
|
+
`\n(missing exact howto...)` +
|
|
647
|
+
/* `\n httpsPort and` +
|
|
648
|
+
`\n cert: {` +
|
|
649
|
+
`\n keyPath: FileSystem.PathLike,` +
|
|
650
|
+
`\n certPath: FileSystem.PathLike,` +
|
|
651
|
+
`\n }` + */
|
|
652
|
+
`\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
|
|
653
|
+
errorMsg += '\n\nThe routes setted to use secure server:';
|
|
654
|
+
this._routingModules.forEach((module) => {
|
|
655
|
+
if (module.security && module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
|
|
656
|
+
errorMsg += `\n ${module.route} (security: ${module.security})`;
|
|
657
|
+
errorMsg += `\n subroutes using secure sever:`;
|
|
658
|
+
module.endpoints.forEach((endpoint) => {
|
|
659
|
+
if (endpoint.security && endpoint.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
|
|
660
|
+
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
const error = new Error('Secure routes cannot be established!');
|
|
666
|
+
const errorStack = error.stack.split('\n');
|
|
667
|
+
errorStack.splice(1, 2);
|
|
668
|
+
error.stack = errorStack.join('\n');
|
|
669
|
+
fsm_dynamo_1.DyFM_Log.error(errorMsg);
|
|
670
|
+
throw error;
|
|
671
|
+
}
|
|
672
|
+
await this.initSecureExpress();
|
|
635
673
|
}
|
|
636
|
-
|
|
674
|
+
}
|
|
675
|
+
catch (error) {
|
|
676
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
677
|
+
...this._getDefaultErrorSettings('initExpresses', error),
|
|
678
|
+
errorCode: 'NTS-AS0-IE0',
|
|
679
|
+
});
|
|
637
680
|
}
|
|
638
681
|
}
|
|
639
682
|
/**
|
|
@@ -761,8 +804,10 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
|
|
|
761
804
|
}
|
|
762
805
|
}
|
|
763
806
|
catch (error) {
|
|
764
|
-
fsm_dynamo_1.
|
|
765
|
-
|
|
807
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
808
|
+
...this._getDefaultErrorSettings('startExpresses', error),
|
|
809
|
+
errorCode: 'NTS-AS0-SE0',
|
|
810
|
+
});
|
|
766
811
|
}
|
|
767
812
|
}
|
|
768
813
|
/**
|
|
@@ -797,59 +842,75 @@ class DyNTS_App extends singleton_service_1.DyNTS_SingletonService {
|
|
|
797
842
|
*
|
|
798
843
|
*/
|
|
799
844
|
async mountSecureRoutes() {
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
if (
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
845
|
+
try {
|
|
846
|
+
if (this.fnLogs && this.deepLog)
|
|
847
|
+
fsm_dynamo_1.DyFM_Log.log('\nfn:. mountSecureRoutes');
|
|
848
|
+
this.openExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
|
|
849
|
+
await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
|
|
850
|
+
if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.open) {
|
|
851
|
+
if (this.logSetup) {
|
|
852
|
+
fsm_dynamo_1.DyFM_Log.log(`route mount (secure): ${module.route}`);
|
|
853
|
+
}
|
|
854
|
+
const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
|
|
855
|
+
if (1 < existingRoutes.length) {
|
|
856
|
+
const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
857
|
+
const errorStack = error.stack.split('\n');
|
|
858
|
+
errorStack.splice(1, 4);
|
|
859
|
+
error.stack = errorStack.join('\n');
|
|
860
|
+
fsm_dynamo_1.DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
861
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
862
|
+
...this._getDefaultErrorSettings('mountSecureRoutes', error),
|
|
863
|
+
errorCode: 'NTS-AS0-MSR1',
|
|
864
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
this.secureExpress.use(module.route, module.secureRouter);
|
|
820
868
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
catch (error) {
|
|
872
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
873
|
+
...this._getDefaultErrorSettings('mountSecureRoutes', error),
|
|
874
|
+
errorCode: 'NTS-AS0-MSR0',
|
|
875
|
+
});
|
|
876
|
+
}
|
|
824
877
|
}
|
|
825
878
|
/**
|
|
826
879
|
*
|
|
827
880
|
*/
|
|
828
881
|
async mountOpenRoutes() {
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
if (
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
882
|
+
try {
|
|
883
|
+
if (this.fnLogs && this.deepLog)
|
|
884
|
+
fsm_dynamo_1.DyFM_Log.log('\nfn:. mountOpenRoutes');
|
|
885
|
+
this.openExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
|
|
886
|
+
await fsm_dynamo_1.DyFM_Array.asyncForEach(this._routingModules, async (module) => {
|
|
887
|
+
if (module.security !== route_security_enum_1.DyNTS_RouteSecurity.secure) {
|
|
888
|
+
if (this.logSetup) {
|
|
889
|
+
fsm_dynamo_1.DyFM_Log.log(`route mount (open): ${module.route}`);
|
|
890
|
+
}
|
|
891
|
+
const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
|
|
892
|
+
if (1 < existingRoutes.length) {
|
|
893
|
+
const error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
894
|
+
const errorStack = error.stack.split('\n');
|
|
895
|
+
errorStack.splice(1, 4);
|
|
896
|
+
error.stack = errorStack.join('\n');
|
|
897
|
+
fsm_dynamo_1.DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
898
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
899
|
+
...this._getDefaultErrorSettings('mountOpenRoutes', error),
|
|
900
|
+
errorCode: 'NTS-AS0-MOR1',
|
|
901
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
902
|
+
});
|
|
903
|
+
}
|
|
904
|
+
this.openExpress.use(module.route, module.openRouter);
|
|
849
905
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
906
|
+
});
|
|
907
|
+
}
|
|
908
|
+
catch (error) {
|
|
909
|
+
throw new fsm_dynamo_1.DyFM_Error({
|
|
910
|
+
...this._getDefaultErrorSettings('mountOpenRoutes', error),
|
|
911
|
+
errorCode: 'NTS-AS0-MOR0',
|
|
912
|
+
});
|
|
913
|
+
}
|
|
853
914
|
}
|
|
854
915
|
/**
|
|
855
916
|
*
|