@futdevpro/nts-dynamo 1.6.18 → 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/data.service.js +2 -1
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/base/db.service.d.ts +2 -2
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +57 -215
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/core/global.service.d.ts +1 -1
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +30 -17
- package/lib/_services/core/global.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 +22 -8
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +413 -184
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/server/app.server.spec.js +32 -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 +8 -8
- 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/data.service.ts +1 -1
- package/src/_services/base/db.service.ts +110 -114
- package/src/_services/core/global.service.ts +14 -4
- 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 +35 -5
- package/src/_services/server/app.server.ts +302 -72
- package/src/_services/shared.service.spec.ts +10 -1
- package/src/_services/socket/socket-server.service.ts +36 -11
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
import Mongoose = require("mongoose");
|
|
3
3
|
import Express = require("express");
|
|
4
|
+
import * as Http from 'http';
|
|
4
5
|
import * as Https from 'https';
|
|
5
6
|
import * as FileSystem from 'fs';
|
|
6
7
|
import * as BodyParser from 'body-parser';
|
|
7
8
|
|
|
8
|
-
import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
|
|
9
|
+
import { delay, Dynamo_Array, Dynamo_Error, Dynamo_Log, second, wait } from '@futdevpro/fsm-dynamo';
|
|
9
10
|
|
|
10
11
|
import { DynamoNTS_SingletonService } from '../base/singleton.service';
|
|
11
12
|
import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
@@ -17,6 +18,10 @@ import { DynamoNTS_GlobalServiceSettings } from '../../_models/interfaces/global
|
|
|
17
18
|
import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
|
|
18
19
|
import { DynamoNTS_AppParams } from '../../_models/control-models/app-params.control-model';
|
|
19
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
|
+
|
|
20
25
|
|
|
21
26
|
/**
|
|
22
27
|
* This will be the MAIN service of our server project,
|
|
@@ -176,7 +181,11 @@ import { DynamoNTS_EndpointParams } from '../../_models/control-models/endpoint-
|
|
|
176
181
|
*/
|
|
177
182
|
export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
178
183
|
|
|
179
|
-
|
|
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)[] = [];
|
|
188
|
+
|
|
180
189
|
get serverName(): string { return this.params.name; }
|
|
181
190
|
|
|
182
191
|
private _params: DynamoNTS_AppParams;
|
|
@@ -196,6 +205,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
196
205
|
protected openExpress: Express.Application;
|
|
197
206
|
private secureExpress: Express.Application;
|
|
198
207
|
protected httpsServer: Https.Server;
|
|
208
|
+
protected httpServer: Http.Server;
|
|
209
|
+
|
|
210
|
+
private globalService: DynamoNTS_GlobalService;
|
|
199
211
|
|
|
200
212
|
private _routingModules: DynamoNTS_RoutingModule[] = [];
|
|
201
213
|
/* protected get routingModules(): DynamoNTS_RoutingModule[] { return this._routingModules; } */
|
|
@@ -205,23 +217,34 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
205
217
|
/**
|
|
206
218
|
* setting this value to true, enables this service debug logs
|
|
207
219
|
*/
|
|
208
|
-
protected
|
|
220
|
+
protected logSetup: boolean;
|
|
221
|
+
protected deepLog: boolean;
|
|
222
|
+
protected logFn: boolean;
|
|
209
223
|
|
|
210
|
-
constructor(){
|
|
224
|
+
constructor(dontLog?: boolean){
|
|
211
225
|
super();
|
|
212
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');
|
|
213
232
|
try {
|
|
233
|
+
this.systemControls.app.init = true;
|
|
234
|
+
this.logSetup = dynamoNTS_globalSettings.logSetup;
|
|
214
235
|
this._params = this.getAppParams();
|
|
215
236
|
|
|
237
|
+
|
|
216
238
|
if (this.overrideDynamoNTSGlobalSettings) {
|
|
217
239
|
this.overrideDynamoNTSGlobalSettings();
|
|
218
240
|
}
|
|
219
241
|
|
|
242
|
+
this.globalService = DynamoNTS_GlobalService.getInstance();
|
|
220
243
|
DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
|
|
221
244
|
DynamoNTS_GlobalService.setParams(this.params);
|
|
222
245
|
|
|
223
246
|
if (this.getPortSettings) {
|
|
224
|
-
this._ports = this.getPortSettings();
|
|
247
|
+
this._ports = this.getPortSettings();
|
|
225
248
|
}
|
|
226
249
|
|
|
227
250
|
if (this.getCertificationSettings) {
|
|
@@ -233,7 +256,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
233
256
|
}
|
|
234
257
|
|
|
235
258
|
if (this.createEntries) {
|
|
236
|
-
this.createEntries();
|
|
259
|
+
await this.createEntries();
|
|
237
260
|
}
|
|
238
261
|
|
|
239
262
|
console.log(`\n\n\nStarting ${this._params.name}... `);
|
|
@@ -242,68 +265,222 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
242
265
|
}
|
|
243
266
|
console.log(`Version: ${this._params.version}\n`);
|
|
244
267
|
|
|
245
|
-
this.startDB();
|
|
268
|
+
await this.startDB();
|
|
246
269
|
|
|
247
|
-
this.getGlobalServiceCollection();
|
|
248
|
-
this.debugLog = dynamoNTS_globalSettings.logSetup;
|
|
270
|
+
await this.getGlobalServiceCollection();
|
|
249
271
|
|
|
250
|
-
this.setSecurity();
|
|
272
|
+
await this.setSecurity();
|
|
251
273
|
|
|
252
274
|
if (this._routingModules?.length) {
|
|
253
|
-
this.initExpresses();
|
|
254
|
-
this.startExpresses();
|
|
275
|
+
await this.initExpresses();
|
|
276
|
+
await this.startExpresses();
|
|
255
277
|
|
|
256
278
|
if (this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
257
|
-
this.mountOpenRoutes();
|
|
279
|
+
await this.mountOpenRoutes();
|
|
258
280
|
}
|
|
259
281
|
if (this._security !== DynamoNTS_RouteSecurity.open && this._cert) {
|
|
260
|
-
this.mountSecureRoutes();
|
|
282
|
+
await this.mountSecureRoutes();
|
|
261
283
|
}
|
|
262
284
|
|
|
263
|
-
if (this.
|
|
285
|
+
if (this.logSetup) {
|
|
264
286
|
console.log(`\nRoutes mounted.... server using security: ${this._security}`);
|
|
265
287
|
}
|
|
266
288
|
}
|
|
267
289
|
|
|
268
290
|
if (this.getRootServices) {
|
|
269
|
-
this._rootServices = this.getRootServices();
|
|
291
|
+
this._rootServices = await this.getRootServices();
|
|
270
292
|
}
|
|
271
293
|
|
|
272
294
|
if (this.postProcess) {
|
|
273
|
-
this.postProcess();
|
|
295
|
+
await this.postProcess();
|
|
274
296
|
}
|
|
275
297
|
|
|
276
|
-
this.
|
|
298
|
+
await this.ready();
|
|
299
|
+
|
|
300
|
+
if (!dontLog) {
|
|
301
|
+
Dynamo_Log.test(`${this._params.name} started successfully.`);
|
|
302
|
+
}
|
|
277
303
|
} catch (error) {
|
|
278
|
-
|
|
304
|
+
this.constructErrors.push(error);
|
|
305
|
+
Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
async ready(timeout: number = 4 * second): Promise<void> {
|
|
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
|
+
}
|
|
322
|
+
|
|
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
|
+
);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
await wait(100);
|
|
341
|
+
}
|
|
342
|
+
|
|
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
|
+
}
|
|
364
|
+
|
|
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
|
+
}
|
|
372
|
+
|
|
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.`;
|
|
384
|
+
}
|
|
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
|
+
/* }); */
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
async stop(dontLog?: boolean): Promise<void> {
|
|
403
|
+
if (this.logFn) console.log('\nfn:. stop');
|
|
404
|
+
if (this.started) {
|
|
405
|
+
|
|
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;
|
|
417
|
+
}
|
|
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;
|
|
429
|
+
}
|
|
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.`);
|
|
445
|
+
}
|
|
279
446
|
}
|
|
280
447
|
}
|
|
281
448
|
|
|
282
449
|
/**
|
|
283
450
|
*
|
|
284
451
|
*/
|
|
285
|
-
private startDB(): void {
|
|
286
|
-
this.
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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
|
+
});
|
|
293
468
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
469
|
+
this.mongoose.connect(
|
|
470
|
+
this._params.dbUri,
|
|
471
|
+
{
|
|
472
|
+
useNewUrlParser: true,
|
|
473
|
+
useUnifiedTopology: true
|
|
474
|
+
}
|
|
475
|
+
);
|
|
476
|
+
});
|
|
301
477
|
}
|
|
302
478
|
|
|
303
479
|
/**
|
|
304
480
|
*
|
|
305
481
|
*/
|
|
306
|
-
private initExpresses() {
|
|
482
|
+
private async initExpresses(): Promise<void> {
|
|
483
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. initExpresses');
|
|
307
484
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
308
485
|
if (!this._ports.httpPort) {
|
|
309
486
|
let errorMsg: string =
|
|
@@ -332,7 +509,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
332
509
|
throw error;
|
|
333
510
|
}
|
|
334
511
|
|
|
335
|
-
this.initOpenExpress();
|
|
512
|
+
await this.initOpenExpress();
|
|
336
513
|
}
|
|
337
514
|
|
|
338
515
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.open) {
|
|
@@ -369,14 +546,15 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
369
546
|
throw error;
|
|
370
547
|
}
|
|
371
548
|
|
|
372
|
-
this.initSecureExpress();
|
|
549
|
+
await this.initSecureExpress();
|
|
373
550
|
}
|
|
374
551
|
}
|
|
375
552
|
|
|
376
553
|
/**
|
|
377
554
|
*
|
|
378
555
|
*/
|
|
379
|
-
protected initOpenExpress(): void {
|
|
556
|
+
protected async initOpenExpress(): Promise<void> {
|
|
557
|
+
if (this.logFn) console.log('\nfn:. initOpenExpress');
|
|
380
558
|
this.openExpress = Express();
|
|
381
559
|
this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
382
560
|
this.openExpress.use(BodyParser.json({ limit: '50mb' }));
|
|
@@ -385,7 +563,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
385
563
|
/**
|
|
386
564
|
*
|
|
387
565
|
*/
|
|
388
|
-
protected initSecureExpress(): void {
|
|
566
|
+
protected async initSecureExpress(): Promise<void> {
|
|
567
|
+
if (this.logFn) console.log('\nfn:. initSecureExpress');
|
|
389
568
|
this.secureExpress = Express();
|
|
390
569
|
this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
391
570
|
this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
|
|
@@ -401,31 +580,71 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
401
580
|
*
|
|
402
581
|
*/
|
|
403
582
|
private async startExpresses(): Promise<void> {
|
|
583
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. startExpresses');
|
|
404
584
|
try {
|
|
405
585
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.open) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|
+
});
|
|
416
615
|
}
|
|
417
616
|
|
|
418
617
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
419
|
-
this.
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
+
});
|
|
429
648
|
}
|
|
430
649
|
} catch (error) {
|
|
431
650
|
Dynamo_Log.error(`startExpresses failed...`, error);
|
|
@@ -435,10 +654,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
435
654
|
/**
|
|
436
655
|
*
|
|
437
656
|
*/
|
|
438
|
-
private mountSecureRoutes (): void {
|
|
439
|
-
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) => {
|
|
440
660
|
if (module.security !== DynamoNTS_RouteSecurity.open) {
|
|
441
|
-
if (this.
|
|
661
|
+
if (this.logSetup) {
|
|
442
662
|
console.log(`route mount (secure): ${module.route}`);
|
|
443
663
|
}
|
|
444
664
|
|
|
@@ -452,8 +672,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
452
672
|
errorStack.splice(1, 4);
|
|
453
673
|
error.stack = errorStack.join('\n');
|
|
454
674
|
|
|
455
|
-
throw
|
|
675
|
+
throw new Dynamo_Error({
|
|
676
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
677
|
+
error: error,
|
|
678
|
+
});
|
|
456
679
|
}
|
|
680
|
+
|
|
457
681
|
this.secureExpress.use(module.route, module.secureRouter);
|
|
458
682
|
}
|
|
459
683
|
});
|
|
@@ -462,10 +686,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
462
686
|
/**
|
|
463
687
|
*
|
|
464
688
|
*/
|
|
465
|
-
private mountOpenRoutes
|
|
466
|
-
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) => {
|
|
467
692
|
if (module.security !== DynamoNTS_RouteSecurity.secure) {
|
|
468
|
-
if (this.
|
|
693
|
+
if (this.logSetup) {
|
|
469
694
|
console.log(`route mount (open): ${module.route}`);
|
|
470
695
|
}
|
|
471
696
|
|
|
@@ -479,8 +704,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
479
704
|
errorStack.splice(1, 4);
|
|
480
705
|
error.stack = errorStack.join('\n');
|
|
481
706
|
|
|
482
|
-
throw
|
|
707
|
+
throw new Dynamo_Error({
|
|
708
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
709
|
+
error: error,
|
|
710
|
+
});
|
|
483
711
|
}
|
|
712
|
+
|
|
484
713
|
this.openExpress.use(module.route, module.openRouter);
|
|
485
714
|
}
|
|
486
715
|
});
|
|
@@ -489,7 +718,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
489
718
|
/**
|
|
490
719
|
*
|
|
491
720
|
*/
|
|
492
|
-
private setSecurity(): void {
|
|
721
|
+
private async setSecurity(): Promise<void> {
|
|
722
|
+
if (this.logFn && this.deepLog) console.log('\nfn:. setSecurity');
|
|
493
723
|
this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
|
|
494
724
|
if (!module.security) {
|
|
495
725
|
Dynamo_Log.error(`RoutingModule security is not set for ${module.route}\n`);
|
|
@@ -507,7 +737,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
507
737
|
msg += `\n ${module.route} (security: ${module.security})`;
|
|
508
738
|
});
|
|
509
739
|
if (this._routingModules.length === 0) {
|
|
510
|
-
msg += '\n
|
|
740
|
+
msg += '\n - no RoutingModule found -\n';
|
|
511
741
|
}
|
|
512
742
|
Dynamo_Log.warn(msg);
|
|
513
743
|
}
|
|
@@ -605,7 +835,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
605
835
|
/**
|
|
606
836
|
* MISSING Description (TODO)
|
|
607
837
|
*/
|
|
608
|
-
getRootServices?(): DynamoNTS_SingletonService[]
|
|
838
|
+
getRootServices?(): Promise<DynamoNTS_SingletonService[]>;
|
|
609
839
|
|
|
610
840
|
/**
|
|
611
841
|
* MISSING Description (TODO)
|
|
@@ -615,10 +845,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
615
845
|
/**
|
|
616
846
|
* MISSING Description (TODO)
|
|
617
847
|
*/
|
|
618
|
-
createEntries?(): void
|
|
848
|
+
createEntries?(): Promise<void>;
|
|
619
849
|
|
|
620
850
|
/**
|
|
621
851
|
* MISSING Description (TODO)
|
|
622
852
|
*/
|
|
623
|
-
postProcess?(): void
|
|
853
|
+
postProcess?(): Promise<void>;
|
|
624
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
|
});
|