@futdevpro/nts-dynamo 1.6.19 → 1.6.21

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.
Files changed (88) hide show
  1. package/lib/_constants/mocks/app-extended-server.mock.d.ts +41 -0
  2. package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -0
  3. package/lib/_constants/mocks/app-extended-server.mock.js +168 -0
  4. package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -0
  5. package/lib/_constants/mocks/app-server.mock.d.ts +1 -1
  6. package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
  7. package/lib/_constants/mocks/app-server.mock.js +12 -5
  8. package/lib/_constants/mocks/app-server.mock.js.map +1 -1
  9. package/lib/_constants/mocks/data-model.mock.d.ts +27 -0
  10. package/lib/_constants/mocks/data-model.mock.d.ts.map +1 -0
  11. package/lib/_constants/mocks/data-model.mock.js +57 -0
  12. package/lib/_constants/mocks/data-model.mock.js.map +1 -0
  13. package/lib/_constants/mocks/email-service-collection.mock.d.ts +7 -0
  14. package/lib/_constants/mocks/email-service-collection.mock.d.ts.map +1 -0
  15. package/lib/_constants/mocks/email-service-collection.mock.js +16 -0
  16. package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -0
  17. package/lib/_constants/mocks/email-service.mock.d.ts +5 -0
  18. package/lib/_constants/mocks/email-service.mock.d.ts.map +1 -0
  19. package/lib/_constants/mocks/email-service.mock.js +21 -0
  20. package/lib/_constants/mocks/email-service.mock.js.map +1 -0
  21. package/lib/_constants/mocks/socket-client.mock.d.ts +9 -0
  22. package/lib/_constants/mocks/socket-client.mock.d.ts.map +1 -0
  23. package/lib/_constants/mocks/socket-client.mock.js +39 -0
  24. package/lib/_constants/mocks/socket-client.mock.js.map +1 -0
  25. package/lib/_constants/mocks/socket-server.mock.d.ts +1 -0
  26. package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
  27. package/lib/_constants/mocks/socket-server.mock.js +4 -1
  28. package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
  29. package/lib/_models/control-models/app-system-controls.control-model copy.d.ts +7 -0
  30. package/lib/_models/control-models/app-system-controls.control-model copy.d.ts.map +1 -0
  31. package/lib/_models/control-models/app-system-controls.control-model copy.js +13 -0
  32. package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -0
  33. package/lib/_models/control-models/app-system-controls.control-model.d.ts +8 -0
  34. package/lib/_models/control-models/app-system-controls.control-model.d.ts.map +1 -0
  35. package/lib/_models/control-models/app-system-controls.control-model.js +14 -0
  36. package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -0
  37. package/lib/_models/control-models/system-control.control-model.d.ts +6 -0
  38. package/lib/_models/control-models/system-control.control-model.d.ts.map +1 -0
  39. package/lib/_models/control-models/system-control.control-model.js +15 -0
  40. package/lib/_models/control-models/system-control.control-model.js.map +1 -0
  41. package/lib/_services/base/db.service.d.ts +1 -2
  42. package/lib/_services/base/db.service.d.ts.map +1 -1
  43. package/lib/_services/base/db.service.js +23 -15
  44. package/lib/_services/base/db.service.js.map +1 -1
  45. package/lib/_services/core/email.service.d.ts.map +1 -1
  46. package/lib/_services/core/email.service.js +0 -1
  47. package/lib/_services/core/email.service.js.map +1 -1
  48. package/lib/_services/server/app-extended.server.d.ts +9 -0
  49. package/lib/_services/server/app-extended.server.d.ts.map +1 -1
  50. package/lib/_services/server/app-extended.server.js +228 -81
  51. package/lib/_services/server/app-extended.server.js.map +1 -1
  52. package/lib/_services/server/app-extended.server.spec.d.ts +2 -0
  53. package/lib/_services/server/app-extended.server.spec.d.ts.map +1 -0
  54. package/lib/_services/server/app-extended.server.spec.js +55 -0
  55. package/lib/_services/server/app-extended.server.spec.js.map +1 -0
  56. package/lib/_services/server/app.server.d.ts +17 -17
  57. package/lib/_services/server/app.server.d.ts.map +1 -1
  58. package/lib/_services/server/app.server.js +382 -258
  59. package/lib/_services/server/app.server.js.map +1 -1
  60. package/lib/_services/server/app.server.spec.js +17 -5
  61. package/lib/_services/server/app.server.spec.js.map +1 -1
  62. package/lib/_services/shared.service.spec.js +7 -1
  63. package/lib/_services/shared.service.spec.js.map +1 -1
  64. package/lib/_services/socket/socket-server.service.d.ts +5 -3
  65. package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
  66. package/lib/_services/socket/socket-server.service.js +32 -7
  67. package/lib/_services/socket/socket-server.service.js.map +1 -1
  68. package/lib/tsconfig.tsbuildinfo +1 -1
  69. package/package.json +2 -2
  70. package/src/_constants/mocks/app-extended-server.mock.ts +191 -0
  71. package/src/_constants/mocks/app-server.mock.ts +10 -5
  72. package/src/_constants/mocks/data-model.mock.ts +83 -0
  73. package/src/_constants/mocks/email-service-collection.mock.ts +12 -0
  74. package/src/_constants/mocks/email-service.mock.ts +19 -0
  75. package/src/_constants/mocks/email-template.mock.html +15 -0
  76. package/src/_constants/mocks/socket-client.mock.ts +42 -0
  77. package/src/_constants/mocks/socket-server.mock.ts +5 -1
  78. package/src/_models/control-models/app-system-controls.control-model copy.ts +9 -0
  79. package/src/_models/control-models/app-system-controls.control-model.ts +9 -0
  80. package/src/_models/control-models/system-control.control-model.ts +13 -0
  81. package/src/_services/base/db.service.ts +25 -15
  82. package/src/_services/core/email.service.ts +0 -1
  83. package/src/_services/server/app-extended.server.spec.ts +66 -0
  84. package/src/_services/server/app-extended.server.ts +205 -41
  85. package/src/_services/server/app.server.spec.ts +17 -7
  86. package/src/_services/server/app.server.ts +284 -165
  87. package/src/_services/shared.service.spec.ts +10 -1
  88. package/src/_services/socket/socket-server.service.ts +36 -12
