@futdevpro/nts-dynamo 1.7.15 → 1.7.17
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/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +7 -1
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/system-control.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/system-control.control-model.js +0 -1
- package/lib/_models/control-models/system-control.control-model.js.map +1 -1
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +4 -1
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +1 -0
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +96 -47
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/_models/control-models/endpoint-params.control-model.ts +9 -1
- package/src/_models/control-models/system-control.control-model.ts +0 -1
- package/src/_services/core/global.service.ts +5 -1
- package/src/_services/server/app.server.ts +139 -67
|
@@ -200,13 +200,21 @@ export class DynamoNTS_EndpointParams{
|
|
|
200
200
|
msg += this.getPathParamsLogContent(req);
|
|
201
201
|
|
|
202
202
|
Dynamo_Log.error(msg);
|
|
203
|
-
Dynamo_Log.
|
|
203
|
+
Dynamo_Log.error(
|
|
204
|
+
'ERROR:',
|
|
204
205
|
(error as Dynamo_Error)?.flag?.includes('DYNAMO') ?
|
|
205
206
|
(error as Dynamo_Error).getErrorSimplified() :
|
|
206
207
|
error,
|
|
207
208
|
'\n'
|
|
208
209
|
);
|
|
209
210
|
|
|
211
|
+
if ((error as Dynamo_Error)?.flag?.includes('DYNAMO')) {
|
|
212
|
+
if (!(error as Dynamo_Error).additionalContent) {
|
|
213
|
+
(error as Dynamo_Error).additionalContent = {};
|
|
214
|
+
}
|
|
215
|
+
(error as Dynamo_Error).additionalContent.endpointInfo = msg;
|
|
216
|
+
}
|
|
217
|
+
|
|
210
218
|
await DynamoNTS_GlobalService.globalErrorHandler?.(error, req, res, issuer).catch(err => {
|
|
211
219
|
Dynamo_Log.warn('DynamoNTS_GlobalService.globalErrorHandler failed to handle error: ', err);
|
|
212
220
|
Dynamo_Log.warn('It will proceed as normal.');
|
|
@@ -63,7 +63,11 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
63
63
|
|
|
64
64
|
this.instance.authService = set.authService;
|
|
65
65
|
this.instance.emailServiceCollection = set.emailServiceCollection;
|
|
66
|
-
|
|
66
|
+
|
|
67
|
+
DynamoNTS_GlobalService.globalErrorHandler = set.errorHandler ?? (async (error: any) => {
|
|
68
|
+
Dynamo_Log.warn(`globalErrorHandler not set!`);
|
|
69
|
+
Dynamo_Log.error(`ERROR:\n`, error)
|
|
70
|
+
});
|
|
67
71
|
} catch (error) {
|
|
68
72
|
Dynamo_Log.error(`Failed to create DynamoNTS_GlobalService.`, error);
|
|
69
73
|
/* error = new Dynamo_Error({
|
|
@@ -222,6 +222,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
222
222
|
protected logSetup: boolean;
|
|
223
223
|
protected deepLog: boolean;
|
|
224
224
|
protected logFn: boolean;
|
|
225
|
+
protected debugLog: boolean;
|
|
225
226
|
|
|
226
227
|
constructor(extended?: boolean){
|
|
227
228
|
super();
|
|
@@ -525,38 +526,60 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
525
526
|
*/
|
|
526
527
|
private async startDB(): Promise<void> {
|
|
527
528
|
if (this.logFn && this.deepLog) console.log('\nfn:. startDB');
|
|
529
|
+
|
|
528
530
|
await new Promise<void>(
|
|
529
531
|
async (resolve, reject) => {
|
|
530
532
|
this.systemControls.mongoose.init = true;
|
|
533
|
+
|
|
531
534
|
this.mongoose.connection
|
|
535
|
+
.once('open', () => {
|
|
536
|
+
this.systemControls.mongoose.started = true;
|
|
537
|
+
Dynamo_Log.success('\nConnected to MongoDB\n');
|
|
538
|
+
|
|
539
|
+
resolve();
|
|
540
|
+
})
|
|
532
541
|
.on('error', (error) => {
|
|
533
|
-
this.systemControls.mongoose.started
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
542
|
+
if (!this.systemControls.mongoose.started) {
|
|
543
|
+
this.constructErrors.push(error);
|
|
544
|
+
|
|
545
|
+
if (this.debugLog) Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
|
|
546
|
+
|
|
547
|
+
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
538
548
|
...this._getDefaultErrorSettings(
|
|
539
549
|
'startDB',
|
|
540
550
|
error
|
|
541
551
|
),
|
|
542
|
-
|
|
552
|
+
|
|
543
553
|
errorCode: 'NTS-AS0-SDB1',
|
|
544
|
-
message: `Unable to
|
|
545
|
-
})
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
554
|
+
message: `Unable to start connection to MongoDB server, ERROR: ${error}`,
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
558
|
+
reject(d_error);
|
|
559
|
+
|
|
560
|
+
} else {
|
|
561
|
+
if (this.debugLog) Dynamo_Log.error('\nMongoDB ERROR: ', error);
|
|
562
|
+
|
|
563
|
+
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
564
|
+
...this._getDefaultErrorSettings(
|
|
565
|
+
'mongoose.connection.on(error)',
|
|
566
|
+
error
|
|
567
|
+
),
|
|
568
|
+
|
|
569
|
+
errorCode: 'NTS-AS0-SDB2',
|
|
570
|
+
message: `MongoDB ERROR: ${error}`,
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
574
|
+
}
|
|
552
575
|
});
|
|
553
576
|
|
|
554
577
|
this.mongoose.connect(
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
578
|
+
this._params.dbUri,
|
|
579
|
+
{
|
|
580
|
+
useNewUrlParser: true,
|
|
581
|
+
useUnifiedTopology: true
|
|
582
|
+
}
|
|
560
583
|
);
|
|
561
584
|
}
|
|
562
585
|
);
|
|
@@ -567,6 +590,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
567
590
|
*/
|
|
568
591
|
private async initExpresses(): Promise<void> {
|
|
569
592
|
if (this.logFn && this.deepLog) console.log('\nfn:. initExpresses');
|
|
593
|
+
|
|
570
594
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
571
595
|
if (!this._portSettings.httpPort) {
|
|
572
596
|
let errorMsg: string =
|
|
@@ -604,11 +628,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
604
628
|
`\nYou have secure routes, but the certification paths or httpsPort are not set!` +
|
|
605
629
|
`\nsecurity: ${this._security}` +
|
|
606
630
|
`\nset...` +
|
|
607
|
-
`\n
|
|
631
|
+
`\n(missing exact howto...)` +
|
|
632
|
+
/* `\n httpsPort and` +
|
|
608
633
|
`\n cert: {` +
|
|
609
634
|
`\n keyPath: FileSystem.PathLike,` +
|
|
610
635
|
`\n certPath: FileSystem.PathLike,` +
|
|
611
|
-
`\n }` +
|
|
636
|
+
`\n }` + */
|
|
612
637
|
`\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
|
|
613
638
|
|
|
614
639
|
errorMsg += '\n\nThe routes setted to use secure server:';
|
|
@@ -675,37 +700,56 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
675
700
|
.listen(this._portSettings.httpsPort, 'localhost', 0, () => {
|
|
676
701
|
this.systemControls.httpsServer.started = true;
|
|
677
702
|
Dynamo_Log.success(`\nHTTPS (secure) server is listening on port: ${this._portSettings.httpsPort}`);
|
|
703
|
+
|
|
678
704
|
resolve();
|
|
679
705
|
})
|
|
680
706
|
.on('error', (error) => {
|
|
681
|
-
this.
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
new Dynamo_Error({
|
|
707
|
+
if (this.debugLog) Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
|
|
708
|
+
|
|
709
|
+
if (!this.systemControls.httpsServer.started) {
|
|
710
|
+
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
686
711
|
...this._getDefaultErrorSettings(
|
|
687
712
|
'startExpresses',
|
|
688
713
|
error
|
|
689
714
|
),
|
|
690
715
|
|
|
691
716
|
errorCode: 'NTS-AS0-SE1',
|
|
692
|
-
message: `HTTPS (secure) server ERROR`,
|
|
693
|
-
})
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
717
|
+
message: `HTTPS (secure) start server ERROR`,
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
this.constructErrors.push(d_error);
|
|
721
|
+
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
722
|
+
|
|
723
|
+
reject(d_error);
|
|
724
|
+
|
|
725
|
+
} else {
|
|
726
|
+
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
700
727
|
...this._getDefaultErrorSettings(
|
|
701
|
-
'
|
|
702
|
-
|
|
728
|
+
'httpsServer.on(error)',
|
|
729
|
+
error
|
|
703
730
|
),
|
|
704
731
|
|
|
705
732
|
errorCode: 'NTS-AS0-SE2',
|
|
706
|
-
message: `HTTPS (secure) server
|
|
707
|
-
})
|
|
708
|
-
|
|
733
|
+
message: `HTTPS (secure) server ERROR`,
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
737
|
+
}
|
|
738
|
+
})
|
|
739
|
+
.on('uncaughtException', (ex) => {
|
|
740
|
+
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
741
|
+
...this._getDefaultErrorSettings(
|
|
742
|
+
'httpsServer.on(uncaughtException)',
|
|
743
|
+
ex
|
|
744
|
+
),
|
|
745
|
+
|
|
746
|
+
errorCode: 'NTS-AS0-SE3',
|
|
747
|
+
message: `HTTPS (secure) server uncaughtException`,
|
|
748
|
+
});
|
|
749
|
+
|
|
750
|
+
if (this.debugLog) Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, d_error);
|
|
751
|
+
|
|
752
|
+
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
709
753
|
});
|
|
710
754
|
});
|
|
711
755
|
}
|
|
@@ -717,38 +761,56 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
717
761
|
.listen(this._portSettings.httpPort, () => {
|
|
718
762
|
this.systemControls.httpServer.started = true;
|
|
719
763
|
Dynamo_Log.success(`\nHTTP (open) server is listening on port: ${this._portSettings.httpPort}`);
|
|
764
|
+
|
|
720
765
|
resolve();
|
|
721
766
|
})
|
|
722
767
|
.on('error', (error) => {
|
|
723
|
-
this.
|
|
724
|
-
this.constructErrors.push(error);
|
|
768
|
+
if (this.debugLog) Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
|
|
725
769
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
new Dynamo_Error({
|
|
770
|
+
if (!this.systemControls.httpServer.started) {
|
|
771
|
+
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
729
772
|
...this._getDefaultErrorSettings(
|
|
730
773
|
'startExpresses',
|
|
731
774
|
error
|
|
732
775
|
),
|
|
733
776
|
|
|
734
777
|
errorCode: 'NTS-AS0-SE3',
|
|
735
|
-
message: `HTTP (open) server ERROR`,
|
|
736
|
-
})
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
778
|
+
message: `HTTP (open) start server ERROR`,
|
|
779
|
+
});
|
|
780
|
+
|
|
781
|
+
this.constructErrors.push(d_error);
|
|
782
|
+
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
783
|
+
|
|
784
|
+
reject(d_error);
|
|
785
|
+
|
|
786
|
+
} else {
|
|
787
|
+
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
743
788
|
...this._getDefaultErrorSettings(
|
|
744
|
-
'
|
|
745
|
-
|
|
789
|
+
'httpServer.on(error)',
|
|
790
|
+
error
|
|
746
791
|
),
|
|
747
792
|
|
|
748
793
|
errorCode: 'NTS-AS0-SE4',
|
|
749
|
-
message: `HTTP (open) server
|
|
750
|
-
})
|
|
751
|
-
|
|
794
|
+
message: `HTTP (open) server ERROR`,
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
798
|
+
}
|
|
799
|
+
})
|
|
800
|
+
.on('uncaughtException', (ex) => {
|
|
801
|
+
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
802
|
+
...this._getDefaultErrorSettings(
|
|
803
|
+
'httpServer.on(uncaughtException)',
|
|
804
|
+
ex
|
|
805
|
+
),
|
|
806
|
+
|
|
807
|
+
errorCode: 'NTS-AS0-SE5',
|
|
808
|
+
message: `HTTP (open) server uncaughtException`,
|
|
809
|
+
});
|
|
810
|
+
|
|
811
|
+
if (this.debugLog) Dynamo_Log.warn(`\nHTTP (open) server uncaughtException`, d_error);
|
|
812
|
+
|
|
813
|
+
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
752
814
|
});
|
|
753
815
|
});
|
|
754
816
|
}
|
|
@@ -761,19 +823,29 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
761
823
|
/**
|
|
762
824
|
*
|
|
763
825
|
*/
|
|
764
|
-
private async expressErrorHandling(
|
|
826
|
+
private async expressErrorHandling(error, req, res, next): Promise<void> {
|
|
765
827
|
try {
|
|
766
|
-
if (
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
828
|
+
if (error) {
|
|
829
|
+
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
830
|
+
...this._getDefaultErrorSettings(
|
|
831
|
+
'expressErrorHandling',
|
|
832
|
+
error
|
|
833
|
+
),
|
|
834
|
+
|
|
835
|
+
errorCode: 'NTS-AS0-EEH1',
|
|
836
|
+
message: `Express ERROR`,
|
|
837
|
+
additionalContent: {
|
|
838
|
+
req,
|
|
839
|
+
res,
|
|
840
|
+
},
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
await DynamoNTS_GlobalService.globalErrorHandler?.(d_error, req, res);
|
|
844
|
+
|
|
773
845
|
} else {
|
|
774
846
|
Dynamo_Log.H_error(
|
|
775
847
|
'WTF??? express error; without error?...' +
|
|
776
|
-
'\nerr:',
|
|
848
|
+
'\nerr:', error,
|
|
777
849
|
'\nreq:', req,
|
|
778
850
|
'\nres:', res
|
|
779
851
|
);
|
|
@@ -792,7 +864,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
792
864
|
private async mountSecureRoutes (): Promise<void> {
|
|
793
865
|
if (this.logFn && this.deepLog) console.log('\nfn:. mountSecureRoutes');
|
|
794
866
|
|
|
795
|
-
this.openExpress.use(this.expressErrorHandling);
|
|
867
|
+
this.openExpress.use((error, req, res, next) => this.expressErrorHandling(error, req, res, next));
|
|
796
868
|
|
|
797
869
|
await Dynamo_Array.asyncForEach(this._routingModules, async (module: DynamoNTS_RoutingModule) => {
|
|
798
870
|
if (module.security !== DynamoNTS_RouteSecurity.open) {
|