@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.
- package/lib/_constants/mocks/app-extended-server.mock.d.ts +41 -0
- package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/app-extended-server.mock.js +168 -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 +12 -5
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/data-model.mock.d.ts +27 -0
- package/lib/_constants/mocks/data-model.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/data-model.mock.js +57 -0
- package/lib/_constants/mocks/data-model.mock.js.map +1 -0
- package/lib/_constants/mocks/email-service-collection.mock.d.ts +7 -0
- package/lib/_constants/mocks/email-service-collection.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/email-service-collection.mock.js +16 -0
- package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -0
- package/lib/_constants/mocks/email-service.mock.d.ts +5 -0
- package/lib/_constants/mocks/email-service.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/email-service.mock.js +21 -0
- package/lib/_constants/mocks/email-service.mock.js.map +1 -0
- package/lib/_constants/mocks/socket-client.mock.d.ts +9 -0
- package/lib/_constants/mocks/socket-client.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/socket-client.mock.js +39 -0
- package/lib/_constants/mocks/socket-client.mock.js.map +1 -0
- 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/core/email.service.d.ts.map +1 -1
- package/lib/_services/core/email.service.js +0 -1
- package/lib/_services/core/email.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 +228 -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 +55 -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 +382 -258
- 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 +191 -0
- package/src/_constants/mocks/app-server.mock.ts +10 -5
- package/src/_constants/mocks/data-model.mock.ts +83 -0
- package/src/_constants/mocks/email-service-collection.mock.ts +12 -0
- package/src/_constants/mocks/email-service.mock.ts +19 -0
- package/src/_constants/mocks/email-template.mock.html +15 -0
- package/src/_constants/mocks/socket-client.mock.ts +42 -0
- 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/core/email.service.ts +0 -1
- package/src/_services/server/app-extended.server.spec.ts +66 -0
- package/src/_services/server/app-extended.server.ts +205 -41
- package/src/_services/server/app.server.spec.ts +17 -7
- package/src/_services/server/app.server.ts +284 -165
- package/src/_services/shared.service.spec.ts +10 -1
- 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
|
-
|
|
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(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.
|
|
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
|
-
|
|
291
|
-
|
|
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(
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
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
|
-
|
|
323
|
-
|
|
324
|
-
message: 'Application start failed. TIMEOUT',
|
|
325
|
-
errors: this.constructErrors
|
|
326
|
-
});
|
|
327
|
-
}
|
|
330
|
+
await wait(100);
|
|
331
|
+
}
|
|
328
332
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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.
|
|
361
|
-
|
|
362
|
-
|
|
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
|
-
|
|
366
|
-
|
|
367
|
-
|
|
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
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
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.
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
this.
|
|
398
|
-
this.
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
this.
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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.
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
this.
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
|
586
|
-
this.
|
|
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.
|
|
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
|
-
|
|
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
|
|
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('
|
|
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
|
});
|