@@ -6,7 +6,7 @@ import * as Https from 'https';
6
6
  import * as FileSystem from 'fs';
7
7
  import * as BodyParser from 'body-parser';
8
8
 
9
- import { delay, Dynamo_Array, Dynamo_Error, Dynamo_Log, second } from '@futdevpro/fsm-dynamo';
9
+ import { delay, Dynamo_Array, Dynamo_Error, Dynamo_Log, second, wait } from '@futdevpro/fsm-dynamo';
10
10
 
11
11
  import { DynamoNTS_SingletonService } from '../base/singleton.service';
12
12
  import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
@@ -18,6 +18,10 @@ import { DynamoNTS_GlobalServiceSettings } from '../../_models/interfaces/global
18
18
  import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
19
19
  import { DynamoNTS_AppParams } from '../../_models/control-models/app-params.control-model';
20
20
  import { DynamoNTS_EndpointParams } from '../../_models/control-models/endpoint-params.control-model';
21
+ import { DynamoNTS_SystemControl } from '../../_models/control-models/system-control.control-model';
22
+ import { DynamoNTS_AppSystemControls } from '../../_models/control-models/app-system-controls.control-model';
23
+
24
+
21
25
 
22
26
  /**
23
27
  * This will be the MAIN service of our server project,
@@ -177,15 +181,10 @@ import { DynamoNTS_EndpointParams } from '../../_models/control-models/endpoint-
177
181
  */
178
182
  export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
179
183
 
