@futdevpro/nts-dynamo 1.7.2 → 1.7.5
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/.copilot/patterns.json +8 -0
- package/lib/_constants/mocks/app-extended-server.mock.d.ts +1 -1
- package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-server.mock.d.ts +1 -1
- package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.js +4 -1
- package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +3 -22
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/port-settings.control-model.d.ts +11 -0
- package/lib/_models/control-models/port-settings.control-model.d.ts.map +1 -0
- package/lib/_models/control-models/port-settings.control-model.js +26 -0
- package/lib/_models/control-models/port-settings.control-model.js.map +1 -0
- package/lib/_models/control-models/socket-presence.control-model.d.ts +5 -3
- package/lib/_models/control-models/socket-presence.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js +34 -20
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_models/interfaces/index.d.ts +1 -1
- package/lib/_models/interfaces/index.d.ts.map +1 -1
- package/lib/_models/interfaces/index.js +1 -1
- package/lib/_models/interfaces/index.js.map +1 -1
- package/lib/_modules/app-extended.index.d.ts +1 -1
- package/lib/_modules/app-extended.index.d.ts.map +1 -1
- package/lib/_modules/app-extended.index.js +1 -1
- package/lib/_modules/app-extended.index.js.map +1 -1
- package/lib/_modules/app.index.d.ts +1 -1
- package/lib/_modules/app.index.d.ts.map +1 -1
- package/lib/_modules/app.index.js +1 -1
- package/lib/_modules/app.index.js.map +1 -1
- package/lib/_services/base/data.service.d.ts +1 -1
- package/lib/_services/base/data.service.d.ts.map +1 -1
- package/lib/_services/base/data.service.js +5 -4
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/core/api.service.d.ts +1 -0
- package/lib/_services/core/api.service.d.ts.map +1 -1
- package/lib/_services/core/api.service.js +19 -21
- package/lib/_services/core/api.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.d.ts +2 -2
- package/lib/_services/server/app-extended.server.d.ts.map +1 -1
- package/lib/_services/server/app-extended.server.js +13 -11
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +9 -70
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +83 -34
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +3 -3
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +8 -7
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/src/_constants/mocks/app-extended-server.mock.ts +1 -1
- package/src/_constants/mocks/app-server.mock.ts +1 -1
- package/src/_constants/mocks/socket-server.mock.ts +4 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +11 -24
- package/src/_models/control-models/port-settings.control-model.ts +27 -0
- package/src/_models/control-models/socket-presence.control-model.ts +70 -21
- package/src/_models/interfaces/index.ts +1 -1
- package/src/_modules/app-extended.index.ts +1 -1
- package/src/_modules/app.index.ts +1 -1
- package/src/_services/base/data.service.ts +8 -5
- package/src/_services/core/api.service.ts +36 -21
- package/src/_services/server/app-extended.server.ts +19 -11
- package/src/_services/server/app.server.ts +159 -110
- package/src/_services/socket/socket-server.service.ts +10 -7
- package/lib/_models/interfaces/port-settings.interface.d.ts +0 -5
- package/lib/_models/interfaces/port-settings.interface.d.ts.map +0 -1
- package/lib/_models/interfaces/port-settings.interface.js +0 -3
- package/lib/_models/interfaces/port-settings.interface.js.map +0 -1
- package/src/_models/interfaces/port-settings.interface.ts +0 -5
|
@@ -7,15 +7,13 @@ import * as Https from 'https';
|
|
|
7
7
|
import * as FileSystem from 'fs';
|
|
8
8
|
import * as BodyParser from 'body-parser';
|
|
9
9
|
|
|
10
|
-
import { Request, Response } from 'express';
|
|
11
|
-
|
|
12
10
|
import { Dynamo_Array, Dynamo_Error, dynamo_error_default, Dynamo_Log, second, wait } from '@futdevpro/fsm-dynamo';
|
|
13
11
|
|
|
14
12
|
import { DynamoNTS_SingletonService } from '../base/singleton.service';
|
|
15
13
|
import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
16
14
|
import { DynamoNTS_RoutingModule } from '../route/routing-module.service';
|
|
17
15
|
import { DynamoNTS_GlobalService } from '../core/global.service';
|
|
18
|
-
import { DynamoNTS_PortSettings } from '../../_models/
|
|
16
|
+
import { DynamoNTS_PortSettings } from '../../_models/control-models/port-settings.control-model';
|
|
19
17
|
import { DynamoNTS_CertificationSettings } from '../../_models/interfaces/certification-settings.interface';
|
|
20
18
|
import { DynamoNTS_GlobalServiceSettings } from '../../_models/interfaces/global-service-settings.interface';
|
|
21
19
|
import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
|
|
@@ -24,7 +22,6 @@ import { DynamoNTS_EndpointParams } from '../../_models/control-models/endpoint-
|
|
|
24
22
|
import { DynamoNTS_AppSystemControls } from '../../_models/control-models/app-system-controls.control-model';
|
|
25
23
|
|
|
26
24
|
|
|
27
|
-
|
|
28
25
|
/**
|
|
29
26
|
* This will be the MAIN service of our server project,
|
|
30
27
|
* follow the types and type instructions while setting up your project
|
|
@@ -198,8 +195,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
198
195
|
private _security: DynamoNTS_RouteSecurity;
|
|
199
196
|
protected get security(): DynamoNTS_RouteSecurity { return this._security; }
|
|
200
197
|
|
|
201
|
-
protected
|
|
202
|
-
protected get
|
|
198
|
+
protected _portSettings: DynamoNTS_PortSettings;
|
|
199
|
+
protected get portSettings(): DynamoNTS_PortSettings { return this._portSettings; }
|
|
203
200
|
|
|
204
201
|
private _cert?: DynamoNTS_CertificationSettings;
|
|
205
202
|
protected get cert(): DynamoNTS_CertificationSettings { return this._cert; }
|
|
@@ -214,6 +211,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
214
211
|
|
|
215
212
|
private _routingModules: DynamoNTS_RoutingModule[] = [];
|
|
216
213
|
|
|
214
|
+
defaultErrorUserMsg =
|
|
215
|
+
`We encountered a Server Error, ` +
|
|
216
|
+
`\nplease contact the responsible development team.\n` +
|
|
217
|
+
`\n(Internal Server error)`;
|
|
218
|
+
|
|
217
219
|
/**
|
|
218
220
|
* setting this value to true, enables this service debug logs
|
|
219
221
|
*/
|
|
@@ -245,7 +247,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
245
247
|
});
|
|
246
248
|
|
|
247
249
|
this.asyncConstruct(extended).catch((error: any) => {
|
|
248
|
-
Dynamo_Log.error(
|
|
250
|
+
Dynamo_Log.error(
|
|
251
|
+
`\nApplication: ${this._params.name} start failed.` +
|
|
252
|
+
`\n`, error
|
|
253
|
+
);
|
|
249
254
|
});
|
|
250
255
|
}
|
|
251
256
|
|
|
@@ -253,11 +258,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
253
258
|
if (this.logFn && this.deepLog) console.log('\nfn:. asyncConstruct');
|
|
254
259
|
try {
|
|
255
260
|
this.systemControls.app.init = true;
|
|
256
|
-
this._params = this.getAppParams();
|
|
261
|
+
this._params = this.getAppParams();
|
|
257
262
|
|
|
258
|
-
dynamo_error_default.issuerSystem = this._params.systemName;
|
|
263
|
+
dynamo_error_default.issuerSystem = this._params.systemName;
|
|
259
264
|
|
|
260
|
-
this.overrideDynamoNTSGlobalSettings?.();
|
|
265
|
+
this.overrideDynamoNTSGlobalSettings?.();
|
|
261
266
|
|
|
262
267
|
this.logSetup = dynamoNTS_globalSettings.logSetup;
|
|
263
268
|
|
|
@@ -266,7 +271,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
266
271
|
DynamoNTS_GlobalService.setParams(this.params);
|
|
267
272
|
|
|
268
273
|
if (this.getPortSettings) {
|
|
269
|
-
this.
|
|
274
|
+
this._portSettings = this.getPortSettings();
|
|
270
275
|
}
|
|
271
276
|
|
|
272
277
|
if (this.getCertificationSettings) {
|
|
@@ -321,8 +326,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
321
326
|
this.constructErrors.push(error);
|
|
322
327
|
Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
|
|
323
328
|
throw new Dynamo_Error({
|
|
329
|
+
...this._getDefaultErrorSettings(
|
|
330
|
+
'asyncConstruct',
|
|
331
|
+
error
|
|
332
|
+
),
|
|
333
|
+
|
|
324
334
|
errorCode: 'NTS-AS0-001',
|
|
325
|
-
error: error,
|
|
326
335
|
additionalContent: {
|
|
327
336
|
constructErrors: this.constructErrors,
|
|
328
337
|
systemControls: this.systemControls,
|
|
@@ -345,7 +354,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
345
354
|
if (this.constructErrors.length) {
|
|
346
355
|
Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
|
|
347
356
|
throw new Dynamo_Error({
|
|
348
|
-
|
|
357
|
+
...this._getDefaultErrorSettings(
|
|
358
|
+
'ready',
|
|
359
|
+
new Error(`${this._params.name} start failed. ERRORS`)
|
|
360
|
+
),
|
|
361
|
+
|
|
362
|
+
errorCode: 'NTS-AS0-R1',
|
|
349
363
|
additionalContent: this.constructErrors.length === 1 ? this.constructErrors[0] : { errors: this.constructErrors },
|
|
350
364
|
});
|
|
351
365
|
}
|
|
@@ -369,7 +383,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
369
383
|
if (timeout < +new Date() - start) {
|
|
370
384
|
Dynamo_Log.error(`${this._params.name} start failed. TIMEOUT`, this.constructErrors);
|
|
371
385
|
throw new Dynamo_Error({
|
|
372
|
-
|
|
386
|
+
...this._getDefaultErrorSettings(
|
|
387
|
+
'ready',
|
|
388
|
+
new Error(`${this._params.name} start failed. TIMEOUT`)
|
|
389
|
+
),
|
|
390
|
+
|
|
391
|
+
errorCode: 'NTS-AS0-R2',
|
|
373
392
|
additionalContent: {
|
|
374
393
|
constructErrors: this.constructErrors,
|
|
375
394
|
systemControls: this.systemControls,
|
|
@@ -385,7 +404,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
385
404
|
if (this.constructErrors.length) {
|
|
386
405
|
Dynamo_Log.error(`${this._params.name} start failed. ERROR`, this.constructErrors);
|
|
387
406
|
throw new Dynamo_Error({
|
|
388
|
-
|
|
407
|
+
...this._getDefaultErrorSettings(
|
|
408
|
+
'ready',
|
|
409
|
+
new Error(`${this._params.name} start failed. ERROR`)
|
|
410
|
+
),
|
|
411
|
+
|
|
412
|
+
errorCode: 'NTS-AS0-R3',
|
|
389
413
|
additionalContent: this.constructErrors,
|
|
390
414
|
});
|
|
391
415
|
}
|
|
@@ -411,8 +435,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
411
435
|
|
|
412
436
|
Dynamo_Log.error(msg, this.constructErrors);
|
|
413
437
|
throw new Dynamo_Error({
|
|
414
|
-
|
|
415
|
-
|
|
438
|
+
...this._getDefaultErrorSettings(
|
|
439
|
+
'ready',
|
|
440
|
+
new Error(msg)
|
|
441
|
+
),
|
|
442
|
+
|
|
443
|
+
errorCode: 'NTS-AS0-R4',
|
|
416
444
|
additionalContent: {
|
|
417
445
|
constructErrors: this.constructErrors,
|
|
418
446
|
systemControls: this.systemControls,
|
|
@@ -434,11 +462,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
434
462
|
|
|
435
463
|
if (this.systemControls.mongoose.init) {
|
|
436
464
|
this.systemControls.mongoose.started = false;
|
|
465
|
+
|
|
437
466
|
if (this.mongoose) {
|
|
438
467
|
await Dynamo_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
|
|
439
468
|
await this.mongoose.deleteModel(modelName);
|
|
440
469
|
});
|
|
441
470
|
await this.mongoose.disconnect();
|
|
471
|
+
|
|
442
472
|
} else {
|
|
443
473
|
Dynamo_Log.error(`\nMongoose not found.`);
|
|
444
474
|
}
|
|
@@ -490,9 +520,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
490
520
|
Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
|
|
491
521
|
reject(
|
|
492
522
|
new Dynamo_Error({
|
|
493
|
-
|
|
523
|
+
...this._getDefaultErrorSettings(
|
|
524
|
+
'startDB',
|
|
525
|
+
error
|
|
526
|
+
),
|
|
527
|
+
|
|
528
|
+
errorCode: 'NTS-AS0-SDB1',
|
|
494
529
|
message: `Unable to connect to MongoDB server, ERROR: ${error}`,
|
|
495
|
-
error: error,
|
|
496
530
|
})
|
|
497
531
|
);
|
|
498
532
|
})
|
|
@@ -519,7 +553,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
519
553
|
private async initExpresses(): Promise<void> {
|
|
520
554
|
if (this.logFn && this.deepLog) console.log('\nfn:. initExpresses');
|
|
521
555
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
522
|
-
if (!this.
|
|
556
|
+
if (!this._portSettings.httpPort) {
|
|
523
557
|
let errorMsg: string =
|
|
524
558
|
`\nYou have open routes, but httpPort is not set!` +
|
|
525
559
|
`\nsecurity: ${this._security}` +
|
|
@@ -550,7 +584,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
550
584
|
}
|
|
551
585
|
|
|
552
586
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.open) {
|
|
553
|
-
if (!this._cert || !this.
|
|
587
|
+
if (!this._cert || !this._portSettings.httpsPort) {
|
|
554
588
|
let errorMsg: string =
|
|
555
589
|
`\nYou have secure routes, but the certification paths or httpsPort are not set!` +
|
|
556
590
|
`\nsecurity: ${this._security}` +
|
|
@@ -593,8 +627,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
593
627
|
protected async initOpenExpress(): Promise<void> {
|
|
594
628
|
if (this.logFn) console.log('\nfn:. initOpenExpress');
|
|
595
629
|
this.openExpress = Express();
|
|
596
|
-
this.openExpress.use(BodyParser.urlencoded(
|
|
597
|
-
this.openExpress.use(BodyParser.json(
|
|
630
|
+
this.openExpress.use(BodyParser.urlencoded(this._portSettings.httpEncodeSettings));
|
|
631
|
+
this.openExpress.use(BodyParser.json(this._portSettings.httpJsonSettings));
|
|
598
632
|
}
|
|
599
633
|
|
|
600
634
|
/**
|
|
@@ -603,8 +637,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
603
637
|
protected async initSecureExpress(): Promise<void> {
|
|
604
638
|
if (this.logFn) console.log('\nfn:. initSecureExpress');
|
|
605
639
|
this.secureExpress = Express();
|
|
606
|
-
this.secureExpress.use(BodyParser.urlencoded(
|
|
607
|
-
this.secureExpress.use(BodyParser.json(
|
|
640
|
+
this.secureExpress.use(BodyParser.urlencoded(this._portSettings.httpsEncodeSettings));
|
|
641
|
+
this.secureExpress.use(BodyParser.json(this._portSettings.httpsJsonSettings));
|
|
608
642
|
|
|
609
643
|
const options = {
|
|
610
644
|
key: FileSystem.readFileSync(this._cert.keyPath),
|
|
@@ -623,9 +657,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
623
657
|
await new Promise<void>((resolve, reject) => {
|
|
624
658
|
this.systemControls.httpsServer.init = true;
|
|
625
659
|
this.httpsServer
|
|
626
|
-
.listen(this.
|
|
660
|
+
.listen(this._portSettings.httpsPort, 'localhost', 0, () => {
|
|
627
661
|
this.systemControls.httpsServer.started = true;
|
|
628
|
-
Dynamo_Log.success(`\nHTTPS (secure) server is listening on port: ${this.
|
|
662
|
+
Dynamo_Log.success(`\nHTTPS (secure) server is listening on port: ${this._portSettings.httpsPort}`);
|
|
629
663
|
resolve();
|
|
630
664
|
})
|
|
631
665
|
.on('error', (error) => {
|
|
@@ -634,9 +668,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
634
668
|
Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
|
|
635
669
|
reject(
|
|
636
670
|
new Dynamo_Error({
|
|
637
|
-
|
|
671
|
+
...this._getDefaultErrorSettings(
|
|
672
|
+
'startExpresses',
|
|
673
|
+
error
|
|
674
|
+
),
|
|
675
|
+
|
|
676
|
+
errorCode: 'NTS-AS0-SE1',
|
|
638
677
|
message: `HTTPS (secure) server ERROR`,
|
|
639
|
-
error: error,
|
|
640
678
|
})
|
|
641
679
|
);
|
|
642
680
|
})
|
|
@@ -644,9 +682,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
644
682
|
Dynamo_Log.warn(
|
|
645
683
|
`\nHTTPS (secure) server uncaughtException`,
|
|
646
684
|
new Dynamo_Error({
|
|
647
|
-
|
|
685
|
+
...this._getDefaultErrorSettings(
|
|
686
|
+
'startExpresses',
|
|
687
|
+
ex
|
|
688
|
+
),
|
|
689
|
+
|
|
690
|
+
errorCode: 'NTS-AS0-SE2',
|
|
648
691
|
message: `HTTPS (secure) server uncaughtException`,
|
|
649
|
-
error: ex,
|
|
650
692
|
})
|
|
651
693
|
);
|
|
652
694
|
});
|
|
@@ -657,9 +699,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
657
699
|
this.systemControls.httpServer.init = true;
|
|
658
700
|
await new Promise<void>((resolve, reject) => {
|
|
659
701
|
this.httpServer = this.openExpress
|
|
660
|
-
.listen(this.
|
|
702
|
+
.listen(this._portSettings.httpPort, () => {
|
|
661
703
|
this.systemControls.httpServer.started = true;
|
|
662
|
-
Dynamo_Log.success(`\nHTTP (open) server is listening on port: ${this.
|
|
704
|
+
Dynamo_Log.success(`\nHTTP (open) server is listening on port: ${this._portSettings.httpPort}`);
|
|
663
705
|
resolve();
|
|
664
706
|
})
|
|
665
707
|
.on('error', (error) => {
|
|
@@ -669,9 +711,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
669
711
|
Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
|
|
670
712
|
reject(
|
|
671
713
|
new Dynamo_Error({
|
|
672
|
-
|
|
714
|
+
...this._getDefaultErrorSettings(
|
|
715
|
+
'startExpresses',
|
|
716
|
+
error
|
|
717
|
+
),
|
|
718
|
+
|
|
719
|
+
errorCode: 'NTS-AS0-SE3',
|
|
673
720
|
message: `HTTP (open) server ERROR`,
|
|
674
|
-
error: error,
|
|
675
721
|
})
|
|
676
722
|
);
|
|
677
723
|
})
|
|
@@ -679,9 +725,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
679
725
|
Dynamo_Log.warn(
|
|
680
726
|
`\nHTTP (open) server uncaughtException`,
|
|
681
727
|
new Dynamo_Error({
|
|
682
|
-
|
|
728
|
+
...this._getDefaultErrorSettings(
|
|
729
|
+
'startExpresses',
|
|
730
|
+
ex
|
|
731
|
+
),
|
|
732
|
+
|
|
733
|
+
errorCode: 'NTS-AS0-SE4',
|
|
683
734
|
message: `HTTP (open) server uncaughtException`,
|
|
684
|
-
error: ex
|
|
685
735
|
})
|
|
686
736
|
);
|
|
687
737
|
});
|
|
@@ -693,11 +743,50 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
693
743
|
}
|
|
694
744
|
}
|
|
695
745
|
|
|
746
|
+
private async expressErrorHandling(err, req, res, next): Promise<void> {
|
|
747
|
+
try {
|
|
748
|
+
if (err) {
|
|
749
|
+
if (DynamoNTS_GlobalService.globalErrorHandler) {
|
|
750
|
+
Dynamo_Log.error('unhandled express ERROR (must be a parsing error...)');
|
|
751
|
+
await DynamoNTS_GlobalService.globalErrorHandler?.(err, req, res);
|
|
752
|
+
} else {
|
|
753
|
+
Dynamo_Log.error('unhandled express ERROR (must be a parsing error...)', err);
|
|
754
|
+
}
|
|
755
|
+
} else {
|
|
756
|
+
Dynamo_Log.H_error(
|
|
757
|
+
'WTF??? express error; without error?...' +
|
|
758
|
+
'\nerr:', err,
|
|
759
|
+
'\nreq:', req,
|
|
760
|
+
'\nres:', res
|
|
761
|
+
);
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
res.status(err?.status || 500);
|
|
765
|
+
res.render('error', {
|
|
766
|
+
message: err?.message,
|
|
767
|
+
});
|
|
768
|
+
res.send(err);
|
|
769
|
+
} catch (error) {
|
|
770
|
+
Dynamo_Log.H_error(
|
|
771
|
+
'MULTILEVEL ERROR (expressErrorHandling)....', error
|
|
772
|
+
);
|
|
773
|
+
|
|
774
|
+
res.status(err?.status || 500);
|
|
775
|
+
res.render('error', {
|
|
776
|
+
message: err?.message,
|
|
777
|
+
});
|
|
778
|
+
res.send(err);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
696
782
|
/**
|
|
697
783
|
*
|
|
698
784
|
*/
|
|
699
785
|
private async mountSecureRoutes (): Promise<void> {
|
|
700
786
|
if (this.logFn && this.deepLog) console.log('\nfn:. mountSecureRoutes');
|
|
787
|
+
|
|
788
|
+
this.openExpress.use(this.expressErrorHandling);
|
|
789
|
+
|
|
701
790
|
await Dynamo_Array.asyncForEach(this._routingModules, async (module: DynamoNTS_RoutingModule) => {
|
|
702
791
|
if (module.security !== DynamoNTS_RouteSecurity.open) {
|
|
703
792
|
if (this.logSetup) {
|
|
@@ -709,16 +798,20 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
709
798
|
);
|
|
710
799
|
|
|
711
800
|
if (1 < existingRoutes.length) {
|
|
712
|
-
let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
801
|
+
let error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
713
802
|
let errorStack: string[] = error.stack.split('\n');
|
|
714
803
|
errorStack.splice(1, 4);
|
|
715
804
|
error.stack = errorStack.join('\n');
|
|
716
805
|
|
|
717
806
|
Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
718
807
|
throw new Dynamo_Error({
|
|
719
|
-
|
|
808
|
+
...this._getDefaultErrorSettings(
|
|
809
|
+
'mountSecureRoutes',
|
|
810
|
+
error
|
|
811
|
+
),
|
|
812
|
+
|
|
813
|
+
errorCode: 'NTS-AS0-MSR1',
|
|
720
814
|
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
721
|
-
error: error,
|
|
722
815
|
});
|
|
723
816
|
}
|
|
724
817
|
|
|
@@ -732,6 +825,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
732
825
|
*/
|
|
733
826
|
private async mountOpenRoutes(): Promise<void> {
|
|
734
827
|
if (this.logFn && this.deepLog) console.log('\nfn:. mountOpenRoutes');
|
|
828
|
+
|
|
829
|
+
this.openExpress.use(this.expressErrorHandling);
|
|
830
|
+
|
|
735
831
|
await Dynamo_Array.asyncForEach(this._routingModules, async (module: DynamoNTS_RoutingModule) => {
|
|
736
832
|
if (module.security !== DynamoNTS_RouteSecurity.secure) {
|
|
737
833
|
if (this.logSetup) {
|
|
@@ -743,16 +839,20 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
743
839
|
);
|
|
744
840
|
|
|
745
841
|
if (1 < existingRoutes.length) {
|
|
746
|
-
let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
842
|
+
let error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
747
843
|
let errorStack: string[] = error.stack.split('\n');
|
|
748
844
|
errorStack.splice(1, 4);
|
|
749
845
|
error.stack = errorStack.join('\n');
|
|
750
846
|
|
|
751
847
|
Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
752
848
|
throw new Dynamo_Error({
|
|
753
|
-
|
|
849
|
+
...this._getDefaultErrorSettings(
|
|
850
|
+
'mountOpenRoutes',
|
|
851
|
+
error
|
|
852
|
+
),
|
|
853
|
+
|
|
854
|
+
errorCode: 'NTS-AS0-MOR1',
|
|
754
855
|
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
755
|
-
error: error,
|
|
756
856
|
});
|
|
757
857
|
}
|
|
758
858
|
|
|
@@ -769,8 +869,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
769
869
|
this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
|
|
770
870
|
if (!module.security) {
|
|
771
871
|
Dynamo_Log.warn(`RoutingModule security is not set for ${module.route}\n`);
|
|
872
|
+
|
|
772
873
|
} else if (!this._security) {
|
|
773
874
|
this._security = module.security;
|
|
875
|
+
|
|
774
876
|
} else if (this._security !== module.security) {
|
|
775
877
|
this._security = DynamoNTS_RouteSecurity.both;
|
|
776
878
|
}
|
|
@@ -788,46 +890,25 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
788
890
|
Dynamo_Log.warn(msg);
|
|
789
891
|
}
|
|
790
892
|
}
|
|
893
|
+
|
|
894
|
+
private _getDefaultErrorSettings(fnName: string, error: Error | Dynamo_Error) {
|
|
895
|
+
return {
|
|
896
|
+
status: (error as Dynamo_Error)?.___status ?? 500,
|
|
897
|
+
message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS)`,
|
|
898
|
+
addECToUserMsg: true,
|
|
899
|
+
userMessage: this.defaultErrorUserMsg,
|
|
900
|
+
issuerService: `${this?.constructor?.name}-DynamoNTS_App`,
|
|
901
|
+
error: error,
|
|
902
|
+
}
|
|
903
|
+
}
|
|
791
904
|
|
|
792
905
|
/**
|
|
793
|
-
*
|
|
794
|
-
* Setting up App params, and preparing project global settings
|
|
795
|
-
* You must setup app params in this function like this:
|
|
796
|
-
*
|
|
797
|
-
* @example
|
|
798
|
-
* setupAppParams(): void {
|
|
799
|
-
* this.params = new DynamoBEAppParams({
|
|
800
|
-
* name: 'Sample Server',
|
|
801
|
-
* title: 'A BIG nice header that will be logged on start',
|
|
802
|
-
* version: version,
|
|
803
|
-
* dbName: 'sampleapp',
|
|
804
|
-
* });
|
|
805
|
-
*
|
|
806
|
-
* DBE_Global_S.setGlobalSettings({
|
|
807
|
-
* defaultRouteSecurity: DynamoBERouteSecurity.secure,
|
|
808
|
-
* logSetup: true,
|
|
809
|
-
* });
|
|
810
|
-
* }
|
|
906
|
+
* MISSING Description (TODO)
|
|
811
907
|
*/
|
|
812
908
|
abstract getAppParams(): DynamoNTS_AppParams;
|
|
813
909
|
|
|
814
910
|
/**
|
|
815
|
-
*
|
|
816
|
-
* Setting up DBServices
|
|
817
|
-
* You must setup globalServiceCollection and dbServices in this function
|
|
818
|
-
*
|
|
819
|
-
* @example
|
|
820
|
-
* setGlobalServiceCollection(): void {
|
|
821
|
-
* DBE_Global_S.setServices({
|
|
822
|
-
* authService: AuthService.getInstance(),
|
|
823
|
-
* emailServiceCollection: EmailServiceCollectionService.getInstance(),
|
|
824
|
-
* dbModels: [
|
|
825
|
-
* accountModelParams,
|
|
826
|
-
* projectModelParams,
|
|
827
|
-
* ...
|
|
828
|
-
* ]
|
|
829
|
-
* });
|
|
830
|
-
* }
|
|
911
|
+
* MISSING Description (TODO)
|
|
831
912
|
*/
|
|
832
913
|
abstract getGlobalServiceCollection(): DynamoNTS_GlobalServiceSettings;
|
|
833
914
|
|
|
@@ -842,39 +923,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
842
923
|
overrideDynamoNTSGlobalSettings?(): void;
|
|
843
924
|
|
|
844
925
|
/**
|
|
845
|
-
*
|
|
846
|
-
* You must setup endpoints and required services in this function
|
|
847
|
-
*
|
|
848
|
-
* @example
|
|
849
|
-
* // Setting up Routes
|
|
850
|
-
* setupRoutingModules(): void {
|
|
851
|
-
* this.httpPort = env.httpPort;
|
|
852
|
-
* this.httpsPort = env.httpsPort;
|
|
853
|
-
*
|
|
854
|
-
* this.cert = {
|
|
855
|
-
* keyPath: Path.join(__dirname, './_assets/cert/ucc.key'),
|
|
856
|
-
* certPath: Path.join(__dirname, './_assets/cert/ucc.crt'),
|
|
857
|
-
* };
|
|
858
|
-
*
|
|
859
|
-
* this.routingModules = [
|
|
860
|
-
* new DynamoBERountingModule({
|
|
861
|
-
* route: '/api/account',
|
|
862
|
-
* controllers: [
|
|
863
|
-
* AccountController.getInstance(),
|
|
864
|
-
* PersonalInformationController.getInstance(),
|
|
865
|
-
* ...
|
|
866
|
-
* ]
|
|
867
|
-
* }),
|
|
868
|
-
* new DynamoBERountingModule({
|
|
869
|
-
* route: '/api/project',
|
|
870
|
-
* controllers: [
|
|
871
|
-
* ProjectController.getInstance(),
|
|
872
|
-
* ProjectExtensionController.getInstance(),
|
|
873
|
-
* ]
|
|
874
|
-
* }),
|
|
875
|
-
* ...
|
|
876
|
-
* ];
|
|
877
|
-
* }
|
|
926
|
+
* MISSING Description (TODO)
|
|
878
927
|
*/
|
|
879
928
|
getRoutingModules?(): DynamoNTS_RoutingModule[];
|
|
880
929
|
|
|
@@ -201,7 +201,10 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
201
201
|
await this.subscriptionEvent.executeEventTasks(content, issuer);
|
|
202
202
|
|
|
203
203
|
socket.emit(DynamoNTS_SocketEventKey.subscriptionSuccessful, 'subscribe was successful', error => {
|
|
204
|
-
Dynamo_Log.error(
|
|
204
|
+
Dynamo_Log.error(
|
|
205
|
+
`Emitting subscriptionSuccessful event failed!` +
|
|
206
|
+
`\nerror:`, error
|
|
207
|
+
);
|
|
205
208
|
});
|
|
206
209
|
|
|
207
210
|
Dynamo_Log.success(`<-==> socket(${this.params.name}) subscription successfull (${issuer})`);
|
|
@@ -394,9 +397,9 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
394
397
|
}
|
|
395
398
|
}
|
|
396
399
|
|
|
397
|
-
async emitError(presenceIssuerId: string, error: any): Promise<void> {
|
|
400
|
+
async emitError(presenceIssuerId: string, error: any, issuer: string): Promise<void> {
|
|
398
401
|
try {
|
|
399
|
-
await this.sendEventForId(presenceIssuerId, DynamoNTS_SocketEventKey.error, error);
|
|
402
|
+
await this.sendEventForId(presenceIssuerId, DynamoNTS_SocketEventKey.error, error, issuer);
|
|
400
403
|
} catch (error) {
|
|
401
404
|
throw new Dynamo_Error({
|
|
402
405
|
...this._getDefaultErrorSettings(
|
|
@@ -411,7 +414,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
411
414
|
}
|
|
412
415
|
}
|
|
413
416
|
|
|
414
|
-
async sendEventForId(id: string, event: string, content: any
|
|
417
|
+
async sendEventForId(id: string, event: string, content: any, issuer: string): Promise<void> {
|
|
415
418
|
try {
|
|
416
419
|
const presence: DynamoNTS_SocketPresence = this.presences.find((pres: DynamoNTS_SocketPresence) => pres.issuerId === id);
|
|
417
420
|
|
|
@@ -428,7 +431,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
428
431
|
});
|
|
429
432
|
}
|
|
430
433
|
|
|
431
|
-
presence.emitEvent(event, content);
|
|
434
|
+
presence.emitEvent(event, content, issuer);
|
|
432
435
|
|
|
433
436
|
if (dynamoNTS_globalSettings.logSocketEventContent) {
|
|
434
437
|
Dynamo_Log.success(` <--= emitted socket(${this.params.name}) event for presence: ${event}, presenceId: ${id}) \ncontent:`, content);
|
|
@@ -478,12 +481,12 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
478
481
|
}
|
|
479
482
|
}
|
|
480
483
|
|
|
481
|
-
broadcastEvent(event: string, content: any): void {
|
|
484
|
+
broadcastEvent(event: string, content: any, issuer: string): void {
|
|
482
485
|
try {
|
|
483
486
|
Dynamo_Log.log(` <=-== broadcasting socket(${this.params.name}) event: ${event}`);
|
|
484
487
|
|
|
485
488
|
this.presences.forEach((presence: DynamoNTS_SocketPresence) => {
|
|
486
|
-
presence.emitEvent(event, content);
|
|
489
|
+
presence.emitEvent(event, content, issuer);
|
|
487
490
|
});
|
|
488
491
|
} catch (error) {
|
|
489
492
|
Dynamo_Log.error(`socket(${this.params.name}) Event Broadcast (${event}) failed`, error);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"port-settings.interface.d.ts","sourceRoot":"","sources":["../../../src/_models/interfaces/port-settings.interface.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"port-settings.interface.js","sourceRoot":"","sources":["../../../src/_models/interfaces/port-settings.interface.ts"],"names":[],"mappings":""}
|