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