180
- started: boolean = false;
181
- private initDone: boolean = false;
182
- private haveMongoose: boolean = false;
183
- private mongooseStarted: boolean = false;
184
- private haveHttpServer: boolean = false;
185
- private httpServerStarted: boolean = false;
186
- private haveHttpsServer: boolean = false;
187
- private httpsServerStarted: boolean = false;
188
- private constructErrors: (Error | Dynamo_Error)[] = [];
184
+ protected systemControls: DynamoNTS_AppSystemControls = new DynamoNTS_AppSystemControls();
185
+ get started(): boolean { return this.systemControls.app.started; }
186
+ protected get superStarted(): boolean { return this.systemControls.app.started; }
187
+ protected constructErrors: (Error | Dynamo_Error)[] = [];
189
188
 
190
189
  get serverName(): string { return this.params.name; }
191
190
 
@@ -218,14 +217,24 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
218
217
  /**
219
218
  * setting this value to true, enables this service debug logs
220
219
  */
221
- protected debugLog: boolean;
220
+ protected logSetup: boolean;
221
+ protected deepLog: boolean;
222
+ protected logFn: boolean;
222
223
 
223
- constructor(){
224
+ constructor(extended?: boolean){
224
225
  super();
225
226
 
227
+ this.asyncConstruct(extended);
228
+ }
229
+
230
+ private async asyncConstruct(extended?: boolean): Promise<void> {
231
+ if (this.logFn && this.deepLog) console.log('\nfn:. asyncConstruct');
226
232
  try {
233
+ this.systemControls.app.init = true;
234
+ this.logSetup = dynamoNTS_globalSettings.logSetup;
227
235
  this._params = this.getAppParams();
228
236
 
237
+
229
238
  if (this.overrideDynamoNTSGlobalSettings) {
230
239
  this.overrideDynamoNTSGlobalSettings();
231
240
  }
@@ -235,7 +244,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
235
244
  DynamoNTS_GlobalService.setParams(this.params);
236
245
 
237
246
  if (this.getPortSettings) {
238
- this._ports = this.getPortSettings();
247
+ this._ports = this.getPortSettings();
239
248
  }
240
249
 
241
250
  if (this.getCertificationSettings) {
@@ -247,7 +256,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
247
256
  }
248
257
 
249
258
  if (this.createEntries) {
250
- this.createEntries();
259
+ await this.createEntries();
251
260
  }
252
261
 
253
262
  console.log(`\n\n\nStarting ${this._params.name}... `);
@@ -256,166 +265,223 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
256
265
  }
257
266
  console.log(`Version: ${this._params.version}\n`);
258
267
 
259
- this.startDB();
260
-
261
- this.getGlobalServiceCollection();
262
- this.debugLog = dynamoNTS_globalSettings.logSetup;
268
+ await this.startDB();
263
269
 
264
270
  this.setSecurity();
265
271
 
266
272
  if (this._routingModules?.length) {
267
- this.initExpresses();
268
- this.startExpresses();
273
+ await this.initExpresses();
274
+ await this.startExpresses();
269
275
 
270
276
  if (this._security !== DynamoNTS_RouteSecurity.secure) {
271
- this.mountOpenRoutes();
277
+ await this.mountOpenRoutes();
272
278
  }
273
279
  if (this._security !== DynamoNTS_RouteSecurity.open && this._cert) {
274
- this.mountSecureRoutes();
280
+ await this.mountSecureRoutes();
275
281
  }
276
282
 
277
- if (this.debugLog) {
283
+ if (this.logSetup) {
278
284
  console.log(`\nRoutes mounted.... server using security: ${this._security}`);
279
285
  }
280
286
  }
281
287
 
282
288
  if (this.getRootServices) {
283
- this._rootServices = this.getRootServices();
289
+ this._rootServices = await this.getRootServices();
284
290
  }
285
291
 
286
292
  if (this.postProcess) {
287
- this.postProcess();
293
+ await this.postProcess();
288
294
  }
289
295
 
290
- this.initDone = true;
291
- this.ready();
296
+
297
+ if (!extended) {
298
+ await this.ready();
299
+
300
+ Dynamo_Log.test(`${this._params.name} started successfully.`);
301
+ }
292
302
  } catch (error) {
293
303
  this.constructErrors.push(error);
294
- Dynamo_Log.error('\nApplication start failed.\n', error);
304
+ Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
295
305
  }
296
306
  }
297
307
 
298
308
  async ready(timeout: number = 4 * second): Promise<void> {
299
- return new Promise(async (resolve, reject) => {
300
- let ready: boolean = false;
301
- const start: number = +new Date();
302
-
303
- if (this.constructErrors.length) {
304
- reject({
305
- message: 'Application start failed. TIMEOUT',
306
- errors: this.constructErrors
307
- });
308
- }
309
-
310
- while (!ready && +new Date() - start < timeout) {
311
- await delay(100);
309
+ if (this.logFn) console.log('\nfn:. ready');
310
+ let ready: boolean = false;
311
+ const start: number = +new Date();
312
+
313
+ if (this.constructErrors.length) {
314
+ Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
315
+ throw new Dynamo_Error({
316
+ message: `${this._params.name} start failed. ERRORS`,
317
+ additionalContent: this.constructErrors.length === 1 ? this.constructErrors[0] : { errors: this.constructErrors },
318
+ });
319
+ }
312
320
 
313
- if (this.initDone) {
314
- ready = (
315
- this.haveMongoose ? this.mongooseStarted : true &&
316
- this.haveHttpServer ? this.httpServerStarted : true &&
317
- this.haveHttpsServer ? this.httpsServerStarted : true
318
- );
319
- }
321
+ while (!ready && +new Date() - start < timeout) {
322
+ if (this.systemControls.app.init) {
323
+ ready = (
324
+ this.systemControls.mongoose.getReady() &&
325
+ this.systemControls.httpServer.getReady() &&
326
+ this.systemControls.httpsServer.getReady()
327
+ );
320
328
  }
321
329
 
322
- if (this.constructErrors.length) {
323
- reject({
324
- message: 'Application start failed. TIMEOUT',
325
- errors: this.constructErrors
326
- });
327
- }
330
+ await wait(100);
331
+ }
328
332
 
329
- if (ready) {
330
- this.started = true;
331
-
332
- resolve();
333
- } else {
334
- this.started = false;
335
-
336
- let msg: string = 'Application start failed. TIMEOUT';
337
- if (this.haveMongoose && !this.mongooseStarted) {
338
- msg += '\nMongoose start failed.';
339
- }
340
- if (this.haveHttpServer && !this.httpServerStarted) {
341
- msg += '\nHTTP Server start failed.';
342
- }
343
- if (this.haveHttpsServer && !this.httpsServerStarted) {
344
- msg += '\nHTTPS Server start failed.';
345
- }
333
+ if (timeout < +new Date() - start) {
334
+ Dynamo_Log.error(`${this._params.name} start failed. TIMEOUT`, this.constructErrors);
335
+ throw new Dynamo_Error({
336
+ message: `${this._params.name} start failed. TIMEOUT`,
337
+ additionalContent: {
338
+ constructErrors: this.constructErrors,
339
+ systemControls: this.systemControls,
340
+ systemReadies: {
341
+ mongoose: this.systemControls.mongoose.getReady(),
342
+ httpServer: this.systemControls.httpServer.getReady(),
343
+ httpsServer: this.systemControls.httpsServer.getReady(),
344
+ },
345
+ },
346
+ });
347
+ }
346
348
 
347
-
349
+ if (this.constructErrors.length) {
350
+ Dynamo_Log.error(`${this._params.name} start failed. ERROR`, this.constructErrors);
351
+ throw new Dynamo_Error({
352
+ message: `${this._params.name} start failed. ERROR`,
353
+ additionalContent: this.constructErrors,
354
+ });
355
+ }
348
356
 
349
- reject({
350
- message: 'Application start failed. TIMEOUT',
351
- errors: this.constructErrors
352
- });
357
+ if (ready) {
358
+ this.systemControls.app.started = true;
359
+
360
+ if (this.logFn && this.deepLog) console.log('\nfn:. ready: return');
361
+ return;
362
+ } else {
363
+ this.systemControls.app.started = false;
364
+
365
+ let msg: string = `${this._params.name} start failed. UNKNOWN`;
366
+ if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
367
+ msg += `\nMongoose start failed.`;
353
368
  }
354
- });
369
+ if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
370
+ msg += `\nHTTP Server start failed.`;
371
+ }
372
+ if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
373
+ msg += `\nHTTPS Server start failed.`;
374
+ }
375
+
376
+ Dynamo_Log.error(msg, this.constructErrors);
377
+ throw new Dynamo_Error({
378
+ errorCode: 'NTS-AS0-110',
379
+ message: msg,
380
+ additionalContent: {
381
+ constructErrors: this.constructErrors,
382
+ systemControls: this.systemControls,
383
+ systemReadies: {
384
+ app: this.systemControls.app.getReady(),
385
+ mongoose: this.systemControls.mongoose.getReady(),
386
+ httpServer: this.systemControls.httpServer.getReady(),
387
+ httpsServer: this.systemControls.httpsServer.getReady(),
388
+ },
389
+ },
390
+ error: this.constructErrors?.[0] ?? new Error(),
391
+ });
392
+ }
355
393
  }
