@futdevpro/nts-dynamo 1.9.32 → 1.9.34
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/control-models/system-control.control-model.d.ts +1 -1
- package/build/_models/control-models/system-control.control-model.d.ts.map +1 -1
- package/build/_models/control-models/system-control.control-model.js +1 -1
- package/build/_models/control-models/system-control.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 +136 -105
- package/build/_modules/socket/_services/app-extended.server.js.map +1 -1
- package/build/_modules/socket/_services/app-extended.server.spec.js +51 -12
- package/build/_modules/socket/_services/app-extended.server.spec.js.map +1 -1
- package/build/_services/core/email.service.d.ts.map +1 -1
- package/build/_services/core/email.service.js +39 -34
- package/build/_services/core/email.service.js.map +1 -1
- package/build/_services/core/global.service.d.ts +18 -4
- package/build/_services/core/global.service.d.ts.map +1 -1
- package/build/_services/core/global.service.js +130 -20
- package/build/_services/core/global.service.js.map +1 -1
- package/build/_services/server/app.server.d.ts +2 -0
- package/build/_services/server/app.server.d.ts.map +1 -1
- package/build/_services/server/app.server.js +362 -297
- package/build/_services/server/app.server.js.map +1 -1
- package/build/_services/server/app.server.spec.js +21 -6
- package/build/_services/server/app.server.spec.js.map +1 -1
- package/package.json +2 -2
- package/src/_models/control-models/endpoint-params.control-model.ts +1 -1
- package/src/_models/control-models/system-control.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 +60 -16
- package/src/_modules/socket/_services/app-extended.server.ts +179 -132
- package/src/_services/core/email.service.ts +61 -51
- package/src/_services/core/global.service.ts +116 -37
- package/src/_services/server/app.server.spec.ts +26 -7
- package/src/_services/server/app.server.ts +483 -447
|
@@ -16,7 +16,8 @@ import {
|
|
|
16
16
|
DyFM_Array, DyFM_Error, DyFM_error_defaults,
|
|
17
17
|
DyFM_Error_Settings,
|
|
18
18
|
DyFM_ErrorLevel, DyFM_Log, second, DyFM_wait,
|
|
19
|
-
DyFM_errorFlag
|
|
19
|
+
DyFM_errorFlag,
|
|
20
|
+
DyFM_delay
|
|
20
21
|
} from '@futdevpro/fsm-dynamo';
|
|
21
22
|
|
|
22
23
|
import { DyNTS_SingletonService } from '../base/singleton.service';
|
|
@@ -249,6 +250,8 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
249
250
|
|
|
250
251
|
private _routingModules: DyNTS_RoutingModule[] = [];
|
|
251
252
|
|
|
253
|
+
protected readonly defaultReadyTimeout: number = 10 * second;
|
|
254
|
+
|
|
252
255
|
override readonly defaultErrorUserMsg =
|
|
253
256
|
`We encountered an unhandled Server Error, ` +
|
|
254
257
|
`\nplease contact the responsible development team.` +
|
|
@@ -270,10 +273,10 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
270
273
|
|
|
271
274
|
process.on('unhandledRejection', (reason: object, p_passWhatIsThis: any): void => {
|
|
272
275
|
DyFM_Log.H_error(
|
|
273
|
-
'Unhandled Rejection: ', p_passWhatIsThis
|
|
274
|
-
'\n Rejection reason:', reason
|
|
276
|
+
'Unhandled Rejection: ', p_passWhatIsThis?.toString()?.split('at')?.[0],
|
|
277
|
+
'\n Rejection reason:', reason?.toString()?.split('at')?.[0],
|
|
275
278
|
'\n\n Stack:',
|
|
276
|
-
(reason as any)
|
|
279
|
+
(reason as any)?.stack?.replaceAll?.('\n at', '\n at'),
|
|
277
280
|
);
|
|
278
281
|
|
|
279
282
|
try {
|
|
@@ -309,11 +312,14 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
309
312
|
`Application: "${this.params?.name}" start failed. (constructor asyncConstruct.catch)`
|
|
310
313
|
);
|
|
311
314
|
}
|
|
315
|
+
|
|
316
|
+
DyFM_Log.H_warn('T1000\n', error?.additionalContent);
|
|
312
317
|
});
|
|
313
318
|
}
|
|
314
319
|
|
|
315
320
|
private async asyncConstruct(extended?: boolean): Promise<void> {
|
|
316
321
|
if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. asyncConstruct');
|
|
322
|
+
|
|
317
323
|
try {
|
|
318
324
|
this.systemControls.app.init = true;
|
|
319
325
|
this._params = this.getAppParams();
|
|
@@ -400,289 +406,308 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
400
406
|
} catch (error) {
|
|
401
407
|
this.constructErrors.push(error);
|
|
402
408
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
409
|
+
if (this.deepLog) {
|
|
410
|
+
if (DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
411
|
+
DyFM_Log.H_error(
|
|
412
|
+
`"${this._params.name}" start failed (in asyncConstruct (highDetailedLog)). `,
|
|
413
|
+
`\n\n construct ERRORS:`, this.constructErrors,
|
|
414
|
+
'\n\nlast error:', error
|
|
415
|
+
);
|
|
416
|
+
} else {
|
|
417
|
+
DyFM_Log.H_error(
|
|
418
|
+
`"${this._params.name}" start failed (in asyncConstruct). `,
|
|
419
|
+
`\n\n construct ERRORS:`, this.getSimplifiedConstructErrors(),
|
|
420
|
+
'\n\nlast error:', error instanceof DyFM_Error ? error.getErrorSimplified() : error
|
|
421
|
+
);
|
|
422
|
+
}
|
|
423
|
+
}
|
|
410
424
|
|
|
411
425
|
throw new DyFM_Error({
|
|
412
|
-
...this._getDefaultErrorSettings(
|
|
413
|
-
'asyncConstruct',
|
|
414
|
-
error
|
|
415
|
-
),
|
|
426
|
+
...this._getDefaultErrorSettings('asyncConstruct', error),
|
|
416
427
|
|
|
417
428
|
errorCode: 'NTS-AS0-001',
|
|
418
429
|
additionalContent: {
|
|
419
430
|
constructErrors: this.constructErrors,
|
|
420
431
|
systemControls: this.systemControls,
|
|
421
432
|
systemReadies: {
|
|
422
|
-
app: this.systemControls.app.
|
|
423
|
-
mongoose: this.systemControls.mongoose.
|
|
424
|
-
httpServer: this.systemControls.httpServer.
|
|
425
|
-
httpsServer: this.systemControls.httpsServer.
|
|
433
|
+
app: this.systemControls.app.getIsReady(),
|
|
434
|
+
mongoose: this.systemControls.mongoose.getIsReady(),
|
|
435
|
+
httpServer: this.systemControls.httpServer.getIsReady(),
|
|
436
|
+
httpsServer: this.systemControls.httpsServer.getIsReady(),
|
|
426
437
|
},
|
|
427
438
|
},
|
|
428
439
|
});
|
|
429
440
|
}
|
|
430
441
|
}
|
|
431
442
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
443
|
+
// eslint-disable-next-line max-lines-per-function
|
|
444
|
+
async ready(timeout: number = this.defaultReadyTimeout): Promise<void> {
|
|
445
|
+
try {
|
|
446
|
+
if (this.fnLogs) DyFM_Log.log('\nfn:. ready');
|
|
447
|
+
|
|
448
|
+
await DyFM_delay(100);
|
|
449
|
+
|
|
450
|
+
let ready: boolean = false;
|
|
451
|
+
const start: number = +new Date();
|
|
452
|
+
|
|
453
|
+
if (this.constructErrors.length) {
|
|
454
|
+
if (this.deepLog) {
|
|
455
|
+
if (DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
456
|
+
DyFM_Log.H_error(
|
|
457
|
+
`"${this._params.name}" start failed. (ready; constructErrors check 1)`,
|
|
458
|
+
`\n construct ERRORS:`, this.constructErrors
|
|
459
|
+
);
|
|
460
|
+
} else {
|
|
461
|
+
DyFM_Log.H_error(
|
|
462
|
+
`"${this._params.name}" start failed. (ready; constructErrors check 1)`,
|
|
463
|
+
`\n construct ERRORS:`, this.getSimplifiedConstructErrors(),
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
436
467
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
return error.getErrorSimplified();
|
|
450
|
-
} else {
|
|
451
|
-
return error;
|
|
452
|
-
}
|
|
453
|
-
}),
|
|
454
|
-
);
|
|
468
|
+
throw new DyFM_Error({
|
|
469
|
+
...this._getDefaultErrorSettings(
|
|
470
|
+
'ready',
|
|
471
|
+
new Error(`"${this._params.name}" start failed.`)
|
|
472
|
+
),
|
|
473
|
+
|
|
474
|
+
errorCode: 'NTS-AS0-R01',
|
|
475
|
+
additionalContent:
|
|
476
|
+
this.constructErrors.length === 1 ?
|
|
477
|
+
{ error: this.constructErrors[0] } :
|
|
478
|
+
{ errors: this.constructErrors },
|
|
479
|
+
});
|
|
455
480
|
}
|
|
456
481
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
this.
|
|
466
|
-
|
|
467
|
-
{ errors: this.constructErrors },
|
|
468
|
-
});
|
|
469
|
-
}
|
|
482
|
+
while (!ready && +new Date() - start < timeout) {
|
|
483
|
+
if (this.systemControls.app.init) {
|
|
484
|
+
ready = (
|
|
485
|
+
this.systemControls.mongoose.getIsReady() &&
|
|
486
|
+
this.systemControls.httpServer.getIsReady() &&
|
|
487
|
+
this.systemControls.httpsServer.getIsReady()
|
|
488
|
+
);
|
|
489
|
+
} else {
|
|
490
|
+
DyFM_Log.error(`"${this._params.name}" APP NOT INITIALIZED while trying to get ready.`);
|
|
491
|
+
}
|
|
470
492
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
)
|
|
478
|
-
|
|
479
|
-
|
|
493
|
+
if (!ready) {
|
|
494
|
+
await DyFM_wait(100);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
if (timeout < +new Date() - start) {
|
|
499
|
+
if (this.deepLog) {
|
|
500
|
+
if (DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
501
|
+
DyFM_Log.H_error(
|
|
502
|
+
`"${this._params.name}" start failed. (ready; TIMEOUT check)`,
|
|
503
|
+
`\n construct ERRORS:`, this.constructErrors
|
|
504
|
+
);
|
|
505
|
+
} else {
|
|
506
|
+
DyFM_Log.H_error(
|
|
507
|
+
`"${this._params.name}" start failed. (ready; TIMEOUT check)`,
|
|
508
|
+
`\n construct ERRORS:`, this.getSimplifiedConstructErrors(),
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
throw new DyFM_Error({
|
|
514
|
+
...this._getDefaultErrorSettings(
|
|
515
|
+
'ready',
|
|
516
|
+
new Error(`"${this._params.name}" start failed. TIMEOUT`)
|
|
517
|
+
),
|
|
518
|
+
|
|
519
|
+
errorCode: 'NTS-AS0-R02',
|
|
520
|
+
additionalContent: {
|
|
521
|
+
constructErrors: this.constructErrors,
|
|
522
|
+
systemControls: this.systemControls,
|
|
523
|
+
systemReadies: {
|
|
524
|
+
mongoose: this.systemControls.mongoose.getIsReady(),
|
|
525
|
+
httpServer: this.systemControls.httpServer.getIsReady(),
|
|
526
|
+
httpsServer: this.systemControls.httpsServer.getIsReady(),
|
|
527
|
+
},
|
|
528
|
+
},
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
if (this.constructErrors.length) {
|
|
533
|
+
if (this.deepLog) {
|
|
534
|
+
if (DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
535
|
+
DyFM_Log.H_error(
|
|
536
|
+
`"${this._params.name}" start failed. (ready; constructErrors check 2)`,
|
|
537
|
+
`\n construct ERRORS:`, this.constructErrors
|
|
538
|
+
);
|
|
539
|
+
} else {
|
|
540
|
+
DyFM_Log.H_error(
|
|
541
|
+
`"${this._params.name}" start failed. (ready; constructErrors check 2)`,
|
|
542
|
+
`\n construct ERRORS:`, this.getSimplifiedConstructErrors(),
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
throw new DyFM_Error({
|
|
548
|
+
...this._getDefaultErrorSettings(
|
|
549
|
+
'ready',
|
|
550
|
+
new Error(`"${this._params.name}" start failed.`)
|
|
551
|
+
),
|
|
552
|
+
|
|
553
|
+
errorCode: 'NTS-AS0-R03',
|
|
554
|
+
additionalContent: this.constructErrors,
|
|
555
|
+
});
|
|
480
556
|
}
|
|
481
557
|
|
|
482
|
-
if (
|
|
483
|
-
|
|
558
|
+
if (ready) {
|
|
559
|
+
this.systemControls.app.started = true;
|
|
560
|
+
|
|
561
|
+
if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. ready: return');
|
|
562
|
+
|
|
563
|
+
return;
|
|
484
564
|
}
|
|
485
|
-
}
|
|
486
565
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
} else {
|
|
494
|
-
DyFM_Log.H_error(
|
|
495
|
-
`${this._params.name} start failed. TIMEOUT`,
|
|
496
|
-
`\n construct ERRORS:`,
|
|
497
|
-
this.constructErrors.map((error: any): any => {
|
|
498
|
-
if (error instanceof DyFM_Error) {
|
|
499
|
-
return error.getErrorSimplified();
|
|
500
|
-
} else {
|
|
501
|
-
return error;
|
|
502
|
-
}
|
|
503
|
-
}),
|
|
504
|
-
);
|
|
566
|
+
this.systemControls.app.started = false;
|
|
567
|
+
|
|
568
|
+
let msg: string = `"${this._params.name}" start failed. UNKNOWN`;
|
|
569
|
+
|
|
570
|
+
if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
|
|
571
|
+
msg += `\nMongoose start failed.`;
|
|
505
572
|
}
|
|
506
573
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
574
|
+
if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
|
|
575
|
+
msg += `\nHTTP Server start failed.`;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
|
|
579
|
+
msg += `\nHTTPS Server start failed.`;
|
|
580
|
+
}
|
|
512
581
|
|
|
513
|
-
|
|
582
|
+
DyFM_Log.error(msg, this.constructErrors);
|
|
583
|
+
|
|
584
|
+
throw new DyFM_Error({
|
|
585
|
+
...this._getDefaultErrorSettings('ready', new Error(msg)),
|
|
586
|
+
|
|
587
|
+
errorCode: 'NTS-AS0-R04',
|
|
514
588
|
additionalContent: {
|
|
515
589
|
constructErrors: this.constructErrors,
|
|
516
590
|
systemControls: this.systemControls,
|
|
517
591
|
systemReadies: {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
592
|
+
app: this.systemControls.app.getIsReady(),
|
|
593
|
+
mongoose: this.systemControls.mongoose.getIsReady(),
|
|
594
|
+
httpServer: this.systemControls.httpServer.getIsReady(),
|
|
595
|
+
httpsServer: this.systemControls.httpsServer.getIsReady(),
|
|
521
596
|
},
|
|
522
597
|
},
|
|
598
|
+
error: this.constructErrors?.[0] ?? new Error(),
|
|
523
599
|
});
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
if (this.constructErrors.length) {
|
|
527
|
-
if (DyNTS_global_settings.log_settings.highDetailedLogs) {
|
|
528
|
-
DyFM_Log.H_error(
|
|
529
|
-
`${this._params.name} start failed. (ready check 2)`,
|
|
530
|
-
`\n construct ERRORS:`, this.constructErrors
|
|
531
|
-
);
|
|
532
|
-
} else {
|
|
533
|
-
DyFM_Log.H_error(
|
|
534
|
-
`${this._params.name} start failed. (ready check 2)`,
|
|
535
|
-
`\n construct ERRORS:`,
|
|
536
|
-
this.constructErrors.map((error: any): any => {
|
|
537
|
-
if (error instanceof DyFM_Error) {
|
|
538
|
-
return error.getErrorSimplified();
|
|
539
|
-
} else {
|
|
540
|
-
return error;
|
|
541
|
-
}
|
|
542
|
-
}),
|
|
543
|
-
);
|
|
544
|
-
}
|
|
545
|
-
|
|
600
|
+
} catch (error) {
|
|
546
601
|
throw new DyFM_Error({
|
|
547
|
-
...this._getDefaultErrorSettings(
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
),
|
|
551
|
-
|
|
552
|
-
errorCode: 'NTS-AS0-R03',
|
|
553
|
-
additionalContent: this.constructErrors,
|
|
602
|
+
...this._getDefaultErrorSettings('ready', error),
|
|
603
|
+
|
|
604
|
+
errorCode: 'NTS-AS0-READY0',
|
|
554
605
|
});
|
|
555
606
|
}
|
|
607
|
+
}
|
|
556
608
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
this.systemControls.app.started = false;
|
|
566
|
-
|
|
567
|
-
let msg: string = `${this._params.name} start failed. UNKNOWN`;
|
|
568
|
-
|
|
569
|
-
if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
|
|
570
|
-
msg += `\nMongoose start failed.`;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
|
|
574
|
-
msg += `\nHTTP Server start failed.`;
|
|
575
|
-
}
|
|
576
|
-
|
|
577
|
-
if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
|
|
578
|
-
msg += `\nHTTPS Server start failed.`;
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
DyFM_Log.error(msg, this.constructErrors);
|
|
582
|
-
|
|
583
|
-
throw new DyFM_Error({
|
|
584
|
-
...this._getDefaultErrorSettings(
|
|
585
|
-
'ready',
|
|
586
|
-
new Error(msg)
|
|
587
|
-
),
|
|
588
|
-
|
|
589
|
-
errorCode: 'NTS-AS0-R04',
|
|
590
|
-
additionalContent: {
|
|
591
|
-
constructErrors: this.constructErrors,
|
|
592
|
-
systemControls: this.systemControls,
|
|
593
|
-
systemReadies: {
|
|
594
|
-
app: this.systemControls.app.getReady(),
|
|
595
|
-
mongoose: this.systemControls.mongoose.getReady(),
|
|
596
|
-
httpServer: this.systemControls.httpServer.getReady(),
|
|
597
|
-
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
598
|
-
},
|
|
599
|
-
},
|
|
600
|
-
error: this.constructErrors?.[0] ?? new Error(),
|
|
609
|
+
protected getSimplifiedConstructErrors(): string[] {
|
|
610
|
+
return this.constructErrors.map((error: any): any => {
|
|
611
|
+
if (error instanceof DyFM_Error) {
|
|
612
|
+
return error.getErrorSimplified();
|
|
613
|
+
} else {
|
|
614
|
+
return error;
|
|
615
|
+
}
|
|
601
616
|
});
|
|
602
617
|
}
|
|
603
618
|
|
|
604
619
|
async stop(dontLog?: boolean): Promise<void> {
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
await this.ready();
|
|
608
|
-
|
|
609
|
-
if (this.started) {
|
|
610
|
-
|
|
611
|
-
if (this.systemControls.mongoose.init) {
|
|
612
|
-
DyFM_Log.info(`\nstopping Mongoose....`);
|
|
620
|
+
try {
|
|
621
|
+
DyFM_Log.info('\nstopping server...\n');
|
|
613
622
|
|
|
614
|
-
|
|
623
|
+
await this.ready();
|
|
615
624
|
|
|
616
|
-
|
|
617
|
-
!this.systemControls.mongoose.started &&
|
|
618
|
-
!this.constructErrors.length &&
|
|
619
|
-
tryCount++ < 10
|
|
620
|
-
) {
|
|
621
|
-
DyFM_Log.warn(`Mongoose not even started yet....`);
|
|
622
|
-
await DyFM_wait(second);
|
|
623
|
-
}
|
|
624
|
-
this.systemControls.mongoose.started = false;
|
|
625
|
+
if (this.started) {
|
|
625
626
|
|
|
626
|
-
if (this.mongoose) {
|
|
627
|
-
|
|
628
|
-
Object.keys(this.mongoose.models),
|
|
629
|
-
async (modelName): Promise<void> => {
|
|
630
|
-
await this.mongoose.deleteModel(modelName);
|
|
631
|
-
}
|
|
632
|
-
);
|
|
627
|
+
if (this.systemControls.mongoose.init) {
|
|
628
|
+
DyFM_Log.info(`\nstopping Mongoose....`);
|
|
633
629
|
|
|
634
|
-
|
|
635
|
-
this.mongoose.connection.on('disconnecting', (): void => {
|
|
636
|
-
resolve();
|
|
637
|
-
});
|
|
638
|
-
});
|
|
639
|
-
|
|
640
|
-
await this.mongoose.disconnect();
|
|
641
|
-
await this.mongoose.connection.close();
|
|
642
|
-
await disconnect;
|
|
630
|
+
let tryCount: number = 0;
|
|
643
631
|
|
|
644
632
|
while (
|
|
645
|
-
this.mongoose.
|
|
646
|
-
!this.constructErrors.length
|
|
633
|
+
!this.systemControls.mongoose.started &&
|
|
634
|
+
!this.constructErrors.length &&
|
|
635
|
+
tryCount++ < 10
|
|
647
636
|
) {
|
|
648
|
-
DyFM_Log.warn(
|
|
637
|
+
DyFM_Log.warn(`Mongoose not even started yet....`);
|
|
649
638
|
await DyFM_wait(second);
|
|
650
639
|
}
|
|
651
|
-
|
|
652
|
-
|
|
640
|
+
this.systemControls.mongoose.started = false;
|
|
641
|
+
|
|
642
|
+
if (this.mongoose) {
|
|
643
|
+
await DyFM_Array.asyncForEach(
|
|
644
|
+
Object.keys(this.mongoose.models),
|
|
645
|
+
async (modelName): Promise<void> => {
|
|
646
|
+
this.mongoose.deleteModel(modelName);
|
|
647
|
+
}
|
|
648
|
+
);
|
|
649
|
+
|
|
650
|
+
const disconnect: Promise<void> = new Promise((resolve): void => {
|
|
651
|
+
this.mongoose.connection.on('disconnecting', (): void => {
|
|
652
|
+
resolve();
|
|
653
|
+
});
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
await this.mongoose.disconnect();
|
|
657
|
+
await this.mongoose.connection.close();
|
|
658
|
+
await disconnect;
|
|
659
|
+
|
|
660
|
+
while (
|
|
661
|
+
this.mongoose.connection.readyState !== 0 &&
|
|
662
|
+
!this.constructErrors.length
|
|
663
|
+
) {
|
|
664
|
+
DyFM_Log.warn(`\nMongoose still not disconnected....`);
|
|
665
|
+
await DyFM_wait(second);
|
|
666
|
+
}
|
|
667
|
+
} else {
|
|
668
|
+
DyFM_Log.error(`\nMongoose not found.`);
|
|
669
|
+
}
|
|
670
|
+
this.systemControls.mongoose.init = false;
|
|
653
671
|
}
|
|
654
|
-
this.systemControls.mongoose.init = false;
|
|
655
|
-
}
|
|
656
672
|
|
|
657
|
-
|
|
658
|
-
|
|
673
|
+
if (this.systemControls.httpServer.init) {
|
|
674
|
+
this.systemControls.httpServer.started = false;
|
|
659
675
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
676
|
+
if (this.httpServer) {
|
|
677
|
+
await new Promise((resolve): void => {
|
|
678
|
+
this.httpServer.close(resolve);
|
|
679
|
+
});
|
|
680
|
+
} else {
|
|
681
|
+
DyFM_Log.error(`\nHTTP Server not found.`);
|
|
682
|
+
}
|
|
683
|
+
this.systemControls.httpServer.init = false;
|
|
666
684
|
}
|
|
667
|
-
this.systemControls.httpServer.init = false;
|
|
668
|
-
}
|
|
669
685
|
|
|
670
|
-
|
|
671
|
-
|
|
686
|
+
if (this.systemControls.httpsServer.init) {
|
|
687
|
+
this.systemControls.httpsServer.started = false;
|
|
672
688
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
689
|
+
if (this.httpsServer) {
|
|
690
|
+
await new Promise((resolve): void => {
|
|
691
|
+
this.httpsServer.close(resolve);
|
|
692
|
+
});
|
|
693
|
+
} else {
|
|
694
|
+
DyFM_Log.error(`\nHTTPS Server not found.`);
|
|
695
|
+
}
|
|
696
|
+
this.systemControls.httpsServer.init = false;
|
|
679
697
|
}
|
|
680
|
-
this.systemControls.httpsServer.init = false;
|
|
681
|
-
}
|
|
682
698
|
|
|
683
|
-
|
|
684
|
-
|
|
699
|
+
await DyFM_wait(second);
|
|
700
|
+
|
|
701
|
+
if (!dontLog) {
|
|
702
|
+
DyFM_Log.H_log(`"${this._params.name}" stopped successfully.`);
|
|
703
|
+
}
|
|
685
704
|
}
|
|
705
|
+
} catch (error) {
|
|
706
|
+
throw new DyFM_Error({
|
|
707
|
+
...this._getDefaultErrorSettings('stop', error),
|
|
708
|
+
|
|
709
|
+
errorCode: 'NTS-AS0-STOP0',
|
|
710
|
+
});
|
|
686
711
|
}
|
|
687
712
|
}
|
|
688
713
|
|
|
@@ -692,66 +717,77 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
692
717
|
private async startDB(): Promise<void> {
|
|
693
718
|
if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. startDB');
|
|
694
719
|
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
720
|
+
try {
|
|
721
|
+
await new Promise<void>(
|
|
722
|
+
(resolve, reject): void => {
|
|
723
|
+
this.systemControls.mongoose.init = true;
|
|
698
724
|
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
725
|
+
this.mongoose.connection
|
|
726
|
+
.once('open', (): void => {
|
|
727
|
+
this.systemControls.mongoose.started = true;
|
|
728
|
+
DyFM_Log.success('\nConnected to MongoDB\n');
|
|
703
729
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
if (this.debugLog) DyFM_Log.error(
|
|
711
|
-
'\nUnable to connect to MongoDB server, ERROR: ',
|
|
712
|
-
error
|
|
713
|
-
);
|
|
730
|
+
resolve();
|
|
731
|
+
})
|
|
732
|
+
.on('error', (error): void => {
|
|
733
|
+
if (!this.systemControls.mongoose.started) {
|
|
734
|
+
this.constructErrors.push(error);
|
|
714
735
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
'startDB',
|
|
736
|
+
if (this.debugLog) DyFM_Log.error(
|
|
737
|
+
'\nUnable to connect to MongoDB server, ERROR: ',
|
|
718
738
|
error
|
|
719
|
-
)
|
|
720
|
-
|
|
721
|
-
errorCode: 'NTS-AS0-SDB1',
|
|
722
|
-
message: `Unable to start connection to MongoDB server, ERROR: ${error}`,
|
|
723
|
-
});
|
|
739
|
+
);
|
|
724
740
|
|
|
725
|
-
|
|
726
|
-
|
|
741
|
+
const d_error: DyFM_Error = new DyFM_Error({
|
|
742
|
+
...this._getDefaultErrorSettings('startDB', error),
|
|
743
|
+
|
|
744
|
+
errorCode: 'NTS-AS0-SDB1',
|
|
745
|
+
message: `Unable to start connection to MongoDB server, ERROR: ${error}`,
|
|
746
|
+
});
|
|
727
747
|
|
|
728
|
-
|
|
729
|
-
if (this.debugLog) DyFM_Log.error('\nMongoDB ERROR: ', error);
|
|
748
|
+
DyNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
730
749
|
|
|
731
|
-
|
|
732
|
-
...this._getDefaultErrorSettings(
|
|
733
|
-
'mongoose.connection.on(error)',
|
|
734
|
-
error
|
|
735
|
-
),
|
|
736
|
-
|
|
737
|
-
errorCode: 'NTS-AS0-SDB2',
|
|
738
|
-
message: `MongoDB ERROR: ${error}`,
|
|
739
|
-
level: DyFM_ErrorLevel.critical,
|
|
740
|
-
});
|
|
750
|
+
reject(d_error);
|
|
741
751
|
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
});
|
|
752
|
+
} else {
|
|
753
|
+
if (this.debugLog) DyFM_Log.error('\nMongoDB ERROR: ', error);
|
|
745
754
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
755
|
+
const d_error: DyFM_Error = new DyFM_Error({
|
|
756
|
+
...this._getDefaultErrorSettings('mongoose.connection.on(error)', error),
|
|
757
|
+
|
|
758
|
+
errorCode: 'NTS-AS0-SDB2',
|
|
759
|
+
message: `MongoDB ERROR: ${error}`,
|
|
760
|
+
level: DyFM_ErrorLevel.critical,
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
DyNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
764
|
+
}
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
try {
|
|
768
|
+
this.mongoose.connect(
|
|
769
|
+
this._params.dbUri,
|
|
770
|
+
{
|
|
771
|
+
useNewUrlParser: true,
|
|
772
|
+
useUnifiedTopology: true,
|
|
773
|
+
}
|
|
774
|
+
);
|
|
775
|
+
} catch (error) {
|
|
776
|
+
throw new DyFM_Error({
|
|
777
|
+
...this._getDefaultErrorSettings('startDB', error),
|
|
778
|
+
|
|
779
|
+
errorCode: 'NTS-AS0-SDB3',
|
|
780
|
+
});
|
|
751
781
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
)
|
|
782
|
+
}
|
|
783
|
+
);
|
|
784
|
+
} catch (error) {
|
|
785
|
+
throw new DyFM_Error({
|
|
786
|
+
...this._getDefaultErrorSettings('startDB', error),
|
|
787
|
+
|
|
788
|
+
errorCode: 'NTS-AS0-SDB0',
|
|
789
|
+
});
|
|
790
|
+
}
|
|
755
791
|
}
|
|
756
792
|
|
|
757
793
|
/**
|
|
@@ -760,79 +796,87 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
760
796
|
private async initExpresses(): Promise<void> {
|
|
761
797
|
if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. initExpresses');
|
|
762
798
|
|
|
763
|
-
|
|
764
|
-
if (
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
799
|
+
try {
|
|
800
|
+
if (this._security && this._security !== DyNTS_RouteSecurity.secure) {
|
|
801
|
+
if (!this._portSettings.httpPort) {
|
|
802
|
+
let errorMsg: string =
|
|
803
|
+
`\nYou have open routes, but httpPort is not set!` +
|
|
804
|
+
`\nsecurity: ${this._security}` +
|
|
805
|
+
`\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
|
|
806
|
+
|
|
807
|
+
errorMsg += '\n\nThe routes setted to use open server:';
|
|
808
|
+
this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
|
|
809
|
+
if (module.security != DyNTS_RouteSecurity.secure) {
|
|
810
|
+
errorMsg += `\n ${module.route} (security: ${module.security})`;
|
|
811
|
+
errorMsg += `\n subroutes using open sever:`;
|
|
812
|
+
module.endpoints.forEach((endpoint: DyNTS_Endpoint_Params): void => {
|
|
813
|
+
if (endpoint.security != DyNTS_RouteSecurity.secure) {
|
|
814
|
+
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
});
|
|
782
819
|
|
|
783
|
-
|
|
784
|
-
|
|
820
|
+
const error = new Error('Open routes cannot be established!');
|
|
821
|
+
const errorStack: string[] = error.stack.split('\n');
|
|
785
822
|
|
|
786
|
-
|
|
787
|
-
|
|
823
|
+
errorStack.splice(1, 2);
|
|
824
|
+
error.stack = errorStack.join('\n');
|
|
788
825
|
|
|
789
|
-
|
|
826
|
+
DyFM_Log.error(errorMsg);
|
|
790
827
|
|
|
791
|
-
|
|
828
|
+
throw error;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
await this.initOpenExpress();
|
|
792
832
|
}
|
|
793
833
|
|
|
794
|
-
|
|
795
|
-
|
|
834
|
+
if (this._security && this._security !== DyNTS_RouteSecurity.open) {
|
|
835
|
+
if (!this._cert || !this._portSettings.httpsPort) {
|
|
836
|
+
let errorMsg: string =
|
|
837
|
+
`\nYou have secure routes, but the certification paths or httpsPort are not set!` +
|
|
838
|
+
`\nsecurity: ${this._security}` +
|
|
839
|
+
`\nset...` +
|
|
840
|
+
`\n(missing exact howto...)` +
|
|
841
|
+
/* `\n httpsPort and` +
|
|
842
|
+
`\n cert: {` +
|
|
843
|
+
`\n keyPath: FileSystem.PathLike,` +
|
|
844
|
+
`\n certPath: FileSystem.PathLike,` +
|
|
845
|
+
`\n }` + */
|
|
846
|
+
`\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
|
|
847
|
+
|
|
848
|
+
errorMsg += '\n\nThe routes setted to use secure server:';
|
|
849
|
+
this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
|
|
850
|
+
if (module.security && module.security !== DyNTS_RouteSecurity.open) {
|
|
851
|
+
errorMsg += `\n ${module.route} (security: ${module.security})`;
|
|
852
|
+
errorMsg += `\n subroutes using secure sever:`;
|
|
853
|
+
module.endpoints.forEach((endpoint: DyNTS_Endpoint_Params): void => {
|
|
854
|
+
if (endpoint.security && endpoint.security !== DyNTS_RouteSecurity.open) {
|
|
855
|
+
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
});
|
|
796
860
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
let errorMsg: string =
|
|
800
|
-
`\nYou have secure routes, but the certification paths or httpsPort are not set!` +
|
|
801
|
-
`\nsecurity: ${this._security}` +
|
|
802
|
-
`\nset...` +
|
|
803
|
-
`\n(missing exact howto...)` +
|
|
804
|
-
/* `\n httpsPort and` +
|
|
805
|
-
`\n cert: {` +
|
|
806
|
-
`\n keyPath: FileSystem.PathLike,` +
|
|
807
|
-
`\n certPath: FileSystem.PathLike,` +
|
|
808
|
-
`\n }` + */
|
|
809
|
-
`\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
|
|
810
|
-
|
|
811
|
-
errorMsg += '\n\nThe routes setted to use secure server:';
|
|
812
|
-
this._routingModules.forEach((module: DyNTS_RoutingModule): void => {
|
|
813
|
-
if (module.security && module.security !== DyNTS_RouteSecurity.open) {
|
|
814
|
-
errorMsg += `\n ${module.route} (security: ${module.security})`;
|
|
815
|
-
errorMsg += `\n subroutes using secure sever:`;
|
|
816
|
-
module.endpoints.forEach((endpoint: DyNTS_Endpoint_Params): void => {
|
|
817
|
-
if (endpoint.security && endpoint.security !== DyNTS_RouteSecurity.open) {
|
|
818
|
-
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
819
|
-
}
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
});
|
|
861
|
+
const error = new Error('Secure routes cannot be established!');
|
|
862
|
+
const errorStack: string[] = error.stack.split('\n');
|
|
823
863
|
|
|
824
|
-
|
|
825
|
-
|
|
864
|
+
errorStack.splice(1, 2);
|
|
865
|
+
error.stack = errorStack.join('\n');
|
|
826
866
|
|
|
827
|
-
|
|
828
|
-
error.stack = errorStack.join('\n');
|
|
867
|
+
DyFM_Log.error(errorMsg);
|
|
829
868
|
|
|
830
|
-
|
|
869
|
+
throw error;
|
|
870
|
+
}
|
|
831
871
|
|
|
832
|
-
|
|
872
|
+
await this.initSecureExpress();
|
|
833
873
|
}
|
|
834
|
-
|
|
835
|
-
|
|
874
|
+
} catch (error) {
|
|
875
|
+
throw new DyFM_Error({
|
|
876
|
+
...this._getDefaultErrorSettings('initExpresses', error),
|
|
877
|
+
|
|
878
|
+
errorCode: 'NTS-AS0-IE0',
|
|
879
|
+
});
|
|
836
880
|
}
|
|
837
881
|
}
|
|
838
882
|
|
|
@@ -868,6 +912,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
868
912
|
*/
|
|
869
913
|
private async startExpresses(): Promise<void> {
|
|
870
914
|
if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. startExpresses');
|
|
915
|
+
|
|
871
916
|
try {
|
|
872
917
|
if (this._security && this._security !== DyNTS_RouteSecurity.open) {
|
|
873
918
|
await new Promise<void>((resolve, reject): void => {
|
|
@@ -886,10 +931,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
886
931
|
|
|
887
932
|
if (!this.systemControls.httpsServer.started) {
|
|
888
933
|
const d_error: DyFM_Error = new DyFM_Error({
|
|
889
|
-
...this._getDefaultErrorSettings(
|
|
890
|
-
'startExpresses',
|
|
891
|
-
error
|
|
892
|
-
),
|
|
934
|
+
...this._getDefaultErrorSettings('startExpresses', error),
|
|
893
935
|
|
|
894
936
|
errorCode: 'NTS-AS0-SE1',
|
|
895
937
|
message: `HTTPS (secure) start server ERROR`,
|
|
@@ -902,10 +944,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
902
944
|
|
|
903
945
|
} else {
|
|
904
946
|
const d_error: DyFM_Error = new DyFM_Error({
|
|
905
|
-
...this._getDefaultErrorSettings(
|
|
906
|
-
'httpsServer.on(error)',
|
|
907
|
-
error
|
|
908
|
-
),
|
|
947
|
+
...this._getDefaultErrorSettings('httpsServer.on(error)', error),
|
|
909
948
|
|
|
910
949
|
errorCode: 'NTS-AS0-SE2',
|
|
911
950
|
message: `HTTPS (secure) server ERROR`,
|
|
@@ -917,10 +956,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
917
956
|
})
|
|
918
957
|
.on('uncaughtException', (exception): void => {
|
|
919
958
|
const d_error: DyFM_Error = new DyFM_Error({
|
|
920
|
-
...this._getDefaultErrorSettings(
|
|
921
|
-
'httpsServer.on(uncaughtException)',
|
|
922
|
-
exception
|
|
923
|
-
),
|
|
959
|
+
...this._getDefaultErrorSettings('httpsServer.on(uncaughtException)', exception),
|
|
924
960
|
|
|
925
961
|
errorCode: 'NTS-AS0-SE3',
|
|
926
962
|
message: `HTTPS (secure) server uncaughtException`,
|
|
@@ -954,10 +990,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
954
990
|
|
|
955
991
|
if (!this.systemControls.httpServer.started) {
|
|
956
992
|
const d_error: DyFM_Error = new DyFM_Error({
|
|
957
|
-
...this._getDefaultErrorSettings(
|
|
958
|
-
'startExpresses',
|
|
959
|
-
error
|
|
960
|
-
),
|
|
993
|
+
...this._getDefaultErrorSettings('startExpresses', error),
|
|
961
994
|
|
|
962
995
|
errorCode: 'NTS-AS0-SE3',
|
|
963
996
|
message: `HTTP (open) start server ERROR`,
|
|
@@ -970,10 +1003,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
970
1003
|
|
|
971
1004
|
} else {
|
|
972
1005
|
const d_error: DyFM_Error = new DyFM_Error({
|
|
973
|
-
...this._getDefaultErrorSettings(
|
|
974
|
-
'httpServer.on(error)',
|
|
975
|
-
error
|
|
976
|
-
),
|
|
1006
|
+
...this._getDefaultErrorSettings('httpServer.on(error)', error),
|
|
977
1007
|
|
|
978
1008
|
errorCode: 'NTS-AS0-SE4',
|
|
979
1009
|
message: `HTTP (open) server ERROR`,
|
|
@@ -985,10 +1015,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
985
1015
|
})
|
|
986
1016
|
.on('uncaughtException', (exception): void => {
|
|
987
1017
|
const d_error: DyFM_Error = new DyFM_Error({
|
|
988
|
-
...this._getDefaultErrorSettings(
|
|
989
|
-
'httpServer.on(uncaughtException)',
|
|
990
|
-
exception
|
|
991
|
-
),
|
|
1018
|
+
...this._getDefaultErrorSettings('httpServer.on(uncaughtException)', exception),
|
|
992
1019
|
|
|
993
1020
|
errorCode: 'NTS-AS0-SE5',
|
|
994
1021
|
message: `HTTP (open) server uncaughtException`,
|
|
@@ -1004,9 +1031,11 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
1004
1031
|
});
|
|
1005
1032
|
}
|
|
1006
1033
|
} catch (error) {
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1034
|
+
throw new DyFM_Error({
|
|
1035
|
+
...this._getDefaultErrorSettings('startExpresses', error),
|
|
1036
|
+
|
|
1037
|
+
errorCode: 'NTS-AS0-SE0',
|
|
1038
|
+
});
|
|
1010
1039
|
}
|
|
1011
1040
|
}
|
|
1012
1041
|
|
|
@@ -1017,10 +1046,7 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
1017
1046
|
try {
|
|
1018
1047
|
if (error) {
|
|
1019
1048
|
const d_error: DyFM_Error = new DyFM_Error({
|
|
1020
|
-
...this._getDefaultErrorSettings(
|
|
1021
|
-
'expressErrorHandling',
|
|
1022
|
-
error
|
|
1023
|
-
),
|
|
1049
|
+
...this._getDefaultErrorSettings('expressErrorHandling', error),
|
|
1024
1050
|
|
|
1025
1051
|
errorCode: 'NTS-AS0-EEH1',
|
|
1026
1052
|
message: `Express ERROR`,
|
|
@@ -1053,96 +1079,106 @@ export abstract class DyNTS_App extends DyNTS_SingletonService {
|
|
|
1053
1079
|
*
|
|
1054
1080
|
*/
|
|
1055
1081
|
private async mountSecureRoutes (): Promise<void> {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
await DyFM_Array.asyncForEach(
|
|
1063
|
-
this._routingModules,
|
|
1064
|
-
async (module: DyNTS_RoutingModule): Promise<void> => {
|
|
1065
|
-
if (module.security !== DyNTS_RouteSecurity.open) {
|
|
1066
|
-
if (this.logSetup) {
|
|
1067
|
-
DyFM_Log.log(`route mount (secure): ${module.route}`);
|
|
1068
|
-
}
|
|
1069
|
-
|
|
1070
|
-
const existingRoutes: DyNTS_RoutingModule[] = this._routingModules.filter(
|
|
1071
|
-
(mod: DyNTS_RoutingModule): boolean => mod.route === module.route
|
|
1072
|
-
);
|
|
1082
|
+
try {
|
|
1083
|
+
if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. mountSecureRoutes');
|
|
1084
|
+
|
|
1085
|
+
this.openExpress.use(
|
|
1086
|
+
(error, req, res, next): Promise<void> => this.expressErrorHandling(error, req, res, next)
|
|
1087
|
+
);
|
|
1073
1088
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1089
|
+
await DyFM_Array.asyncForEach(
|
|
1090
|
+
this._routingModules,
|
|
1091
|
+
async (module: DyNTS_RoutingModule): Promise<void> => {
|
|
1092
|
+
if (module.security !== DyNTS_RouteSecurity.open) {
|
|
1093
|
+
if (this.logSetup) {
|
|
1094
|
+
DyFM_Log.log(`route mount (secure): ${module.route}`);
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
const existingRoutes: DyNTS_RoutingModule[] = this._routingModules.filter(
|
|
1098
|
+
(mod: DyNTS_RoutingModule): boolean => mod.route === module.route
|
|
1099
|
+
);
|
|
1077
1100
|
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
1101
|
+
if (1 < existingRoutes.length) {
|
|
1102
|
+
const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
1103
|
+
const errorStack: string[] = error.stack.split('\n');
|
|
1082
1104
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
),
|
|
1105
|
+
errorStack.splice(1, 4);
|
|
1106
|
+
error.stack = errorStack.join('\n');
|
|
1107
|
+
|
|
1108
|
+
DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
1088
1109
|
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
});
|
|
1092
|
-
}
|
|
1110
|
+
throw new DyFM_Error({
|
|
1111
|
+
...this._getDefaultErrorSettings('mountSecureRoutes', error),
|
|
1093
1112
|
|
|
1094
|
-
|
|
1113
|
+
errorCode: 'NTS-AS0-MSR1',
|
|
1114
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
this.secureExpress.use(module.route, module.secureRouter);
|
|
1119
|
+
}
|
|
1095
1120
|
}
|
|
1096
|
-
|
|
1097
|
-
)
|
|
1121
|
+
);
|
|
1122
|
+
} catch (error) {
|
|
1123
|
+
throw new DyFM_Error({
|
|
1124
|
+
...this._getDefaultErrorSettings('mountSecureRoutes', error),
|
|
1125
|
+
|
|
1126
|
+
errorCode: 'NTS-AS0-MSR0',
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1098
1129
|
}
|
|
1099
1130
|
|
|
1100
1131
|
/**
|
|
1101
1132
|
*
|
|
1102
1133
|
*/
|
|
1103
1134
|
private async mountOpenRoutes(): Promise<void> {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
if (
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
'mountOpenRoutes',
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1135
|
+
try {
|
|
1136
|
+
if (this.fnLogs && this.deepLog) DyFM_Log.log('\nfn:. mountOpenRoutes');
|
|
1137
|
+
|
|
1138
|
+
this.openExpress.use(
|
|
1139
|
+
(error, req, res, next): Promise<void> => this.expressErrorHandling(error, req, res, next)
|
|
1140
|
+
);
|
|
1141
|
+
|
|
1142
|
+
await DyFM_Array.asyncForEach(
|
|
1143
|
+
this._routingModules,
|
|
1144
|
+
async (module: DyNTS_RoutingModule): Promise<void> => {
|
|
1145
|
+
if (module.security !== DyNTS_RouteSecurity.secure) {
|
|
1146
|
+
if (this.logSetup) {
|
|
1147
|
+
DyFM_Log.log(`route mount (open): ${module.route}`);
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
const existingRoutes: DyNTS_RoutingModule[] = this._routingModules.filter(
|
|
1151
|
+
(mod: DyNTS_RoutingModule): boolean => mod.route === module.route
|
|
1152
|
+
);
|
|
1153
|
+
|
|
1154
|
+
if (1 < existingRoutes.length) {
|
|
1155
|
+
const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
1156
|
+
const errorStack: string[] = error.stack.split('\n');
|
|
1157
|
+
|
|
1158
|
+
errorStack.splice(1, 4);
|
|
1159
|
+
error.stack = errorStack.join('\n');
|
|
1160
|
+
|
|
1161
|
+
DyFM_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
1162
|
+
|
|
1163
|
+
throw new DyFM_Error({
|
|
1164
|
+
...this._getDefaultErrorSettings('mountOpenRoutes', error),
|
|
1165
|
+
|
|
1166
|
+
errorCode: 'NTS-AS0-MOR1',
|
|
1167
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
this.openExpress.use(module.route, module.openRouter);
|
|
1140
1172
|
}
|
|
1141
|
-
|
|
1142
|
-
this.openExpress.use(module.route, module.openRouter);
|
|
1143
1173
|
}
|
|
1144
|
-
|
|
1145
|
-
)
|
|
1174
|
+
);
|
|
1175
|
+
} catch (error) {
|
|
1176
|
+
throw new DyFM_Error({
|
|
1177
|
+
...this._getDefaultErrorSettings('mountOpenRoutes', error),
|
|
1178
|
+
|
|
1179
|
+
errorCode: 'NTS-AS0-MOR0',
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1146
1182
|
}
|
|
1147
1183
|
|
|
1148
1184
|
/**
|