@futdevpro/nts-dynamo 1.7.17 → 1.7.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/.eslintrc.json +171 -0
- package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -1
- package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/data-model.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/data-model.mock.js.map +1 -1
- package/lib/_constants/mocks/email-service-collection.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/email-service-collection.mock.js.map +1 -1
- package/lib/_constants/mocks/email-service.mock.js +3 -3
- package/lib/_constants/mocks/email-service.mock.js.map +1 -1
- package/lib/_constants/mocks/endpoint.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/endpoint.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
- package/lib/_enums/index.js +1 -1
- package/lib/_enums/index.js.map +1 -1
- package/lib/_models/control-models/api-call-params.control-model.d.ts +2 -2
- package/lib/_models/control-models/api-call-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/api-call-params.control-model.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.d.ts.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/endpoint-params.control-model.js +15 -9
- package/lib/_models/control-models/endpoint-params.control-model.js.map +1 -1
- package/lib/_models/control-models/http-settings.control-model.d.ts +1 -1
- package/lib/_models/control-models/http-settings.control-model.d.ts.map +1 -1
- package/lib/_models/control-models/http-settings.control-model.js +3 -1
- package/lib/_models/control-models/http-settings.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-client-service-params.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-event.control-model.js.map +1 -1
- package/lib/_models/control-models/socket-presence.control-model.js.map +1 -1
- package/lib/_modules/custom-data/custom-data.controller.d.ts.map +1 -1
- package/lib/_modules/custom-data/custom-data.controller.js +2 -1
- package/lib/_modules/custom-data/custom-data.controller.js.map +1 -1
- package/lib/_modules/custom-data/get-custom-data-routing-module.util.d.ts.map +1 -1
- package/lib/_modules/custom-data/get-custom-data-routing-module.util.js.map +1 -1
- package/lib/_modules/test/get-test-routing-module.util.d.ts.map +1 -1
- package/lib/_modules/test/get-test-routing-module.util.js.map +1 -1
- package/lib/_modules/test/test.controller.d.ts.map +1 -1
- package/lib/_modules/test/test.controller.js.map +1 -1
- package/lib/_modules/usage/get-usage-routing-module.util.d.ts.map +1 -1
- package/lib/_modules/usage/get-usage-routing-module.util.js +1 -1
- package/lib/_modules/usage/get-usage-routing-module.util.js.map +1 -1
- package/lib/_modules/usage/usage.controller.d.ts.map +1 -1
- package/lib/_modules/usage/usage.controller.js +15 -14
- package/lib/_modules/usage/usage.controller.js.map +1 -1
- package/lib/_modules/usage/usage.data-service.d.ts +3 -1
- package/lib/_modules/usage/usage.data-service.d.ts.map +1 -1
- package/lib/_modules/usage/usage.data-service.js +24 -16
- package/lib/_modules/usage/usage.data-service.js.map +1 -1
- package/lib/_services/base/data.service.d.ts.map +1 -1
- package/lib/_services/base/data.service.js +45 -23
- package/lib/_services/base/data.service.js.map +1 -1
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +82 -53
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/base/singleton.service.d.ts.map +1 -1
- package/lib/_services/base/singleton.service.js.map +1 -1
- package/lib/_services/core/api.service.d.ts +21 -13
- package/lib/_services/core/api.service.d.ts.map +1 -1
- package/lib/_services/core/api.service.js +192 -143
- package/lib/_services/core/api.service.js.map +1 -1
- package/lib/_services/core/auth.service.d.ts.map +1 -1
- package/lib/_services/core/auth.service.js.map +1 -1
- package/lib/_services/core/email.service.d.ts +50 -36
- package/lib/_services/core/email.service.d.ts.map +1 -1
- package/lib/_services/core/email.service.js +329 -94
- package/lib/_services/core/email.service.js.map +1 -1
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +30 -19
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/route/controller.service.d.ts.map +1 -1
- package/lib/_services/route/controller.service.js.map +1 -1
- package/lib/_services/route/routing-module.service.d.ts.map +1 -1
- package/lib/_services/route/routing-module.service.js +2 -2
- package/lib/_services/route/routing-module.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.d.ts.map +1 -1
- package/lib/_services/server/app-extended.server.js +19 -14
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app-extended.server.spec.js +1 -0
- package/lib/_services/server/app-extended.server.spec.js.map +1 -1
- package/lib/_services/server/app.server.d.ts +4 -3
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +106 -51
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/server/app.server.spec.js +1 -0
- package/lib/_services/server/app.server.spec.js.map +1 -1
- package/lib/_services/shared.static-service.js.map +1 -1
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/nodemon.json +3 -1
- package/package.json +9 -8
- package/src/_constants/mocks/app-extended-server.mock.ts +6 -2
- package/src/_constants/mocks/app-server.mock.ts +7 -1
- package/src/_constants/mocks/data-model.mock.ts +2 -2
- package/src/_constants/mocks/email-service-collection.mock.ts +2 -1
- package/src/_constants/mocks/email-service.mock.ts +2 -2
- package/src/_constants/mocks/endpoint.mock.ts +28 -26
- package/src/_constants/mocks/socket-server.mock.ts +12 -4
- package/src/_enums/index.ts +1 -1
- package/src/_models/control-models/api-call-params.control-model.ts +3 -2
- package/src/_models/control-models/app-system-controls.control-model copy.ts +1 -1
- package/src/_models/control-models/app-system-controls.control-model.ts +1 -1
- package/src/_models/control-models/endpoint-params.control-model.ts +39 -16
- package/src/_models/control-models/http-settings.control-model.ts +4 -2
- package/src/_modules/custom-data/custom-data.controller.ts +55 -51
- package/src/_modules/custom-data/get-custom-data-routing-module.util.ts +7 -3
- package/src/_modules/test/get-test-routing-module.util.ts +7 -3
- package/src/_modules/test/test.controller.ts +98 -96
- package/src/_modules/usage/get-usage-routing-module.util.ts +8 -4
- package/src/_modules/usage/usage.controller.ts +108 -102
- package/src/_modules/usage/usage.data-service.ts +54 -28
- package/src/_services/base/data.service.ts +133 -34
- package/src/_services/base/db.service.ts +254 -171
- package/src/_services/base/singleton.service.ts +1 -1
- package/src/_services/core/api.service.ts +348 -218
- package/src/_services/core/auth.service.ts +2 -0
- package/src/_services/core/email.service.ts +537 -129
- package/src/_services/core/global.service.ts +56 -26
- package/src/_services/route/controller.service.ts +3 -1
- package/src/_services/route/routing-module.service.ts +33 -16
- package/src/_services/server/app-extended.server.spec.ts +22 -17
- package/src/_services/server/app-extended.server.ts +108 -45
- package/src/_services/server/app.server.spec.ts +17 -12
- package/src/_services/server/app.server.ts +264 -138
|
@@ -1,25 +1,40 @@
|
|
|
1
1
|
|
|
2
|
-
import Mongoose = require(
|
|
3
|
-
import Express = require(
|
|
2
|
+
import Mongoose = require('mongoose');
|
|
3
|
+
import Express = require('express');
|
|
4
|
+
/* import Mongoose from 'mongoose';
|
|
5
|
+
import Express from 'express'; */
|
|
4
6
|
|
|
5
7
|
import * as Http from 'http';
|
|
6
8
|
import * as Https from 'https';
|
|
7
9
|
import * as FileSystem from 'fs';
|
|
8
10
|
import * as BodyParser from 'body-parser';
|
|
9
11
|
|
|
10
|
-
import {
|
|
12
|
+
/* import { version } from '../../../package.json'; */
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
Dynamo_Array, Dynamo_Error, dynamo_error_default,
|
|
16
|
+
Dynamo_ErrorLevel, Dynamo_Log, second, wait
|
|
17
|
+
} from '@futdevpro/fsm-dynamo';
|
|
11
18
|
|
|
12
19
|
import { DynamoNTS_SingletonService } from '../base/singleton.service';
|
|
13
20
|
import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
|
|
14
21
|
import { DynamoNTS_RoutingModule } from '../route/routing-module.service';
|
|
15
22
|
import { DynamoNTS_GlobalService } from '../core/global.service';
|
|
16
23
|
import { DynamoNTS_HttpSettings } from '../../_models/control-models/http-settings.control-model';
|
|
17
|
-
import {
|
|
18
|
-
|
|
24
|
+
import {
|
|
25
|
+
DynamoNTS_CertificationSettings
|
|
26
|
+
} from '../../_models/interfaces/certification-settings.interface';
|
|
27
|
+
import {
|
|
28
|
+
DynamoNTS_GlobalServiceSettings
|
|
29
|
+
} from '../../_models/interfaces/global-service-settings.interface';
|
|
19
30
|
import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
|
|
20
31
|
import { DynamoNTS_AppParams } from '../../_models/control-models/app-params.control-model';
|
|
21
|
-
import {
|
|
22
|
-
|
|
32
|
+
import {
|
|
33
|
+
DynamoNTS_EndpointParams
|
|
34
|
+
} from '../../_models/control-models/endpoint-params.control-model';
|
|
35
|
+
import {
|
|
36
|
+
DynamoNTS_AppSystemControls
|
|
37
|
+
} from '../../_models/control-models/app-system-controls.control-model';
|
|
23
38
|
|
|
24
39
|
|
|
25
40
|
/**
|
|
@@ -118,7 +133,8 @@ import { DynamoNTS_AppSystemControls } from '../../_models/control-models/app-sy
|
|
|
118
133
|
* // A commonly used basic service,
|
|
119
134
|
* // which is necessary fur certain functions (such as registering call issuers)
|
|
120
135
|
* //
|
|
121
|
-
* // This will handle Authentication Token checking/refreshing,
|
|
136
|
+
* // This will handle Authentication Token checking/refreshing,
|
|
137
|
+
* // checking issuer's identifier and routeParams,
|
|
122
138
|
* // handling JWT Token, or maybe with OAuth2 or other commonly used security procedures
|
|
123
139
|
* //
|
|
124
140
|
* // You can create one with this Dynamo Object:
|
|
@@ -181,25 +197,45 @@ import { DynamoNTS_AppSystemControls } from '../../_models/control-models/app-sy
|
|
|
181
197
|
export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
182
198
|
|
|
183
199
|
protected systemControls: DynamoNTS_AppSystemControls = new DynamoNTS_AppSystemControls();
|
|
184
|
-
get started(): boolean {
|
|
185
|
-
|
|
200
|
+
get started(): boolean {
|
|
201
|
+
return this.systemControls.app.started;
|
|
202
|
+
}
|
|
203
|
+
protected get superStarted(): boolean {
|
|
204
|
+
return this.systemControls.app.started;
|
|
205
|
+
}
|
|
186
206
|
protected constructErrors: (Error | Dynamo_Error)[] = [];
|
|
187
|
-
|
|
188
|
-
|
|
207
|
+
|
|
208
|
+
/* removed since cant use version from package.json
|
|
209
|
+
private readonly _ntsVersion: string = 'v01.07.18';
|
|
210
|
+
protected get ntsVersion(): string {
|
|
211
|
+
return this._ntsVersion;
|
|
212
|
+
} */
|
|
213
|
+
|
|
214
|
+
get serverName(): string {
|
|
215
|
+
return this.params.name;
|
|
216
|
+
}
|
|
189
217
|
|
|
190
218
|
private _params: DynamoNTS_AppParams;
|
|
191
|
-
protected get params(): DynamoNTS_AppParams {
|
|
219
|
+
protected get params(): DynamoNTS_AppParams {
|
|
220
|
+
return this._params;
|
|
221
|
+
}
|
|
192
222
|
|
|
193
223
|
protected mongoose = Mongoose;
|
|
194
224
|
|
|
195
225
|
private _security: DynamoNTS_RouteSecurity;
|
|
196
|
-
protected get security(): DynamoNTS_RouteSecurity {
|
|
226
|
+
protected get security(): DynamoNTS_RouteSecurity {
|
|
227
|
+
return this._security;
|
|
228
|
+
}
|
|
197
229
|
|
|
198
|
-
protected _portSettings: DynamoNTS_HttpSettings;
|
|
199
|
-
protected get portSettings(): DynamoNTS_HttpSettings {
|
|
230
|
+
protected _portSettings: DynamoNTS_HttpSettings = new DynamoNTS_HttpSettings();
|
|
231
|
+
protected get portSettings(): DynamoNTS_HttpSettings {
|
|
232
|
+
return this._portSettings;
|
|
233
|
+
}
|
|
200
234
|
|
|
201
235
|
private _cert?: DynamoNTS_CertificationSettings;
|
|
202
|
-
protected get cert(): DynamoNTS_CertificationSettings {
|
|
236
|
+
protected get cert(): DynamoNTS_CertificationSettings {
|
|
237
|
+
return this._cert;
|
|
238
|
+
}
|
|
203
239
|
|
|
204
240
|
protected openExpress: Express.Application;
|
|
205
241
|
private secureExpress: Express.Application;
|
|
@@ -227,9 +263,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
227
263
|
constructor(extended?: boolean){
|
|
228
264
|
super();
|
|
229
265
|
|
|
230
|
-
process.on('unhandledRejection', (reason: object,
|
|
266
|
+
process.on('unhandledRejection', (reason: object, p_passWhatIsThis: any): void => {
|
|
231
267
|
Dynamo_Log.highlightedError(
|
|
232
|
-
'Unhandled Rejection at: ',
|
|
268
|
+
'Unhandled Rejection at: ', p_passWhatIsThis,
|
|
233
269
|
'\nRejection reason:', reason
|
|
234
270
|
);
|
|
235
271
|
|
|
@@ -238,8 +274,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
238
274
|
new Dynamo_Error({
|
|
239
275
|
errorCode: 'NTS-AS0-BASE-UR',
|
|
240
276
|
message: 'Unhandled Rejection!',
|
|
241
|
-
error: new Error(
|
|
242
|
-
additionalContent: { reason, p },
|
|
277
|
+
error: new Error(p_passWhatIsThis),
|
|
278
|
+
additionalContent: { reason, p: p_passWhatIsThis },
|
|
279
|
+
level: Dynamo_ErrorLevel.critical,
|
|
243
280
|
})
|
|
244
281
|
);
|
|
245
282
|
|
|
@@ -248,7 +285,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
248
285
|
}
|
|
249
286
|
});
|
|
250
287
|
|
|
251
|
-
this.asyncConstruct(extended).catch((error: any) => {
|
|
288
|
+
this.asyncConstruct(extended).catch((error: any): void => {
|
|
252
289
|
Dynamo_Log.error(
|
|
253
290
|
`\nApplication: ${this._params.name} start failed.` +
|
|
254
291
|
`\n`, error
|
|
@@ -257,22 +294,21 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
257
294
|
}
|
|
258
295
|
|
|
259
296
|
private async asyncConstruct(extended?: boolean): Promise<void> {
|
|
260
|
-
if (this.logFn && this.deepLog)
|
|
297
|
+
if (this.logFn && this.deepLog) Dynamo_Log.log('\nfn:. asyncConstruct');
|
|
261
298
|
try {
|
|
262
|
-
|
|
299
|
+
this.systemControls.app.init = true;
|
|
300
|
+
this._params = this.getAppParams();
|
|
301
|
+
Dynamo_Log.log(
|
|
263
302
|
`\n\n\n\n\n\n\n\n\n\n` +
|
|
264
303
|
`Starting ${this._params?.name}... `
|
|
265
304
|
);
|
|
266
305
|
|
|
267
|
-
this.systemControls.app.init = true;
|
|
268
|
-
this._params = this.getAppParams();
|
|
269
|
-
|
|
270
306
|
if (!this._params) {
|
|
271
307
|
throw new Error('getAppParams() must return a DynamoNTS_AppParams object!');
|
|
272
308
|
}
|
|
273
309
|
|
|
274
310
|
process.stdout.write(
|
|
275
|
-
String.fromCharCode(27) +
|
|
311
|
+
String.fromCharCode(27) + ']0;' +
|
|
276
312
|
this._params?.name +
|
|
277
313
|
String.fromCharCode(7)
|
|
278
314
|
);
|
|
@@ -284,7 +320,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
284
320
|
this.logSetup = dynamoNTS_globalSettings.logSetup;
|
|
285
321
|
|
|
286
322
|
this.globalService = DynamoNTS_GlobalService.getInstance();
|
|
287
|
-
DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
|
|
323
|
+
await DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
|
|
288
324
|
DynamoNTS_GlobalService.setParams(this.params);
|
|
289
325
|
|
|
290
326
|
if (this.getPortSettings) {
|
|
@@ -299,10 +335,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
299
335
|
this._routingModules = this.getRoutingModules();
|
|
300
336
|
}
|
|
301
337
|
|
|
302
|
-
await this.createEntries?.();
|
|
303
|
-
|
|
304
338
|
await this.startDB();
|
|
305
339
|
|
|
340
|
+
await this.createEntries?.();
|
|
341
|
+
|
|
306
342
|
this.setSecurity();
|
|
307
343
|
|
|
308
344
|
if (this._routingModules?.length) {
|
|
@@ -312,12 +348,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
312
348
|
if (this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
313
349
|
await this.mountOpenRoutes();
|
|
314
350
|
}
|
|
351
|
+
|
|
315
352
|
if (this._security !== DynamoNTS_RouteSecurity.open && this._cert) {
|
|
316
353
|
await this.mountSecureRoutes();
|
|
317
354
|
}
|
|
318
355
|
|
|
319
356
|
if (this.logSetup) {
|
|
320
|
-
|
|
357
|
+
Dynamo_Log.log(`\nRoutes mounted.... server using security: ${this._security}`);
|
|
321
358
|
}
|
|
322
359
|
}
|
|
323
360
|
|
|
@@ -332,14 +369,16 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
332
369
|
await this.ready();
|
|
333
370
|
|
|
334
371
|
if (this.params.title) {
|
|
335
|
-
|
|
336
|
-
console.log(`Version: ${this.params.version}`);
|
|
372
|
+
Dynamo_Log.success(this.params.title);
|
|
337
373
|
}
|
|
374
|
+
Dynamo_Log.info(`Version: ${this.params.version}`);
|
|
375
|
+
/* Dynamo_Log.info(`NTS Version: ${this.ntsVersion}`); */
|
|
338
376
|
Dynamo_Log.H_success(`${this.params.name} started successfully.`);
|
|
339
377
|
}
|
|
340
378
|
} catch (error) {
|
|
341
379
|
this.constructErrors.push(error);
|
|
342
380
|
Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
|
|
381
|
+
|
|
343
382
|
throw new Dynamo_Error({
|
|
344
383
|
...this._getDefaultErrorSettings(
|
|
345
384
|
'asyncConstruct',
|
|
@@ -362,12 +401,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
362
401
|
}
|
|
363
402
|
|
|
364
403
|
async ready(timeout: number = 4 * second): Promise<void> {
|
|
365
|
-
if (this.logFn)
|
|
404
|
+
if (this.logFn) Dynamo_Log.log('\nfn:. ready');
|
|
366
405
|
let ready: boolean = false;
|
|
367
406
|
const start: number = +new Date();
|
|
368
407
|
|
|
369
408
|
if (this.constructErrors.length) {
|
|
370
409
|
Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
|
|
410
|
+
|
|
371
411
|
throw new Dynamo_Error({
|
|
372
412
|
...this._getDefaultErrorSettings(
|
|
373
413
|
'ready',
|
|
@@ -375,7 +415,10 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
375
415
|
),
|
|
376
416
|
|
|
377
417
|
errorCode: 'NTS-AS0-R1',
|
|
378
|
-
additionalContent:
|
|
418
|
+
additionalContent:
|
|
419
|
+
this.constructErrors.length === 1 ?
|
|
420
|
+
this.constructErrors[0] :
|
|
421
|
+
{ errors: this.constructErrors },
|
|
379
422
|
});
|
|
380
423
|
}
|
|
381
424
|
|
|
@@ -397,6 +440,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
397
440
|
|
|
398
441
|
if (timeout < +new Date() - start) {
|
|
399
442
|
Dynamo_Log.error(`${this._params.name} start failed. TIMEOUT`, this.constructErrors);
|
|
443
|
+
|
|
400
444
|
throw new Dynamo_Error({
|
|
401
445
|
...this._getDefaultErrorSettings(
|
|
402
446
|
'ready',
|
|
@@ -433,23 +477,28 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
433
477
|
if (ready) {
|
|
434
478
|
this.systemControls.app.started = true;
|
|
435
479
|
|
|
436
|
-
if (this.logFn && this.deepLog)
|
|
480
|
+
if (this.logFn && this.deepLog) Dynamo_Log.log('\nfn:. ready: return');
|
|
481
|
+
|
|
437
482
|
return;
|
|
438
483
|
} else {
|
|
439
484
|
this.systemControls.app.started = false;
|
|
440
485
|
|
|
441
486
|
let msg: string = `${this._params.name} start failed. UNKNOWN`;
|
|
487
|
+
|
|
442
488
|
if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
|
|
443
489
|
msg += `\nMongoose start failed.`;
|
|
444
490
|
}
|
|
491
|
+
|
|
445
492
|
if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
|
|
446
493
|
msg += `\nHTTP Server start failed.`;
|
|
447
494
|
}
|
|
495
|
+
|
|
448
496
|
if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
|
|
449
497
|
msg += `\nHTTPS Server start failed.`;
|
|
450
498
|
}
|
|
451
499
|
|
|
452
500
|
Dynamo_Log.error(msg, this.constructErrors);
|
|
501
|
+
|
|
453
502
|
throw new Dynamo_Error({
|
|
454
503
|
...this._getDefaultErrorSettings(
|
|
455
504
|
'ready',
|
|
@@ -473,18 +522,52 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
473
522
|
}
|
|
474
523
|
|
|
475
524
|
async stop(dontLog?: boolean): Promise<void> {
|
|
476
|
-
|
|
525
|
+
Dynamo_Log.info('\nstoping server...\n');
|
|
526
|
+
|
|
527
|
+
await this.ready();
|
|
528
|
+
|
|
477
529
|
if (this.started) {
|
|
478
530
|
|
|
479
531
|
if (this.systemControls.mongoose.init) {
|
|
532
|
+
Dynamo_Log.info(`\nstopping Mongoose....`);
|
|
533
|
+
|
|
534
|
+
let tryCount: number = 0;
|
|
535
|
+
|
|
536
|
+
while (
|
|
537
|
+
!this.systemControls.mongoose.started &&
|
|
538
|
+
!this.constructErrors.length &&
|
|
539
|
+
tryCount++ < 10
|
|
540
|
+
) {
|
|
541
|
+
Dynamo_Log.warn(`Mongoose not even started yet....`);
|
|
542
|
+
await wait(second);
|
|
543
|
+
}
|
|
480
544
|
this.systemControls.mongoose.started = false;
|
|
481
545
|
|
|
482
546
|
if (this.mongoose) {
|
|
483
|
-
await Dynamo_Array.asyncForEach(
|
|
484
|
-
|
|
547
|
+
await Dynamo_Array.asyncForEach(
|
|
548
|
+
Object.keys(this.mongoose.models),
|
|
549
|
+
async (modelName): Promise<void> => {
|
|
550
|
+
await this.mongoose.deleteModel(modelName);
|
|
551
|
+
}
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
const disconnect: Promise<void> = new Promise((resolve): void => {
|
|
555
|
+
this.mongoose.connection.on('disconnecting', (): void => {
|
|
556
|
+
resolve();
|
|
557
|
+
});
|
|
485
558
|
});
|
|
559
|
+
|
|
486
560
|
await this.mongoose.disconnect();
|
|
487
|
-
|
|
561
|
+
await this.mongoose.connection.close();
|
|
562
|
+
await disconnect;
|
|
563
|
+
|
|
564
|
+
while (
|
|
565
|
+
this.mongoose.connection.readyState !== 0 &&
|
|
566
|
+
!this.constructErrors.length
|
|
567
|
+
) {
|
|
568
|
+
Dynamo_Log.warn(`\nMongoose still not disconnected....`);
|
|
569
|
+
await wait(second);
|
|
570
|
+
}
|
|
488
571
|
} else {
|
|
489
572
|
Dynamo_Log.error(`\nMongoose not found.`);
|
|
490
573
|
}
|
|
@@ -493,8 +576,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
493
576
|
|
|
494
577
|
if (this.systemControls.httpServer.init) {
|
|
495
578
|
this.systemControls.httpServer.started = false;
|
|
579
|
+
|
|
496
580
|
if (this.httpServer) {
|
|
497
|
-
await new Promise((resolve) => {
|
|
581
|
+
await new Promise((resolve): void => {
|
|
498
582
|
this.httpServer.close(resolve);
|
|
499
583
|
});
|
|
500
584
|
} else {
|
|
@@ -505,8 +589,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
505
589
|
|
|
506
590
|
if (this.systemControls.httpsServer.init) {
|
|
507
591
|
this.systemControls.httpsServer.started = false;
|
|
592
|
+
|
|
508
593
|
if (this.httpsServer) {
|
|
509
|
-
await new Promise((resolve) => {
|
|
594
|
+
await new Promise((resolve): void => {
|
|
510
595
|
this.httpsServer.close(resolve);
|
|
511
596
|
});
|
|
512
597
|
} else {
|
|
@@ -525,24 +610,27 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
525
610
|
*
|
|
526
611
|
*/
|
|
527
612
|
private async startDB(): Promise<void> {
|
|
528
|
-
if (this.logFn && this.deepLog)
|
|
613
|
+
if (this.logFn && this.deepLog) Dynamo_Log.log('\nfn:. startDB');
|
|
529
614
|
|
|
530
615
|
await new Promise<void>(
|
|
531
|
-
|
|
616
|
+
(resolve, reject): void => {
|
|
532
617
|
this.systemControls.mongoose.init = true;
|
|
533
618
|
|
|
534
619
|
this.mongoose.connection
|
|
535
|
-
.once('open', () => {
|
|
620
|
+
.once('open', (): void => {
|
|
536
621
|
this.systemControls.mongoose.started = true;
|
|
537
622
|
Dynamo_Log.success('\nConnected to MongoDB\n');
|
|
538
623
|
|
|
539
624
|
resolve();
|
|
540
625
|
})
|
|
541
|
-
.on('error', (error) => {
|
|
626
|
+
.on('error', (error): void => {
|
|
542
627
|
if (!this.systemControls.mongoose.started) {
|
|
543
628
|
this.constructErrors.push(error);
|
|
544
629
|
|
|
545
|
-
if (this.debugLog) Dynamo_Log.error(
|
|
630
|
+
if (this.debugLog) Dynamo_Log.error(
|
|
631
|
+
'\nUnable to connect to MongoDB server, ERROR: ',
|
|
632
|
+
error
|
|
633
|
+
);
|
|
546
634
|
|
|
547
635
|
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
548
636
|
...this._getDefaultErrorSettings(
|
|
@@ -568,6 +656,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
568
656
|
|
|
569
657
|
errorCode: 'NTS-AS0-SDB2',
|
|
570
658
|
message: `MongoDB ERROR: ${error}`,
|
|
659
|
+
level: Dynamo_ErrorLevel.critical,
|
|
571
660
|
});
|
|
572
661
|
|
|
573
662
|
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
@@ -578,7 +667,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
578
667
|
this._params.dbUri,
|
|
579
668
|
{
|
|
580
669
|
useNewUrlParser: true,
|
|
581
|
-
useUnifiedTopology: true
|
|
670
|
+
useUnifiedTopology: true,
|
|
582
671
|
}
|
|
583
672
|
);
|
|
584
673
|
}
|
|
@@ -589,7 +678,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
589
678
|
*
|
|
590
679
|
*/
|
|
591
680
|
private async initExpresses(): Promise<void> {
|
|
592
|
-
if (this.logFn && this.deepLog)
|
|
681
|
+
if (this.logFn && this.deepLog) Dynamo_Log.log('\nfn:. initExpresses');
|
|
593
682
|
|
|
594
683
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
595
684
|
if (!this._portSettings.httpPort) {
|
|
@@ -599,10 +688,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
599
688
|
`\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
|
|
600
689
|
|
|
601
690
|
errorMsg += '\n\nThe routes setted to use open server:';
|
|
602
|
-
this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
|
|
691
|
+
this._routingModules.forEach((module: DynamoNTS_RoutingModule): void => {
|
|
603
692
|
if (module.security != DynamoNTS_RouteSecurity.secure) {
|
|
604
|
-
errorMsg += `\n ${module.route} (security: ${module.security})
|
|
605
|
-
|
|
693
|
+
errorMsg += `\n ${module.route} (security: ${module.security})`;
|
|
694
|
+
errorMsg += `\n subroutes using open sever:`;
|
|
695
|
+
module.endpoints.forEach((endpoint: DynamoNTS_EndpointParams): void => {
|
|
606
696
|
if (endpoint.security != DynamoNTS_RouteSecurity.secure) {
|
|
607
697
|
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
608
698
|
}
|
|
@@ -610,12 +700,14 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
610
700
|
}
|
|
611
701
|
});
|
|
612
702
|
|
|
613
|
-
|
|
614
|
-
|
|
703
|
+
const error = new Error('Open routes cannot be established!');
|
|
704
|
+
const errorStack: string[] = error.stack.split('\n');
|
|
705
|
+
|
|
615
706
|
errorStack.splice(1, 2);
|
|
616
707
|
error.stack = errorStack.join('\n');
|
|
617
708
|
|
|
618
709
|
Dynamo_Log.error(errorMsg);
|
|
710
|
+
|
|
619
711
|
throw error;
|
|
620
712
|
}
|
|
621
713
|
|
|
@@ -637,10 +729,11 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
637
729
|
`\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
|
|
638
730
|
|
|
639
731
|
errorMsg += '\n\nThe routes setted to use secure server:';
|
|
640
|
-
this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
|
|
732
|
+
this._routingModules.forEach((module: DynamoNTS_RoutingModule): void => {
|
|
641
733
|
if (module.security && module.security !== DynamoNTS_RouteSecurity.open) {
|
|
642
|
-
errorMsg += `\n ${module.route} (security: ${module.security})
|
|
643
|
-
|
|
734
|
+
errorMsg += `\n ${module.route} (security: ${module.security})`;
|
|
735
|
+
errorMsg += `\n subroutes using secure sever:`;
|
|
736
|
+
module.endpoints.forEach((endpoint: DynamoNTS_EndpointParams): void => {
|
|
644
737
|
if (endpoint.security && endpoint.security !== DynamoNTS_RouteSecurity.open) {
|
|
645
738
|
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
646
739
|
}
|
|
@@ -648,12 +741,14 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
648
741
|
}
|
|
649
742
|
});
|
|
650
743
|
|
|
651
|
-
|
|
652
|
-
|
|
744
|
+
const error = new Error('Secure routes cannot be established!');
|
|
745
|
+
const errorStack: string[] = error.stack.split('\n');
|
|
746
|
+
|
|
653
747
|
errorStack.splice(1, 2);
|
|
654
748
|
error.stack = errorStack.join('\n');
|
|
655
749
|
|
|
656
750
|
Dynamo_Log.error(errorMsg);
|
|
751
|
+
|
|
657
752
|
throw error;
|
|
658
753
|
}
|
|
659
754
|
|
|
@@ -665,7 +760,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
665
760
|
*
|
|
666
761
|
*/
|
|
667
762
|
protected async initOpenExpress(): Promise<void> {
|
|
668
|
-
if (this.logFn)
|
|
763
|
+
if (this.logFn) Dynamo_Log.log('\nfn:. initOpenExpress');
|
|
669
764
|
this.openExpress = Express();
|
|
670
765
|
this.openExpress.use(BodyParser.urlencoded(this._portSettings.httpUrlencoded));
|
|
671
766
|
this.openExpress.use(BodyParser.json(this._portSettings.httpJson));
|
|
@@ -675,7 +770,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
675
770
|
*
|
|
676
771
|
*/
|
|
677
772
|
protected async initSecureExpress(): Promise<void> {
|
|
678
|
-
if (this.logFn)
|
|
773
|
+
if (this.logFn) Dynamo_Log.log('\nfn:. initSecureExpress');
|
|
679
774
|
this.secureExpress = Express();
|
|
680
775
|
this.secureExpress.use(BodyParser.urlencoded(this._portSettings.httpsUrlencoded));
|
|
681
776
|
this.secureExpress.use(BodyParser.json(this._portSettings.httpsJson));
|
|
@@ -684,6 +779,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
684
779
|
key: FileSystem.readFileSync(this._cert.keyPath),
|
|
685
780
|
cert: FileSystem.readFileSync(this._cert.certPath),
|
|
686
781
|
};
|
|
782
|
+
|
|
687
783
|
this.httpsServer = Https.createServer(options, this.secureExpress);
|
|
688
784
|
}
|
|
689
785
|
|
|
@@ -691,19 +787,21 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
691
787
|
*
|
|
692
788
|
*/
|
|
693
789
|
private async startExpresses(): Promise<void> {
|
|
694
|
-
if (this.logFn && this.deepLog)
|
|
790
|
+
if (this.logFn && this.deepLog) Dynamo_Log.log('\nfn:. startExpresses');
|
|
695
791
|
try {
|
|
696
792
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.open) {
|
|
697
|
-
await new Promise<void>((resolve, reject) => {
|
|
793
|
+
await new Promise<void>((resolve, reject): void => {
|
|
698
794
|
this.systemControls.httpsServer.init = true;
|
|
699
795
|
this.httpsServer
|
|
700
|
-
.listen(this._portSettings.httpsPort, 'localhost', 0, () => {
|
|
796
|
+
.listen(this._portSettings.httpsPort, 'localhost', 0, (): void => {
|
|
701
797
|
this.systemControls.httpsServer.started = true;
|
|
702
|
-
Dynamo_Log.success(
|
|
798
|
+
Dynamo_Log.success(
|
|
799
|
+
`\nHTTPS (secure) server is listening on port: ${this._portSettings.httpsPort}`
|
|
800
|
+
);
|
|
703
801
|
|
|
704
802
|
resolve();
|
|
705
803
|
})
|
|
706
|
-
.on('error', (error) => {
|
|
804
|
+
.on('error', (error): void => {
|
|
707
805
|
if (this.debugLog) Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error);
|
|
708
806
|
|
|
709
807
|
if (!this.systemControls.httpsServer.started) {
|
|
@@ -731,23 +829,28 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
731
829
|
|
|
732
830
|
errorCode: 'NTS-AS0-SE2',
|
|
733
831
|
message: `HTTPS (secure) server ERROR`,
|
|
832
|
+
level: Dynamo_ErrorLevel.serious,
|
|
734
833
|
});
|
|
735
834
|
|
|
736
835
|
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
737
836
|
}
|
|
738
837
|
})
|
|
739
|
-
.on('uncaughtException', (
|
|
838
|
+
.on('uncaughtException', (exception): void => {
|
|
740
839
|
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
741
840
|
...this._getDefaultErrorSettings(
|
|
742
841
|
'httpsServer.on(uncaughtException)',
|
|
743
|
-
|
|
842
|
+
exception
|
|
744
843
|
),
|
|
745
844
|
|
|
746
845
|
errorCode: 'NTS-AS0-SE3',
|
|
747
846
|
message: `HTTPS (secure) server uncaughtException`,
|
|
847
|
+
level: Dynamo_ErrorLevel.critical,
|
|
748
848
|
});
|
|
749
849
|
|
|
750
|
-
if (this.debugLog) Dynamo_Log.warn(
|
|
850
|
+
if (this.debugLog) Dynamo_Log.warn(
|
|
851
|
+
`\nHTTPS (secure) server uncaughtException`,
|
|
852
|
+
d_error
|
|
853
|
+
);
|
|
751
854
|
|
|
752
855
|
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
753
856
|
});
|
|
@@ -756,15 +859,17 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
756
859
|
|
|
757
860
|
if (this._security && this._security !== DynamoNTS_RouteSecurity.secure) {
|
|
758
861
|
this.systemControls.httpServer.init = true;
|
|
759
|
-
await new Promise<void>((resolve, reject) => {
|
|
862
|
+
await new Promise<void>((resolve, reject): void => {
|
|
760
863
|
this.httpServer = this.openExpress
|
|
761
|
-
.listen(this._portSettings.httpPort, () => {
|
|
864
|
+
.listen(this._portSettings.httpPort, (): void => {
|
|
762
865
|
this.systemControls.httpServer.started = true;
|
|
763
|
-
Dynamo_Log.success(
|
|
866
|
+
Dynamo_Log.success(
|
|
867
|
+
`\nHTTP (open) server is listening on port: ${this._portSettings.httpPort}`
|
|
868
|
+
);
|
|
764
869
|
|
|
765
870
|
resolve();
|
|
766
871
|
})
|
|
767
|
-
.on('error', (error) => {
|
|
872
|
+
.on('error', (error): void => {
|
|
768
873
|
if (this.debugLog) Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
|
|
769
874
|
|
|
770
875
|
if (!this.systemControls.httpServer.started) {
|
|
@@ -792,12 +897,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
792
897
|
|
|
793
898
|
errorCode: 'NTS-AS0-SE4',
|
|
794
899
|
message: `HTTP (open) server ERROR`,
|
|
900
|
+
level: Dynamo_ErrorLevel.serious,
|
|
795
901
|
});
|
|
796
902
|
|
|
797
903
|
DynamoNTS_GlobalService.globalErrorHandler?.(d_error);
|
|
798
904
|
}
|
|
799
905
|
})
|
|
800
|
-
.on('uncaughtException', (ex) => {
|
|
906
|
+
.on('uncaughtException', (ex): void => {
|
|
801
907
|
const d_error: Dynamo_Error = new Dynamo_Error({
|
|
802
908
|
...this._getDefaultErrorSettings(
|
|
803
909
|
'httpServer.on(uncaughtException)',
|
|
@@ -806,6 +912,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
806
912
|
|
|
807
913
|
errorCode: 'NTS-AS0-SE5',
|
|
808
914
|
message: `HTTP (open) server uncaughtException`,
|
|
915
|
+
level: Dynamo_ErrorLevel.critical,
|
|
809
916
|
});
|
|
810
917
|
|
|
811
918
|
if (this.debugLog) Dynamo_Log.warn(`\nHTTP (open) server uncaughtException`, d_error);
|
|
@@ -816,6 +923,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
816
923
|
}
|
|
817
924
|
} catch (error) {
|
|
818
925
|
Dynamo_Log.error(`startExpresses failed...`, error);
|
|
926
|
+
|
|
819
927
|
throw error;
|
|
820
928
|
}
|
|
821
929
|
}
|
|
@@ -838,6 +946,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
838
946
|
req,
|
|
839
947
|
res,
|
|
840
948
|
},
|
|
949
|
+
level: Dynamo_ErrorLevel.error,
|
|
841
950
|
});
|
|
842
951
|
|
|
843
952
|
await DynamoNTS_GlobalService.globalErrorHandler?.(d_error, req, res);
|
|
@@ -862,90 +971,102 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
862
971
|
*
|
|
863
972
|
*/
|
|
864
973
|
private async mountSecureRoutes (): Promise<void> {
|
|
865
|
-
if (this.logFn && this.deepLog)
|
|
974
|
+
if (this.logFn && this.deepLog) Dynamo_Log.log('\nfn:. mountSecureRoutes');
|
|
866
975
|
|
|
867
|
-
this.openExpress.use(
|
|
976
|
+
this.openExpress.use(
|
|
977
|
+
(error, req, res, next): Promise<void> => this.expressErrorHandling(error, req, res, next)
|
|
978
|
+
);
|
|
868
979
|
|
|
869
|
-
await Dynamo_Array.asyncForEach(
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
980
|
+
await Dynamo_Array.asyncForEach(
|
|
981
|
+
this._routingModules,
|
|
982
|
+
async (module: DynamoNTS_RoutingModule): Promise<void> => {
|
|
983
|
+
if (module.security !== DynamoNTS_RouteSecurity.open) {
|
|
984
|
+
if (this.logSetup) {
|
|
985
|
+
Dynamo_Log.log(`route mount (secure): ${module.route}`);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
const existingRoutes: DynamoNTS_RoutingModule[] = this._routingModules.filter(
|
|
989
|
+
(mod: DynamoNTS_RoutingModule): boolean => mod.route === module.route
|
|
990
|
+
);
|
|
878
991
|
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
894
|
-
});
|
|
895
|
-
}
|
|
992
|
+
if (1 < existingRoutes.length) {
|
|
993
|
+
const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
994
|
+
const errorStack: string[] = error.stack.split('\n');
|
|
995
|
+
|
|
996
|
+
errorStack.splice(1, 4);
|
|
997
|
+
error.stack = errorStack.join('\n');
|
|
998
|
+
|
|
999
|
+
Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
1000
|
+
|
|
1001
|
+
throw new Dynamo_Error({
|
|
1002
|
+
...this._getDefaultErrorSettings(
|
|
1003
|
+
'mountSecureRoutes',
|
|
1004
|
+
error
|
|
1005
|
+
),
|
|
896
1006
|
|
|
897
|
-
|
|
1007
|
+
errorCode: 'NTS-AS0-MSR1',
|
|
1008
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
1009
|
+
});
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
this.secureExpress.use(module.route, module.secureRouter);
|
|
1013
|
+
}
|
|
898
1014
|
}
|
|
899
|
-
|
|
1015
|
+
);
|
|
900
1016
|
}
|
|
901
1017
|
|
|
902
1018
|
/**
|
|
903
1019
|
*
|
|
904
1020
|
*/
|
|
905
1021
|
private async mountOpenRoutes(): Promise<void> {
|
|
906
|
-
if (this.logFn && this.deepLog)
|
|
1022
|
+
if (this.logFn && this.deepLog) Dynamo_Log.log('\nfn:. mountOpenRoutes');
|
|
907
1023
|
|
|
908
1024
|
this.openExpress.use(this.expressErrorHandling);
|
|
909
1025
|
|
|
910
|
-
await Dynamo_Array.asyncForEach(
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
1026
|
+
await Dynamo_Array.asyncForEach(
|
|
1027
|
+
this._routingModules,
|
|
1028
|
+
async (module: DynamoNTS_RoutingModule): Promise<void> => {
|
|
1029
|
+
if (module.security !== DynamoNTS_RouteSecurity.secure) {
|
|
1030
|
+
if (this.logSetup) {
|
|
1031
|
+
Dynamo_Log.log(`route mount (open): ${module.route}`);
|
|
1032
|
+
}
|
|
915
1033
|
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
1034
|
+
const existingRoutes: DynamoNTS_RoutingModule[] = this._routingModules.filter(
|
|
1035
|
+
(mod: DynamoNTS_RoutingModule): boolean => mod.route === module.route
|
|
1036
|
+
);
|
|
919
1037
|
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
1038
|
+
if (1 < existingRoutes.length) {
|
|
1039
|
+
const error: Error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
1040
|
+
const errorStack: string[] = error.stack.split('\n');
|
|
1041
|
+
|
|
1042
|
+
errorStack.splice(1, 4);
|
|
1043
|
+
error.stack = errorStack.join('\n');
|
|
1044
|
+
|
|
1045
|
+
Dynamo_Log.error(`ROUTE DUPLICATION: ${module.route}`, error);
|
|
1046
|
+
|
|
1047
|
+
throw new Dynamo_Error({
|
|
1048
|
+
...this._getDefaultErrorSettings(
|
|
1049
|
+
'mountOpenRoutes',
|
|
1050
|
+
error
|
|
1051
|
+
),
|
|
1052
|
+
|
|
1053
|
+
errorCode: 'NTS-AS0-MOR1',
|
|
1054
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
this.openExpress.use(module.route, module.openRouter);
|
|
936
1059
|
}
|
|
937
|
-
|
|
938
|
-
this.openExpress.use(module.route, module.openRouter);
|
|
939
1060
|
}
|
|
940
|
-
|
|
1061
|
+
);
|
|
941
1062
|
}
|
|
942
1063
|
|
|
943
1064
|
/**
|
|
944
1065
|
*
|
|
945
1066
|
*/
|
|
946
1067
|
private setSecurity(): void {
|
|
947
|
-
if (this.logFn && this.deepLog)
|
|
948
|
-
this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
|
|
1068
|
+
if (this.logFn && this.deepLog) Dynamo_Log.log('\nfn:. setSecurity');
|
|
1069
|
+
this._routingModules.forEach((module: DynamoNTS_RoutingModule): void => {
|
|
949
1070
|
if (!module.security) {
|
|
950
1071
|
Dynamo_Log.warn(`RoutingModule security is not set for ${module.route}\n`);
|
|
951
1072
|
|
|
@@ -959,10 +1080,12 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
959
1080
|
|
|
960
1081
|
if (!this._security) {
|
|
961
1082
|
let msg = `Could not set security for the server! (${this.security})`;
|
|
1083
|
+
|
|
962
1084
|
msg += '\n RoutingModules:';
|
|
963
|
-
this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
|
|
1085
|
+
this._routingModules.forEach((module: DynamoNTS_RoutingModule): void => {
|
|
964
1086
|
msg += `\n ${module.route} (security: ${module.security})`;
|
|
965
1087
|
});
|
|
1088
|
+
|
|
966
1089
|
if (this._routingModules.length === 0) {
|
|
967
1090
|
msg += '\n - no RoutingModule found -\n';
|
|
968
1091
|
}
|
|
@@ -970,7 +1093,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
970
1093
|
}
|
|
971
1094
|
}
|
|
972
1095
|
|
|
973
|
-
private _getDefaultErrorSettings(
|
|
1096
|
+
private _getDefaultErrorSettings(
|
|
1097
|
+
fnName: string, error: Error | Dynamo_Error
|
|
1098
|
+
)/* : Dynamo_ErrorSettings */ {
|
|
974
1099
|
return {
|
|
975
1100
|
status: (error as Dynamo_Error)?.___status ?? 500,
|
|
976
1101
|
message: (error as Error)?.message ?? `${fnName} was UNSUCCESFUL (NTS)`,
|
|
@@ -978,7 +1103,8 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
|
|
|
978
1103
|
userMessage: this.defaultErrorUserMsg,
|
|
979
1104
|
issuerService: `${this?.constructor?.name}-DynamoNTS_App`,
|
|
980
1105
|
error: error,
|
|
981
|
-
|
|
1106
|
+
level: Dynamo_ErrorLevel.fatal,
|
|
1107
|
+
};
|
|
982
1108
|
}
|
|
983
1109
|
|
|
984
1110
|
/**
|