356
394
 
357
- async stop(): Promise<void> {
395
+ async stop(dontLog?: boolean): Promise<void> {
396
+ if (this.logFn) console.log('\nfn:. stop');
358
397
  if (this.started) {
359
398
 
360
- if (this.haveHttpServer) {
361
- await new Promise((resolve) => {
362
- this.httpServer.close(resolve);
363
- });
399
+ if (this.systemControls.mongoose.init) {
400
+ this.systemControls.mongoose.started = false;
401
+ if (this.mongoose) {
402
+ await Dynamo_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
403
+ await this.mongoose.deleteModel(modelName);
404
+ });
405
+ await this.mongoose.disconnect();
406
+ } else {
407
+ Dynamo_Log.error(`\nMongoose not found.`);
408
+ }
409
+ this.systemControls.mongoose.init = false;
364
410
  }
365
- if (this.haveHttpsServer) {
366
- await new Promise((resolve) => {
367
- this.httpsServer.close(resolve);
368
- });
411
+
412
+ if (this.systemControls.httpServer.init) {
413
+ this.systemControls.httpServer.started = false;
414
+ if (this.httpServer) {
415
+ await new Promise((resolve) => {
416
+ this.httpServer.close(resolve);
417
+ });
418
+ } else {
419
+ Dynamo_Log.error(`\nHTTP Server not found.`);
420
+ }
421
+ this.systemControls.httpServer.init = false;
369
422
  }
370
- if (this.haveMongoose) {
371
- await Dynamo_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
372
- await this.mongoose.deleteModel(modelName);
373
- });
374
- await this.mongoose.disconnect();
423
+
424
+ if (this.systemControls.httpsServer.init) {
425
+ this.systemControls.httpsServer.started = false;
426
+ if (this.httpsServer) {
427
+ await new Promise((resolve) => {
428
+ this.httpsServer.close(resolve);
429
+ });
430
+ } else {
431
+ Dynamo_Log.error(`\nHTTPS Server not found.`);
432
+ }
433
+ this.systemControls.httpsServer.init = false;
434
+ }
435
+
436
+ if (!dontLog) {
437
+ Dynamo_Log.test(`${this._params.name} stopped successfully.`);
375
438
  }
376
-
377
- this.initDone = false;
378
- this.haveHttpServer = false;
379
- this.haveHttpsServer = false;
380
- this.haveMongoose = false;
381
- this.mongooseStarted = false;
382
- this.httpServerStarted = false;
383
- this.httpsServerStarted = false;
384
- this.started = false;
385
-
386
- Dynamo_Log.success('\nServer stopped.\n');
387
439
  }
388
440
  }
