@futdevpro/nts-dynamo 1.6.19 → 1.6.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_constants/mocks/app-extended-server.mock.d.ts +29 -0
- package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/app-extended-server.mock.js +99 -0
- package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -0
- 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/app-server.mock.js +9 -5
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.d.ts +1 -0
- 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/app-system-controls.control-model copy.d.ts +7 -0
- package/lib/_models/control-models/app-system-controls.control-model copy.d.ts.map +1 -0
- package/lib/_models/control-models/app-system-controls.control-model copy.js +13 -0
- package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -0
- package/lib/_models/control-models/app-system-controls.control-model.d.ts +8 -0
- package/lib/_models/control-models/app-system-controls.control-model.d.ts.map +1 -0
- package/lib/_models/control-models/app-system-controls.control-model.js +14 -0
- package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -0
- package/lib/_models/control-models/system-control.control-model.d.ts +6 -0
- package/lib/_models/control-models/system-control.control-model.d.ts.map +1 -0
- package/lib/_models/control-models/system-control.control-model.js +15 -0
- package/lib/_models/control-models/system-control.control-model.js.map +1 -0
- package/lib/_services/base/db.service.d.ts +1 -2
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +23 -15
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.d.ts +9 -0
- package/lib/_services/server/app-extended.server.d.ts.map +1 -1
- package/lib/_services/server/app-extended.server.js +230 -81
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app-extended.server.spec.d.ts +2 -0
- package/lib/_services/server/app-extended.server.spec.d.ts.map +1 -0
- package/lib/_services/server/app-extended.server.spec.js +39 -0
- package/lib/_services/server/app-extended.server.spec.js.map +1 -0
- package/lib/_services/server/app.server.d.ts +17 -17
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +401 -275
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/server/app.server.spec.js +17 -5
- package/lib/_services/server/app.server.spec.js.map +1 -1
- package/lib/_services/shared.service.spec.js +7 -1
- package/lib/_services/shared.service.spec.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +5 -3
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +32 -7
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/_constants/mocks/app-extended-server.mock.ts +113 -0
- package/src/_constants/mocks/app-server.mock.ts +7 -5
- package/src/_constants/mocks/socket-server.mock.ts +5 -1
- package/src/_models/control-models/app-system-controls.control-model copy.ts +9 -0
- package/src/_models/control-models/app-system-controls.control-model.ts +9 -0
- package/src/_models/control-models/system-control.control-model.ts +13 -0
- package/src/_services/base/db.service.ts +25 -15
- package/src/_services/server/app-extended.server.spec.ts +45 -0
- package/src/_services/server/app-extended.server.ts +208 -41
- package/src/_services/server/app.server.spec.ts +17 -7
- package/src/_services/server/app.server.ts +277 -167
- package/src/_services/shared.service.spec.ts +10 -1
- package/src/_services/socket/socket-server.service.ts +36 -11
|
@@ -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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
|
220
|
+
protected logSetup: boolean;
|
|
221
|
+
protected deepLog: boolean;
|
|
222
|
+
protected logFn: boolean;
|
|
222
223
|
|
|
223
|
-
constructor(){
|
|
224
|
+
constructor(dontLog?: boolean){
|
|
224
225
|
super();
|
|
225
226
|
|
|
227
|
+
this.asyncConstruct(dontLog);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private async asyncConstruct(dontLog?: 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,222 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
256
265
|
}
|
|
257
266
|
console.log(`Version: ${this._params.version}\n`);
|
|
258
267
|
|
|
259
|
-
this.startDB();
|
|
268
|
+
await this.startDB();
|
|
260
269
|
|
|
261
|
-
this.getGlobalServiceCollection();
|
|
262
|
-
this.debugLog = dynamoNTS_globalSettings.logSetup;
|
|
270
|
+
await this.getGlobalServiceCollection();
|
|
263
271
|
|
|
264
|
-
this.setSecurity();
|
|
272
|
+
await this.setSecurity();
|
|
265
273
|
|
|
266
274
|
if (this._routingModules?.length) {
|
|
267
|
-
this.initExpresses();
|
|
268
|
-
this.startExpresses();
|
|
275
|
+
await this.initExpresses();
|
|
276
|
+
await this.startExpresses();
|
|
269
277
|
|
|
270
278
|
if (this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
271
|
-
this.mountOpenRoutes();
|
|
279
|
+
await this.mountOpenRoutes();
|
|
272
280
|
}
|
|
273
281
|
if (this._security !== DynamoNTS_RouteSecurity.open && this._cert) {
|
|
274
|
-
this.mountSecureRoutes();
|
|
282
|
+
await this.mountSecureRoutes();
|
|
275
283
|
}
|
|
276
284
|
|
|
277
|
-
if (this.
|
|
285
|
+
if (this.logSetup) {
|
|
278
286
|
console.log(`\nRoutes mounted.... server using security: ${this._security}`);
|
|
279
287
|
}
|
|
280
288
|
}
|
|
281
289
|
|
|
282
290
|
if (this.getRootServices) {
|
|
283
|
-
this._rootServices = this.getRootServices();
|
|
291
|
+
this._rootServices = await this.getRootServices();
|
|
284
292
|
}
|
|
285
293
|
|
|
286
294
|
if (this.postProcess) {
|
|
287
|
-
this.postProcess();
|
|
295
|
+
await this.postProcess();
|
|
288
296
|
}
|
|
289
297
|
|
|
290
|
-
this.
|
|
291
|
-
|
|
298
|
+
await this.ready();
|
|
299
|
+
|
|
300
|
+
if (!dontLog) {
|
|
301
|
+
Dynamo_Log.test(`${this._params.name} started successfully.`);
|
|
302
|
+
}
|
|
292
303
|
} catch (error) {
|
|
293
304
|
this.constructErrors.push(error);
|
|
294
|
-
Dynamo_Log.error(
|
|
305
|
+
Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
|
|
295
306
|
}
|
|
296
307
|
}
|
|
297
308
|
|
|
298
309
|
async ready(timeout: number = 4 * second): Promise<void> {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
await delay(100);
|
|
310
|
+
if (this.logFn) console.log('\nfn:. ready');
|
|
311
|
+
/* return new Promise<void>(async (resolve, reject) => { */
|
|
312
|
+
let ready: boolean = false;
|
|
313
|
+
const start: number = +new Date();
|
|
314
|
+
|
|
315
|
+
if (this.constructErrors.length) {
|
|
316
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw ERROR-0', this.constructErrors);
|
|
317
|
+
throw new Dynamo_Error({
|
|
318
|
+
message: `${this._params.name} start failed. ERRORS`,
|
|
319
|
+
additionalContent: this.constructErrors.length === 1 ? this.constructErrors[0] : { errors: this.constructErrors },
|
|
320
|
+
});
|
|
321
|
+
}
|
|
312
322
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
323
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. ready: bef while', this.systemControls);
|
|
324
|
+
while (!ready && +new Date() - start < timeout) {
|
|
325
|
+
// if (this.logFn && this.deepLog) console.log('\nfn:. ready: while', this.systemControls);
|
|
326
|
+
/* if (this.logFn && this.deepLog) console.log('\nfn:. ready: while', this.systemControls,
|
|
327
|
+
{
|
|
328
|
+
mongoose: this.systemControls.mongoose.getReady(),
|
|
329
|
+
httpServer: this.systemControls.httpServer.getReady(),
|
|
330
|
+
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
331
|
+
}); */
|
|
332
|
+
if (this.systemControls.app.init) {
|
|
333
|
+
ready = (
|
|
334
|
+
this.systemControls.mongoose.getReady() &&
|
|
335
|
+
this.systemControls.httpServer.getReady() &&
|
|
336
|
+
this.systemControls.httpsServer.getReady()
|
|
337
|
+
);
|
|
320
338
|
}
|
|
321
339
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
message: 'Application start failed. TIMEOUT',
|
|
325
|
-
errors: this.constructErrors
|
|
326
|
-
});
|
|
327
|
-
}
|
|
340
|
+
await wait(100);
|
|
341
|
+
}
|
|
328
342
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
343
|
+
if (timeout < +new Date() - start) {
|
|
344
|
+
//if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw TIMEOUT', this.constructErrors, this.systemControls);
|
|
345
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw TIMEOUT', this.constructErrors, this.systemControls,
|
|
346
|
+
{
|
|
347
|
+
mongoose: this.systemControls.mongoose.getReady(),
|
|
348
|
+
httpServer: this.systemControls.httpServer.getReady(),
|
|
349
|
+
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
350
|
+
});
|
|
351
|
+
throw new Dynamo_Error({
|
|
352
|
+
message: `${this._params.name} start failed. TIMEOUT`,
|
|
353
|
+
additionalContent: {
|
|
354
|
+
constructErrors: this.constructErrors,
|
|
355
|
+
systemControls: this.systemControls,
|
|
356
|
+
systemReadies: {
|
|
357
|
+
mongoose: this.systemControls.mongoose.getReady(),
|
|
358
|
+
httpServer: this.systemControls.httpServer.getReady(),
|
|
359
|
+
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
});
|
|
363
|
+
}
|
|
346
364
|
|
|
347
|
-
|
|
365
|
+
if (this.constructErrors.length) {
|
|
366
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw ERROR');
|
|
367
|
+
throw new Dynamo_Error({
|
|
368
|
+
message: `${this._params.name} start failed. ERROR`,
|
|
369
|
+
additionalContent: this.constructErrors,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
348
372
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
373
|
+
if (ready) {
|
|
374
|
+
this.systemControls.app.started = true;
|
|
375
|
+
|
|
376
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. ready: return');
|
|
377
|
+
return;
|
|
378
|
+
} else {
|
|
379
|
+
this.systemControls.app.started = false;
|
|
380
|
+
|
|
381
|
+
let msg: string = `${this._params.name} start failed. UNKNOWN`;
|
|
382
|
+
if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
|
|
383
|
+
msg += `\nMongoose start failed.`;
|
|
353
384
|
}
|
|
354
|
-
|
|
385
|
+
if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
|
|
386
|
+
msg += `\nHTTP Server start failed.`;
|
|
387
|
+
}
|
|
388
|
+
if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
|
|
389
|
+
msg += `\nHTTPS Server start failed.`;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw UNKNOWN');
|
|
393
|
+
throw new Dynamo_Error({
|
|
394
|
+
message: msg,
|
|
395
|
+
additionalContent: this.constructErrors,
|
|
396
|
+
error: this.constructErrors?.[0] ?? new Error(),
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/* }); */
|
|
355
400
|
}
|
|
356
401
|
|
|
357
|
-
async stop(): Promise<void> {
|
|
402
|
+
async stop(dontLog?: boolean): Promise<void> {
|
|
403
|
+
if (this.logFn) console.log('\nfn:. stop');
|
|
358
404
|
if (this.started) {
|
|
359
405
|
|
|
360
|
-
if (this.
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
406
|
+
if (this.systemControls.mongoose.init) {
|
|
407
|
+
this.systemControls.mongoose.started = false;
|
|
408
|
+
if (this.mongoose) {
|
|
409
|
+
await Dynamo_Array.asyncForEach(Object.keys(this.mongoose.models), async (modelName) => {
|
|
410
|
+
await this.mongoose.deleteModel(modelName);
|
|
411
|
+
});
|
|
412
|
+
await this.mongoose.disconnect();
|
|
413
|
+
} else {
|
|
414
|
+
Dynamo_Log.error(`\nMongoose not found.`);
|
|
415
|
+
}
|
|
416
|
+
this.systemControls.mongoose.init = false;
|
|
364
417
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
418
|
+
|
|
419
|
+
if (this.systemControls.httpServer.init) {
|
|
420
|
+
this.systemControls.httpServer.started = false;
|
|
421
|
+
if (this.httpServer) {
|
|
422
|
+
await new Promise((resolve) => {
|
|
423
|
+
this.httpServer.close(resolve);
|
|
424
|
+
});
|
|
425
|
+
} else {
|
|
426
|
+
Dynamo_Log.error(`\nHTTP Server not found.`);
|
|
427
|
+
}
|
|
428
|
+
this.systemControls.httpServer.init = false;
|
|
369
429
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
430
|
+
|
|
431
|
+
if (this.systemControls.httpsServer.init) {
|
|
432
|
+
this.systemControls.httpsServer.started = false;
|
|
433
|
+
if (this.httpsServer) {
|
|
434
|
+
await new Promise((resolve) => {
|
|
435
|
+
this.httpsServer.close(resolve);
|
|
436
|
+
});
|
|
437
|
+
} else {
|
|
438
|
+
Dynamo_Log.error(`\nHTTPS Server not found.`);
|
|
439
|
+
}
|
|
440
|
+
this.systemControls.httpsServer.init = false;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (!dontLog) {
|
|
444
|
+
Dynamo_Log.test(`${this._params.name} stopped successfully.`);
|
|
375
445
|
}
|
|
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
446
|
}
|
|
388
447
|
}
|
|
389
448
|
|
|
390
449
|
/**
|
|
391
450
|
*
|
|
392
451
|
*/
|
|
393
|
-
private startDB(): void {
|
|
394
|
-
this.
|
|
395
|
-
|
|
396
|
-
.
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
452
|
+
private async startDB(): Promise<void> {
|
|
453
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. startDB');
|
|
454
|
+
await new Promise<void>(async (resolve, reject) => {
|
|
455
|
+
this.systemControls.mongoose.init = true;
|
|
456
|
+
this.mongoose.connection
|
|
457
|
+
.on('error', (error) => {
|
|
458
|
+
this.systemControls.mongoose.started = false;
|
|
459
|
+
this.constructErrors.push(error);
|
|
460
|
+
Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
|
|
461
|
+
reject(error);
|
|
462
|
+
})
|
|
463
|
+
.once('open', () => {
|
|
464
|
+
this.systemControls.mongoose.started = true;
|
|
465
|
+
Dynamo_Log.success('\nConnected to MongoDB\n');
|
|
466
|
+
resolve();
|
|
467
|
+
});
|
|
405
468
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
469
|
+
this.mongoose.connect(
|
|
470
|
+
this._params.dbUri,
|
|
471
|
+
{
|
|
472
|
+
useNewUrlParser: true,
|
|
473
|
+
useUnifiedTopology: true
|
|
474
|
+
}
|
|
475
|
+
);
|
|
476
|
+
});
|
|
413
477
|
}
|
|
414
478
|
|
|
415
479
|
/**
|
|
416
480
|
*
|
|
417
481
|
*/
|
|
418
|
-
private initExpresses() {
|
|
482
|
+
private async initExpresses(): Promise<void> {
|
|
483
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. initExpresses');
|
|
419
484
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
420
485
|
if (!this._ports.httpPort) {
|
|
421
486
|
let errorMsg: string =
|
|
@@ -444,7 +509,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
444
509
|
throw error;
|
|
445
510
|
}
|
|
446
511
|
|
|
447
|
-
this.initOpenExpress();
|
|
512
|
+
await this.initOpenExpress();
|
|
448
513
|
}
|
|
449
514
|
|
|
450
515
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.open) {
|
|
@@ -481,14 +546,15 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
481
546
|
throw error;
|
|
482
547
|
}
|
|
483
548
|
|
|
484
|
-
this.initSecureExpress();
|
|
549
|
+
await this.initSecureExpress();
|
|
485
550
|
}
|
|
486
551
|
}
|
|
487
552
|
|
|
488
553
|
/**
|
|
489
554
|
*
|
|
490
555
|
*/
|
|
491
|
-
protected initOpenExpress(): void {
|
|
556
|
+
protected async initOpenExpress(): Promise<void> {
|
|
557
|
+
if (this.logFn) console.log('\nfn:. initOpenExpress');
|
|
492
558
|
this.openExpress = Express();
|
|
493
559
|
this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
494
560
|
this.openExpress.use(BodyParser.json({ limit: '50mb' }));
|
|
@@ -497,7 +563,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
497
563
|
/**
|
|
498
564
|
*
|
|
499
565
|
*/
|
|
500
|
-
protected initSecureExpress(): void {
|
|
566
|
+
protected async initSecureExpress(): Promise<void> {
|
|
567
|
+
if (this.logFn) console.log('\nfn:. initSecureExpress');
|
|
501
568
|
this.secureExpress = Express();
|
|
502
569
|
this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
503
570
|
this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
|
|
@@ -513,39 +580,71 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
513
580
|
*
|
|
514
581
|
*/
|
|
515
582
|
private async startExpresses(): Promise<void> {
|
|
583
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. startExpresses');
|
|
516
584
|
try {
|
|
517
585
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.open) {
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
this.
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
586
|
+
await new Promise<void>((resolve, reject) => {
|
|
587
|
+
this.systemControls.httpsServer.init = true;
|
|
588
|
+
this.httpsServer
|
|
589
|
+
.listen(this._ports.httpsPort, 'localhost', 0, () => {
|
|
590
|
+
this.systemControls.httpsServer.started = true;
|
|
591
|
+
Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this._ports.httpsPort}`);
|
|
592
|
+
resolve();
|
|
593
|
+
})
|
|
594
|
+
.on('error', (error) => {
|
|
595
|
+
this.systemControls.httpsServer.started = false;
|
|
596
|
+
this.constructErrors.push(error);
|
|
597
|
+
/* Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error); */
|
|
598
|
+
reject(
|
|
599
|
+
new Dynamo_Error({
|
|
600
|
+
message: `HTTPS (secure) server ERROR`,
|
|
601
|
+
error: error,
|
|
602
|
+
})
|
|
603
|
+
);
|
|
604
|
+
})
|
|
605
|
+
.on('uncaughtException', (ex) => {
|
|
606
|
+
Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, ex);
|
|
607
|
+
reject(
|
|
608
|
+
new Dynamo_Error({
|
|
609
|
+
message: `HTTPS (secure) server uncaughtException`,
|
|
610
|
+
error: ex,
|
|
611
|
+
})
|
|
612
|
+
);
|
|
613
|
+
});
|
|
614
|
+
});
|
|
532
615
|
}
|
|
533
616
|
|
|
534
617
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
535
|
-
this.
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
this.
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
618
|
+
this.systemControls.httpServer.init = true;
|
|
619
|
+
await new Promise<void>((resolve, reject) => {
|
|
620
|
+
this.httpServer = this.openExpress
|
|
621
|
+
.listen(this._ports.httpPort, () => {
|
|
622
|
+
this.systemControls.httpServer.started = true;
|
|
623
|
+
Dynamo_Log.success(`\nHTTP (open) server is listening on port ${this._ports.httpPort}`);
|
|
624
|
+
resolve();
|
|
625
|
+
})
|
|
626
|
+
.on('error', (error) => {
|
|
627
|
+
this.systemControls.httpServer.started = false;
|
|
628
|
+
this.constructErrors.push(error);
|
|
629
|
+
|
|
630
|
+
Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
|
|
631
|
+
reject(
|
|
632
|
+
new Dynamo_Error({
|
|
633
|
+
message: `HTTP (open) server ERROR`,
|
|
634
|
+
error: error,
|
|
635
|
+
})
|
|
636
|
+
);
|
|
637
|
+
})
|
|
638
|
+
.on('uncaughtException', (ex) => {
|
|
639
|
+
Dynamo_Log.warn(`\nHTTP (open) server uncaughtException`, ex);
|
|
640
|
+
reject(
|
|
641
|
+
new Dynamo_Error({
|
|
642
|
+
message: `HTTP (open) server uncaughtException`,
|
|
643
|
+
error: ex
|
|
644
|
+
})
|
|
645
|
+
);
|
|
646
|
+
});
|
|
647
|
+
});
|
|
549
648
|
}
|
|
550
649
|
} catch (error) {
|
|
551
650
|
Dynamo_Log.error(`startExpresses failed...`, error);
|
|
@@ -555,10 +654,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
555
654
|
/**
|
|
556
655
|
*
|
|
557
656
|
*/
|
|
558
|
-
private mountSecureRoutes (): void {
|
|
559
|
-
this.
|
|
657
|
+
private async mountSecureRoutes (): Promise<void> {
|
|
658
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. mountSecureRoutes');
|
|
659
|
+
await Dynamo_Array.asyncForEach(this._routingModules, async (module: DynamoNTS_RoutingModule) => {
|
|
560
660
|
if (module.security !== DynamoNTS_RouteSecurity.open) {
|
|
561
|
-
if (this.
|
|
661
|
+
if (this.logSetup) {
|
|
562
662
|
console.log(`route mount (secure): ${module.route}`);
|
|
563
663
|
}
|
|
564
664
|
|
|
@@ -572,8 +672,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
572
672
|
errorStack.splice(1, 4);
|
|
573
673
|
error.stack = errorStack.join('\n');
|
|
574
674
|
|
|
575
|
-
throw
|
|
675
|
+
throw new Dynamo_Error({
|
|
676
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
677
|
+
error: error,
|
|
678
|
+
});
|
|
576
679
|
}
|
|
680
|
+
|
|
577
681
|
this.secureExpress.use(module.route, module.secureRouter);
|
|
578
682
|
}
|
|
579
683
|
});
|
|
@@ -582,10 +686,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
582
686
|
/**
|
|
583
687
|
*
|
|
584
688
|
*/
|
|
585
|
-
private mountOpenRoutes
|
|
586
|
-
this.
|
|
689
|
+
private async mountOpenRoutes(): Promise<void> {
|
|
690
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. mountOpenRoutes');
|
|
691
|
+
await Dynamo_Array.asyncForEach(this._routingModules, async (module: DynamoNTS_RoutingModule) => {
|
|
587
692
|
if (module.security !== DynamoNTS_RouteSecurity.secure) {
|
|
588
|
-
if (this.
|
|
693
|
+
if (this.logSetup) {
|
|
589
694
|
console.log(`route mount (open): ${module.route}`);
|
|
590
695
|
}
|
|
591
696
|
|
|
@@ -599,8 +704,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
599
704
|
errorStack.splice(1, 4);
|
|
600
705
|
error.stack = errorStack.join('\n');
|
|
601
706
|
|
|
602
|
-
throw
|
|
707
|
+
throw new Dynamo_Error({
|
|
708
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
709
|
+
error: error,
|
|
710
|
+
});
|
|
603
711
|
}
|
|
712
|
+
|
|
604
713
|
this.openExpress.use(module.route, module.openRouter);
|
|
605
714
|
}
|
|
606
715
|
});
|
|
@@ -609,7 +718,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
609
718
|
/**
|
|
610
719
|
*
|
|
611
720
|
*/
|
|
612
|
-
private setSecurity(): void {
|
|
721
|
+
private async setSecurity(): Promise<void> {
|
|
722
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. setSecurity');
|
|
613
723
|
this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
|
|
614
724
|
if (!module.security) {
|
|
615
725
|
Dynamo_Log.error(`RoutingModule security is not set for ${module.route}\n`);
|
|
@@ -627,7 +737,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
627
737
|
msg += `\n ${module.route} (security: ${module.security})`;
|
|
628
738
|
});
|
|
629
739
|
if (this._routingModules.length === 0) {
|
|
630
|
-
msg += '\n
|
|
740
|
+
msg += '\n - no RoutingModule found -\n';
|
|
631
741
|
}
|
|
632
742
|
Dynamo_Log.warn(msg);
|
|
633
743
|
}
|
|
@@ -725,7 +835,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
725
835
|
/**
|
|
726
836
|
* MISSING Description (TODO)
|
|
727
837
|
*/
|
|
728
|
-
getRootServices?(): DynamoNTS_SingletonService[]
|
|
838
|
+
getRootServices?(): Promise<DynamoNTS_SingletonService[]>;
|
|
729
839
|
|
|
730
840
|
/**
|
|
731
841
|
* MISSING Description (TODO)
|
|
@@ -735,10 +845,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
735
845
|
/**
|
|
736
846
|
* MISSING Description (TODO)
|
|
737
847
|
*/
|
|
738
|
-
createEntries?(): void
|
|
848
|
+
createEntries?(): Promise<void>;
|
|
739
849
|
|
|
740
850
|
/**
|
|
741
851
|
* MISSING Description (TODO)
|
|
742
852
|
*/
|
|
743
|
-
postProcess?(): void
|
|
853
|
+
postProcess?(): Promise<void>;
|
|
744
854
|
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { DynamoNTS_Shared } from './shared.static-service';
|
|
2
2
|
|
|
3
3
|
describe('DynamoNTS_Shared', () => {
|
|
4
|
-
it('
|
|
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
|
});
|