389
441
 
390
442
  /**
391
443
  *
392
444
  */
393
- private startDB(): void {
394
- this.haveMongoose = true;
395
- this.mongoose.connection
396
- .on('error', (error) => {
397
- this.mongooseStarted = false;
398
- this.constructErrors.push(error);
399
- Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
400
- })
401
- .once('open', () => {
402
- this.mongooseStarted = true;
403
- Dynamo_Log.success('\nConnected to MongoDB\n');
404
- });
445
+ private async startDB(): Promise<void> {
446
+ if (this.logFn && this.deepLog) console.log('\nfn:. startDB');
447
+ await new Promise<void>(
448
+ async (resolve, reject) => {
449
+ this.systemControls.mongoose.init = true;
450
+ this.mongoose.connection
451
+ .on('error', (error) => {
452
+ this.systemControls.mongoose.started = false;
453
+ this.constructErrors.push(error);
454
+ Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
455
+ reject(
456
+ new Dynamo_Error({
457
+ errorCode: 'NTS-AS0-100',
458
+ message: `Unable to connect to MongoDB server, ERROR: ${error}`,
459
+ error: error,
460
+ })
461
+ );
462
+ })
463
+ .once('open', () => {
464
+ this.systemControls.mongoose.started = true;
465
+ Dynamo_Log.success('\nConnected to MongoDB\n');
466
+ resolve();
467
+ });
405
468
 
406
- this.mongoose.connect(
407
- this._params.dbUri,
408
- {
409
- useNewUrlParser: true,
410
- useUnifiedTopology: true
411
- }
469
+ this.mongoose.connect(
470
+ this._params.dbUri,
471
+ {
472
+ useNewUrlParser: true,
473
+ useUnifiedTopology: true
474
+ }
475
+ );
476
+ }
412
477
  );
413
478
  }
414
479
 
415
480
  /**
416
481
  *
417
482
  */
418
- private initExpresses() {
483
+ private async initExpresses(): Promise<void> {
484
+ if (this.logFn && this.deepLog) console.log('\nfn:. initExpresses');
419
485
  if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
420
486
  if (!this._ports.httpPort) {
421
487
  let errorMsg: string =
@@ -444,7 +510,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
444
510
  throw error;
445
511
  }
446
512
 
447
- this.initOpenExpress();
513
+ await this.initOpenExpress();
448
514
  }
449
515
 
450
516
  if (this._security && this._security !== DynamoNTS_RouteSecurity.open) {
@@ -481,14 +547,15 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
481
547
  throw error;
482
548
  }
483
549
 
484
- this.initSecureExpress();
550
+ await this.initSecureExpress();
485
551
  }
486
552
  }
487
553
 
488
554
  /**
489
555
  *
490
556
  */
491
- protected initOpenExpress(): void {
557
+ protected async initOpenExpress(): Promise<void> {
558
+ if (this.logFn) console.log('\nfn:. initOpenExpress');
492
559
  this.openExpress = Express();
493
560
  this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
494
561
  this.openExpress.use(BodyParser.json({ limit: '50mb' }));
@@ -497,7 +564,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
497
564
  /**
498
565
  *
499
566
  */
500
- protected initSecureExpress(): void {
567
+ protected async initSecureExpress(): Promise<void> {
568
+ if (this.logFn) console.log('\nfn:. initSecureExpress');
501
569
  this.secureExpress = Express();
502
570
  this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
503
571
  this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
@@ -513,39 +581,75 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
513
581
  *
514
582
  */
515
583
  private async startExpresses(): Promise<void> {
584
+ if (this.logFn && this.deepLog) console.log('\nfn:. startExpresses');
516
585
  try {
517
586
  if (this._security && this._security !== DynamoNTS_RouteSecurity.open) {
518
- this.haveHttpsServer = true;
519
- this.httpsServer
520
- .listen(this._ports.httpsPort, 'localhost', 0, () => {
521
- this.httpsServerStarted = true;
522
- Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this._ports.httpsPort}`);
523
- })
524
- .on('error', (error) => {
525
- this.httpsServerStarted = false;
526
- this.constructErrors.push(error);
527
- Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
528
- })
529
- .on('uncaughtException', (ex) => {
530
- Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, ex);
531
- });
587
+ await new Promise<void>((resolve, reject) => {
588
+ this.systemControls.httpsServer.init = true;
589
+ this.httpsServer
590
+ .listen(this._ports.httpsPort, 'localhost', 0, () => {
591
+ this.systemControls.httpsServer.started = true;
592
+ Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this._ports.httpsPort}`);
593
+ resolve();
594
+ })
595
+ .on('error', (error) => {
596
+ this.systemControls.httpsServer.started = false;
597
+ this.constructErrors.push(error);
598
+ Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
599
+ reject(
600
+ new Dynamo_Error({
601
+ errorCode: 'NTS-AS0-001',
602
+ message: `HTTPS (secure) server ERROR`,
603
+ error: error,
604
+ })
605
+ );
606
+ })
607
+ .on('uncaughtException', (ex) => {
608
+ Dynamo_Log.warn(
609
+ `\nHTTPS (secure) server uncaughtException`,
610
+ new Dynamo_Error({
611
+ errorCode: 'NTS-AS0-002',
612
+ message: `HTTPS (secure) server uncaughtException`,
613
+ error: ex,
614
+ })
615
+ );
616
+ });
617
+ });
532
618
  }
533
619
 
534
620
  if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
535
- this.haveHttpServer = true;
536
- this.httpServer = this.openExpress
537
- .listen(this._ports.httpPort, () => {
538
- this.httpServerStarted = true;
539
- Dynamo_Log.success(`\nHTTP (-open-) server is listening on port ${this._ports.httpPort}`);
540
- })
541
- .on('error', (error) => {
542
- this.httpServerStarted = false;
543
- this.constructErrors.push(error);
544
- Dynamo_Log.error(`\nHTTP (-open-) server ERROR`, error);
545
- })
546
- .on('uncaughtException', (ex) => {
547
- Dynamo_Log.warn(`\nHTTP (-open-) server uncaughtException`, ex);
548
- });
621
+ this.systemControls.httpServer.init = true;
622
+ await new Promise<void>((resolve, reject) => {
623
+ this.httpServer = this.openExpress
624
+ .listen(this._ports.httpPort, () => {
625
+ this.systemControls.httpServer.started = true;
626
+ Dynamo_Log.success(`\nHTTP (open) server is listening on port ${this._ports.httpPort}`);
627
+ resolve();
628
+ })
629
+ .on('error', (error) => {
630
+ this.systemControls.httpServer.started = false;
631
+ this.constructErrors.push(error);
632
+
633
+ Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
634
+ reject(
635
+ new Dynamo_Error({
636
+ errorCode: 'NTS-AS0-003',
637
+ message: `HTTP (open) server ERROR`,
638
+ error: error,
639
+ })
640
+ );
641
+ })
642
+ .on('uncaughtException', (ex) => {
643
+ Dynamo_Log.warn(
644
+ `\nHTTP (open) server uncaughtException`,
645
+ new Dynamo_Error({
646
+ errorCode: 'NTS-AS0-004',
647
+ message: `HTTP (open) server uncaughtException`,
648
+ error: ex
649
+ })
650
+ );
651
+ });
652
+ });
549
653
  }
550
654
  } catch (error) {
551
655
  Dynamo_Log.error(`startExpresses failed...`, error);
@@ -555,10 +659,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
555
659
  /**
556
660
  *
557
661
  */
558
- private mountSecureRoutes (): void {
559
- this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
662
+ private async mountSecureRoutes (): Promise<void> {
663
+ if (this.logFn && this.deepLog) console.log('\nfn:. mountSecureRoutes');
664
+ await Dynamo_Array.asyncForEach(this._routingModules, async (module: DynamoNTS_RoutingModule) => {
560
665
  if (module.security !== DynamoNTS_RouteSecurity.open) {
561
- if (this.debugLog) {
666
+ if (this.logSetup) {
562
667
  console.log(`route mount (secure): ${module.route}`);
563
668
  }
564
669
 
@@ -572,8 +677,14 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
572
677
  errorStack.splice(1, 4);
573
678
  error.stack = errorStack.join('\n');
574
679
 
575
- throw error;
680
+ Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
681
+ throw new Dynamo_Error({
682
+ errorCode: 'NTS-AS0-005',
683
+ message: `ROUTE DUPLICATION: ${module.route}`,
684
+ error: error,
685
+ });
576
686
  }
687
+
577
688
  this.secureExpress.use(module.route, module.secureRouter);
578
689
  }
579
690
  });
@@ -582,10 +693,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
582
693
  /**
583
694
  *
584
695
  */
585
- private mountOpenRoutes (): void {
586
- this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
696
+ private async mountOpenRoutes(): Promise<void> {
697
+ if (this.logFn && this.deepLog) console.log('\nfn:. mountOpenRoutes');
698
+ await Dynamo_Array.asyncForEach(this._routingModules, async (module: DynamoNTS_RoutingModule) => {
587
699
  if (module.security !== DynamoNTS_RouteSecurity.secure) {
588
- if (this.debugLog) {
700
+ if (this.logSetup) {
589
701
  console.log(`route mount (open): ${module.route}`);
590
702
  }
591
703
 
@@ -599,8 +711,14 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
599
711
  errorStack.splice(1, 4);
600
712
  error.stack = errorStack.join('\n');
601
713
 
602
- throw error;
714
+ Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
715
+ throw new Dynamo_Error({
716
+ errorCode: 'NTS-AS0-006',
717
+ message: `ROUTE DUPLICATION: ${module.route}`,
718
+ error: error,
719
+ });
603
720
  }
721
+
604
722
  this.openExpress.use(module.route, module.openRouter);
605
723
  }
606
724
  });
@@ -610,6 +728,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
610
728
  *
611
729
  */
612
730
  private setSecurity(): void {
731
+ if (this.logFn && this.deepLog) console.log('\nfn:. setSecurity');
613
732
  this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
614
733
  if (!module.security) {
615
734
  Dynamo_Log.error(`RoutingModule security is not set for ${module.route}\n`);
@@ -627,7 +746,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
627
746
  msg += `\n ${module.route} (security: ${module.security})`;
628
747
  });
629
748
  if (this._routingModules.length === 0) {
630
- msg += '\n No RoutingModules found!';
749
+ msg += '\n - no RoutingModule found -\n';
631
750
  }
632
751
  Dynamo_Log.warn(msg);
633
752
  }
@@ -725,7 +844,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
725
844
  /**
726
845
  * MISSING Description (TODO)
727
846
  */
728
- getRootServices?(): DynamoNTS_SingletonService[];
847
+ getRootServices?(): Promise<DynamoNTS_SingletonService[]>;
729
848
 
730
849
  /**
731
850
  * MISSING Description (TODO)
@@ -735,10 +854,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
735
854
  /**
736
855
  * MISSING Description (TODO)
737
856
  */
738
- createEntries?(): void;
857
+ createEntries?(): Promise<void>;
739
858
 
740
859
  /**
741
860
  * MISSING Description (TODO)
742
861
  */
743
- postProcess?(): void;
862
+ postProcess?(): Promise<void>;
744
863
  }
@@ -1,10 +1,19 @@
1
1
  import { DynamoNTS_Shared } from './shared.static-service';
2
2
 
3
3
  describe('DynamoNTS_Shared', () => {
4
- it('fns should be accessible', () => {
4
+ it('getIpFromRequest should be accessible', () => {
5
5
  expect(DynamoNTS_Shared.getIpFromRequest).toBeTruthy();
6
+ });
7
+
8
+ it('getIpFromRequest should be accessible', () => {
6
9
  expect(DynamoNTS_Shared.getLocationDataByRequest).toBeTruthy();
10
+ });
11
+
12
+ it('getIpFromRequest should be accessible', () => {
7
13
  expect(DynamoNTS_Shared.getLocationByIp).toBeTruthy();
14
+ });
15
+
16
+ it('getIpFromRequest should be accessible', () => {
8
17
  expect(DynamoNTS_Shared.prompt).toBeTruthy();
9
18
  });
10
19
  });