@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
|
@@ -12,6 +12,7 @@ const singleton_service_1 = require("../base/singleton.service");
|
|
|
12
12
|
const route_security_enum_1 = require("../../_enums/route-security.enum");
|
|
13
13
|
const global_service_1 = require("../core/global.service");
|
|
14
14
|
const global_settings_const_1 = require("../../_constants/global-settings.const");
|
|
15
|
+
const app_system_controls_control_model_1 = require("../../_models/control-models/app-system-controls.control-model");
|
|
15
16
|
/**
|
|
16
17
|
* This will be the MAIN service of our server project,
|
|
17
18
|
* follow the types and type instructions while setting up your project
|
|
@@ -168,198 +169,408 @@ const global_settings_const_1 = require("../../_constants/global-settings.const"
|
|
|
168
169
|
*
|
|
169
170
|
*/
|
|
170
171
|
class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
|
|
172
|
+
get started() { return this.systemControls.app.started; }
|
|
173
|
+
get superStarted() { return this.systemControls.app.started; }
|
|
171
174
|
get serverName() { return this.params.name; }
|
|
172
175
|
get params() { return this._params; }
|
|
173
176
|
get security() { return this._security; }
|
|
174
177
|
get ports() { return this._ports; }
|
|
175
178
|
get cert() { return this._cert; }
|
|
176
|
-
constructor() {
|
|
177
|
-
var _a;
|
|
179
|
+
constructor(dontLog) {
|
|
178
180
|
super();
|
|
179
|
-
this.
|
|
181
|
+
this.systemControls = new app_system_controls_control_model_1.DynamoNTS_AppSystemControls();
|
|
182
|
+
this.constructErrors = [];
|
|
180
183
|
this.mongoose = Mongoose;
|
|
181
184
|
this._routingModules = [];
|
|
182
185
|
/* protected get routingModules(): DynamoNTS_RoutingModule[] { return this._routingModules; } */
|
|
183
186
|
this._rootServices = [];
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
this.asyncConstruct(dontLog);
|
|
188
|
+
}
|
|
189
|
+
asyncConstruct(dontLog) {
|
|
190
|
+
var _a;
|
|
191
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
if (this.logFn && this.deepLog)
|
|
193
|
+
console.log('\nfn:. asyncConstruct');
|
|
194
|
+
try {
|
|
195
|
+
this.systemControls.app.init = true;
|
|
196
|
+
this.logSetup = global_settings_const_1.dynamoNTS_globalSettings.logSetup;
|
|
197
|
+
this._params = this.getAppParams();
|
|
198
|
+
if (this.overrideDynamoNTSGlobalSettings) {
|
|
199
|
+
this.overrideDynamoNTSGlobalSettings();
|
|
200
|
+
}
|
|
201
|
+
this.globalService = global_service_1.DynamoNTS_GlobalService.getInstance();
|
|
202
|
+
global_service_1.DynamoNTS_GlobalService.setServices(this.getGlobalServiceCollection());
|
|
203
|
+
global_service_1.DynamoNTS_GlobalService.setParams(this.params);
|
|
204
|
+
if (this.getPortSettings) {
|
|
205
|
+
this._ports = this.getPortSettings();
|
|
206
|
+
}
|
|
207
|
+
if (this.getCertificationSettings) {
|
|
208
|
+
this._cert = this.getCertificationSettings();
|
|
209
|
+
}
|
|
210
|
+
if (this.getRoutingModules) {
|
|
211
|
+
this._routingModules = this.getRoutingModules();
|
|
212
|
+
}
|
|
213
|
+
if (this.createEntries) {
|
|
214
|
+
yield this.createEntries();
|
|
215
|
+
}
|
|
216
|
+
console.log(`\n\n\nStarting ${this._params.name}... `);
|
|
217
|
+
if (this._params.title) {
|
|
218
|
+
console.log(this._params.title);
|
|
219
|
+
}
|
|
220
|
+
console.log(`Version: ${this._params.version}\n`);
|
|
221
|
+
yield this.startDB();
|
|
222
|
+
yield this.getGlobalServiceCollection();
|
|
223
|
+
yield this.setSecurity();
|
|
224
|
+
if ((_a = this._routingModules) === null || _a === void 0 ? void 0 : _a.length) {
|
|
225
|
+
yield this.initExpresses();
|
|
226
|
+
yield this.startExpresses();
|
|
227
|
+
if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
228
|
+
yield this.mountOpenRoutes();
|
|
229
|
+
}
|
|
230
|
+
if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open && this._cert) {
|
|
231
|
+
yield this.mountSecureRoutes();
|
|
232
|
+
}
|
|
233
|
+
if (this.logSetup) {
|
|
234
|
+
console.log(`\nRoutes mounted.... server using security: ${this._security}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (this.getRootServices) {
|
|
238
|
+
this._rootServices = yield this.getRootServices();
|
|
239
|
+
}
|
|
240
|
+
if (this.postProcess) {
|
|
241
|
+
yield this.postProcess();
|
|
242
|
+
}
|
|
243
|
+
yield this.ready();
|
|
244
|
+
if (!dontLog) {
|
|
245
|
+
fsm_dynamo_1.Dynamo_Log.test(`${this._params.name} started successfully.`);
|
|
246
|
+
}
|
|
188
247
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
this._ports = this.getPortSettings();
|
|
248
|
+
catch (error) {
|
|
249
|
+
this.constructErrors.push(error);
|
|
250
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
|
|
193
251
|
}
|
|
194
|
-
|
|
195
|
-
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
ready(timeout = 4 * fsm_dynamo_1.second) {
|
|
255
|
+
var _a, _b;
|
|
256
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
if (this.logFn)
|
|
258
|
+
console.log('\nfn:. ready');
|
|
259
|
+
/* return new Promise<void>(async (resolve, reject) => { */
|
|
260
|
+
let ready = false;
|
|
261
|
+
const start = +new Date();
|
|
262
|
+
if (this.constructErrors.length) {
|
|
263
|
+
if (this.logFn && this.deepLog)
|
|
264
|
+
console.log('\nfn:. ready: throw ERROR-0', this.constructErrors);
|
|
265
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
266
|
+
message: `${this._params.name} start failed. ERRORS`,
|
|
267
|
+
additionalContent: this.constructErrors.length === 1 ? this.constructErrors[0] : { errors: this.constructErrors },
|
|
268
|
+
});
|
|
196
269
|
}
|
|
197
|
-
if (this.
|
|
198
|
-
|
|
270
|
+
if (this.logFn && this.deepLog)
|
|
271
|
+
console.log('\nfn:. ready: bef while', this.systemControls);
|
|
272
|
+
while (!ready && +new Date() - start < timeout) {
|
|
273
|
+
// if (this.logFn && this.deepLog) console.log('\nfn:. ready: while', this.systemControls);
|
|
274
|
+
/* if (this.logFn && this.deepLog) console.log('\nfn:. ready: while', this.systemControls,
|
|
275
|
+
{
|
|
276
|
+
mongoose: this.systemControls.mongoose.getReady(),
|
|
277
|
+
httpServer: this.systemControls.httpServer.getReady(),
|
|
278
|
+
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
279
|
+
}); */
|
|
280
|
+
if (this.systemControls.app.init) {
|
|
281
|
+
ready = (this.systemControls.mongoose.getReady() &&
|
|
282
|
+
this.systemControls.httpServer.getReady() &&
|
|
283
|
+
this.systemControls.httpsServer.getReady());
|
|
284
|
+
}
|
|
285
|
+
yield (0, fsm_dynamo_1.wait)(100);
|
|
199
286
|
}
|
|
200
|
-
if (
|
|
201
|
-
this.
|
|
287
|
+
if (timeout < +new Date() - start) {
|
|
288
|
+
//if (this.logFn && this.deepLog) console.log('\nfn:. ready: throw TIMEOUT', this.constructErrors, this.systemControls);
|
|
289
|
+
if (this.logFn && this.deepLog)
|
|
290
|
+
console.log('\nfn:. ready: throw TIMEOUT', this.constructErrors, this.systemControls, {
|
|
291
|
+
mongoose: this.systemControls.mongoose.getReady(),
|
|
292
|
+
httpServer: this.systemControls.httpServer.getReady(),
|
|
293
|
+
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
294
|
+
});
|
|
295
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
296
|
+
message: `${this._params.name} start failed. TIMEOUT`,
|
|
297
|
+
additionalContent: {
|
|
298
|
+
constructErrors: this.constructErrors,
|
|
299
|
+
systemControls: this.systemControls,
|
|
300
|
+
systemReadies: {
|
|
301
|
+
mongoose: this.systemControls.mongoose.getReady(),
|
|
302
|
+
httpServer: this.systemControls.httpServer.getReady(),
|
|
303
|
+
httpsServer: this.systemControls.httpsServer.getReady(),
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
});
|
|
202
307
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
308
|
+
if (this.constructErrors.length) {
|
|
309
|
+
if (this.logFn && this.deepLog)
|
|
310
|
+
console.log('\nfn:. ready: throw ERROR');
|
|
311
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
312
|
+
message: `${this._params.name} start failed. ERROR`,
|
|
313
|
+
additionalContent: this.constructErrors,
|
|
314
|
+
});
|
|
206
315
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
this.
|
|
215
|
-
|
|
216
|
-
|
|
316
|
+
if (ready) {
|
|
317
|
+
this.systemControls.app.started = true;
|
|
318
|
+
if (this.logFn && this.deepLog)
|
|
319
|
+
console.log('\nfn:. ready: return');
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
this.systemControls.app.started = false;
|
|
324
|
+
let msg = `${this._params.name} start failed. UNKNOWN`;
|
|
325
|
+
if (this.systemControls.mongoose.init && !this.systemControls.mongoose.started) {
|
|
326
|
+
msg += `\nMongoose start failed.`;
|
|
217
327
|
}
|
|
218
|
-
if (this.
|
|
219
|
-
|
|
328
|
+
if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
|
|
329
|
+
msg += `\nHTTP Server start failed.`;
|
|
220
330
|
}
|
|
221
|
-
if (this.
|
|
222
|
-
|
|
331
|
+
if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
|
|
332
|
+
msg += `\nHTTPS Server start failed.`;
|
|
223
333
|
}
|
|
334
|
+
if (this.logFn && this.deepLog)
|
|
335
|
+
console.log('\nfn:. ready: throw UNKNOWN');
|
|
336
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
337
|
+
message: msg,
|
|
338
|
+
additionalContent: this.constructErrors,
|
|
339
|
+
error: (_b = (_a = this.constructErrors) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : new Error(),
|
|
340
|
+
});
|
|
224
341
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
stop(dontLog) {
|
|
345
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
346
|
+
if (this.logFn)
|
|
347
|
+
console.log('\nfn:. stop');
|
|
348
|
+
if (this.started) {
|
|
349
|
+
if (this.systemControls.mongoose.init) {
|
|
350
|
+
this.systemControls.mongoose.started = false;
|
|
351
|
+
if (this.mongoose) {
|
|
352
|
+
yield fsm_dynamo_1.Dynamo_Array.asyncForEach(Object.keys(this.mongoose.models), (modelName) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
353
|
+
yield this.mongoose.deleteModel(modelName);
|
|
354
|
+
}));
|
|
355
|
+
yield this.mongoose.disconnect();
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nMongoose not found.`);
|
|
359
|
+
}
|
|
360
|
+
this.systemControls.mongoose.init = false;
|
|
361
|
+
}
|
|
362
|
+
if (this.systemControls.httpServer.init) {
|
|
363
|
+
this.systemControls.httpServer.started = false;
|
|
364
|
+
if (this.httpServer) {
|
|
365
|
+
yield new Promise((resolve) => {
|
|
366
|
+
this.httpServer.close(resolve);
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nHTTP Server not found.`);
|
|
371
|
+
}
|
|
372
|
+
this.systemControls.httpServer.init = false;
|
|
373
|
+
}
|
|
374
|
+
if (this.systemControls.httpsServer.init) {
|
|
375
|
+
this.systemControls.httpsServer.started = false;
|
|
376
|
+
if (this.httpsServer) {
|
|
377
|
+
yield new Promise((resolve) => {
|
|
378
|
+
this.httpsServer.close(resolve);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nHTTPS Server not found.`);
|
|
383
|
+
}
|
|
384
|
+
this.systemControls.httpsServer.init = false;
|
|
385
|
+
}
|
|
386
|
+
if (!dontLog) {
|
|
387
|
+
fsm_dynamo_1.Dynamo_Log.test(`${this._params.name} stopped successfully.`);
|
|
388
|
+
}
|
|
230
389
|
}
|
|
231
|
-
|
|
232
|
-
}
|
|
233
|
-
catch (error) {
|
|
234
|
-
fsm_dynamo_1.Dynamo_Log.error('\nApplication start failed.\n', error);
|
|
235
|
-
}
|
|
390
|
+
});
|
|
236
391
|
}
|
|
237
392
|
/**
|
|
238
393
|
*
|
|
239
394
|
*/
|
|
240
395
|
startDB() {
|
|
241
|
-
this
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
396
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
397
|
+
if (this.logFn && this.deepLog)
|
|
398
|
+
console.log('\nfn:. startDB');
|
|
399
|
+
yield new Promise((resolve, reject) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
this.systemControls.mongoose.init = true;
|
|
401
|
+
this.mongoose.connection
|
|
402
|
+
.on('error', (error) => {
|
|
403
|
+
this.systemControls.mongoose.started = false;
|
|
404
|
+
this.constructErrors.push(error);
|
|
405
|
+
fsm_dynamo_1.Dynamo_Log.error('\nUnable to connect to MongoDB server, ERROR: ', error);
|
|
406
|
+
reject(error);
|
|
407
|
+
})
|
|
408
|
+
.once('open', () => {
|
|
409
|
+
this.systemControls.mongoose.started = true;
|
|
410
|
+
fsm_dynamo_1.Dynamo_Log.success('\nConnected to MongoDB\n');
|
|
411
|
+
resolve();
|
|
412
|
+
});
|
|
413
|
+
this.mongoose.connect(this._params.dbUri, {
|
|
414
|
+
useNewUrlParser: true,
|
|
415
|
+
useUnifiedTopology: true
|
|
416
|
+
});
|
|
417
|
+
}));
|
|
251
418
|
});
|
|
252
419
|
}
|
|
253
420
|
/**
|
|
254
421
|
*
|
|
255
422
|
*/
|
|
256
423
|
initExpresses() {
|
|
257
|
-
|
|
258
|
-
if (
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
424
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
425
|
+
if (this.logFn && this.deepLog)
|
|
426
|
+
console.log('\nfn:. initExpresses');
|
|
427
|
+
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
428
|
+
if (!this._ports.httpPort) {
|
|
429
|
+
let errorMsg = `\nYou have open routes, but httpPort is not set!` +
|
|
430
|
+
`\nsecurity: ${this._security}` +
|
|
431
|
+
`\nset httpPort in DynamoBEServer - setupRoutingModules() to enable secure routes.`;
|
|
432
|
+
errorMsg += '\n\nThe routes setted to use open server:';
|
|
433
|
+
this._routingModules.forEach((module) => {
|
|
434
|
+
if (module.security != route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
435
|
+
errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using open sever:`;
|
|
436
|
+
module.endpoints.forEach((endpoint) => {
|
|
437
|
+
if (endpoint.security != route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
438
|
+
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
fsm_dynamo_1.Dynamo_Log.error(errorMsg);
|
|
444
|
+
let error = new Error('Open routes cannot be established!');
|
|
445
|
+
let errorStack = error.stack.split('\n');
|
|
446
|
+
errorStack.splice(1, 2);
|
|
447
|
+
error.stack = errorStack.join('\n');
|
|
448
|
+
throw error;
|
|
449
|
+
}
|
|
450
|
+
yield this.initOpenExpress();
|
|
279
451
|
}
|
|
280
|
-
this.
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
452
|
+
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
453
|
+
if (!this._cert || !this._ports.httpsPort) {
|
|
454
|
+
let errorMsg = `\nYou have secure routes, but the certification paths or httpsPort are not set!` +
|
|
455
|
+
`\nsecurity: ${this._security}` +
|
|
456
|
+
`\nset...` +
|
|
457
|
+
`\n httpsPort and` +
|
|
458
|
+
`\n cert: {` +
|
|
459
|
+
`\n keyPath: FileSystem.PathLike,` +
|
|
460
|
+
`\n certPath: FileSystem.PathLike,` +
|
|
461
|
+
`\n }` +
|
|
462
|
+
`\nin DynamoBEServer - getRoutingModules() to enable secure routes.`;
|
|
463
|
+
errorMsg += '\n\nThe routes setted to use secure server:';
|
|
464
|
+
this._routingModules.forEach((module) => {
|
|
465
|
+
if (module.security && module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
466
|
+
errorMsg += `\n ${module.route} (security: ${module.security}) \n subroutes using secure sever:`;
|
|
467
|
+
module.endpoints.forEach((endpoint) => {
|
|
468
|
+
if (endpoint.security && endpoint.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
469
|
+
errorMsg += `\n ${endpoint.endpoint} (security: ${endpoint.security})`;
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
fsm_dynamo_1.Dynamo_Log.error(errorMsg);
|
|
475
|
+
let error = new Error('Secure routes cannot be established!');
|
|
476
|
+
let errorStack = error.stack.split('\n');
|
|
477
|
+
errorStack.splice(1, 2);
|
|
478
|
+
error.stack = errorStack.join('\n');
|
|
479
|
+
throw error;
|
|
480
|
+
}
|
|
481
|
+
yield this.initSecureExpress();
|
|
310
482
|
}
|
|
311
|
-
|
|
312
|
-
}
|
|
483
|
+
});
|
|
313
484
|
}
|
|
314
485
|
/**
|
|
315
486
|
*
|
|
316
487
|
*/
|
|
317
488
|
initOpenExpress() {
|
|
318
|
-
this
|
|
319
|
-
|
|
320
|
-
|
|
489
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
490
|
+
if (this.logFn)
|
|
491
|
+
console.log('\nfn:. initOpenExpress');
|
|
492
|
+
this.openExpress = Express();
|
|
493
|
+
this.openExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
494
|
+
this.openExpress.use(BodyParser.json({ limit: '50mb' }));
|
|
495
|
+
});
|
|
321
496
|
}
|
|
322
497
|
/**
|
|
323
498
|
*
|
|
324
499
|
*/
|
|
325
500
|
initSecureExpress() {
|
|
326
|
-
this
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
501
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
502
|
+
if (this.logFn)
|
|
503
|
+
console.log('\nfn:. initSecureExpress');
|
|
504
|
+
this.secureExpress = Express();
|
|
505
|
+
this.secureExpress.use(BodyParser.urlencoded({ limit: '50mb', extended: true }));
|
|
506
|
+
this.secureExpress.use(BodyParser.json({ limit: '50mb' }));
|
|
507
|
+
const options = {
|
|
508
|
+
key: FileSystem.readFileSync(this._cert.keyPath),
|
|
509
|
+
cert: FileSystem.readFileSync(this._cert.certPath),
|
|
510
|
+
};
|
|
511
|
+
this.httpsServer = Https.createServer(options, this.secureExpress);
|
|
512
|
+
});
|
|
334
513
|
}
|
|
335
514
|
/**
|
|
336
515
|
*
|
|
337
516
|
*/
|
|
338
517
|
startExpresses() {
|
|
339
518
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
519
|
+
if (this.logFn && this.deepLog)
|
|
520
|
+
console.log('\nfn:. startExpresses');
|
|
340
521
|
try {
|
|
341
522
|
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
523
|
+
yield new Promise((resolve, reject) => {
|
|
524
|
+
this.systemControls.httpsServer.init = true;
|
|
525
|
+
this.httpsServer
|
|
526
|
+
.listen(this._ports.httpsPort, 'localhost', 0, () => {
|
|
527
|
+
this.systemControls.httpsServer.started = true;
|
|
528
|
+
fsm_dynamo_1.Dynamo_Log.success(`\nHTTPS (secure) server is listening on port ${this._ports.httpsPort}`);
|
|
529
|
+
resolve();
|
|
530
|
+
})
|
|
531
|
+
.on('error', (error) => {
|
|
532
|
+
this.systemControls.httpsServer.started = false;
|
|
533
|
+
this.constructErrors.push(error);
|
|
534
|
+
/* Dynamo_Log.error(`\nHTTPS (secure) server ERROR`, error); */
|
|
535
|
+
reject(new fsm_dynamo_1.Dynamo_Error({
|
|
536
|
+
message: `HTTPS (secure) server ERROR`,
|
|
537
|
+
error: error,
|
|
538
|
+
}));
|
|
539
|
+
})
|
|
540
|
+
.on('uncaughtException', (ex) => {
|
|
541
|
+
fsm_dynamo_1.Dynamo_Log.warn(`\nHTTPS (secure) server uncaughtException`, ex);
|
|
542
|
+
reject(new fsm_dynamo_1.Dynamo_Error({
|
|
543
|
+
message: `HTTPS (secure) server uncaughtException`,
|
|
544
|
+
error: ex,
|
|
545
|
+
}));
|
|
546
|
+
});
|
|
351
547
|
});
|
|
352
548
|
}
|
|
353
549
|
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
354
|
-
this.
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
550
|
+
this.systemControls.httpServer.init = true;
|
|
551
|
+
yield new Promise((resolve, reject) => {
|
|
552
|
+
this.httpServer = this.openExpress
|
|
553
|
+
.listen(this._ports.httpPort, () => {
|
|
554
|
+
this.systemControls.httpServer.started = true;
|
|
555
|
+
fsm_dynamo_1.Dynamo_Log.success(`\nHTTP (open) server is listening on port ${this._ports.httpPort}`);
|
|
556
|
+
resolve();
|
|
557
|
+
})
|
|
558
|
+
.on('error', (error) => {
|
|
559
|
+
this.systemControls.httpServer.started = false;
|
|
560
|
+
this.constructErrors.push(error);
|
|
561
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nHTTP (open) server ERROR`, error);
|
|
562
|
+
reject(new fsm_dynamo_1.Dynamo_Error({
|
|
563
|
+
message: `HTTP (open) server ERROR`,
|
|
564
|
+
error: error,
|
|
565
|
+
}));
|
|
566
|
+
})
|
|
567
|
+
.on('uncaughtException', (ex) => {
|
|
568
|
+
fsm_dynamo_1.Dynamo_Log.warn(`\nHTTP (open) server uncaughtException`, ex);
|
|
569
|
+
reject(new fsm_dynamo_1.Dynamo_Error({
|
|
570
|
+
message: `HTTP (open) server uncaughtException`,
|
|
571
|
+
error: ex
|
|
572
|
+
}));
|
|
573
|
+
});
|
|
363
574
|
});
|
|
364
575
|
}
|
|
365
576
|
}
|
|
@@ -372,70 +583,88 @@ class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
|
|
|
372
583
|
*
|
|
373
584
|
*/
|
|
374
585
|
mountSecureRoutes() {
|
|
375
|
-
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
586
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
587
|
+
if (this.logFn && this.deepLog)
|
|
588
|
+
console.log('\nfn:. mountSecureRoutes');
|
|
589
|
+
yield fsm_dynamo_1.Dynamo_Array.asyncForEach(this._routingModules, (module) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
590
|
+
if (module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
591
|
+
if (this.logSetup) {
|
|
592
|
+
console.log(`route mount (secure): ${module.route}`);
|
|
593
|
+
}
|
|
594
|
+
const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
|
|
595
|
+
if (1 < existingRoutes.length) {
|
|
596
|
+
let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
597
|
+
let errorStack = error.stack.split('\n');
|
|
598
|
+
errorStack.splice(1, 4);
|
|
599
|
+
error.stack = errorStack.join('\n');
|
|
600
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
601
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
602
|
+
error: error,
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
this.secureExpress.use(module.route, module.secureRouter);
|
|
387
606
|
}
|
|
388
|
-
|
|
389
|
-
}
|
|
607
|
+
}));
|
|
390
608
|
});
|
|
391
609
|
}
|
|
392
610
|
/**
|
|
393
611
|
*
|
|
394
612
|
*/
|
|
395
613
|
mountOpenRoutes() {
|
|
396
|
-
|
|
397
|
-
if (
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
614
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
615
|
+
if (this.logFn && this.deepLog)
|
|
616
|
+
console.log('\nfn:. mountOpenRoutes');
|
|
617
|
+
yield fsm_dynamo_1.Dynamo_Array.asyncForEach(this._routingModules, (module) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
618
|
+
if (module.security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
619
|
+
if (this.logSetup) {
|
|
620
|
+
console.log(`route mount (open): ${module.route}`);
|
|
621
|
+
}
|
|
622
|
+
const existingRoutes = this._routingModules.filter((mod) => mod.route === module.route);
|
|
623
|
+
if (1 < existingRoutes.length) {
|
|
624
|
+
let error = new Error(`ROUTE DUPLICATION: ${module.route}`);
|
|
625
|
+
let errorStack = error.stack.split('\n');
|
|
626
|
+
errorStack.splice(1, 4);
|
|
627
|
+
error.stack = errorStack.join('\n');
|
|
628
|
+
throw new fsm_dynamo_1.Dynamo_Error({
|
|
629
|
+
message: `ROUTE DUPLICATION: ${module.route}`,
|
|
630
|
+
error: error,
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
this.openExpress.use(module.route, module.openRouter);
|
|
408
634
|
}
|
|
409
|
-
|
|
410
|
-
}
|
|
635
|
+
}));
|
|
411
636
|
});
|
|
412
637
|
}
|
|
413
638
|
/**
|
|
414
639
|
*
|
|
415
640
|
*/
|
|
416
641
|
setSecurity() {
|
|
417
|
-
|
|
418
|
-
if (
|
|
419
|
-
|
|
420
|
-
}
|
|
421
|
-
else if (!this._security) {
|
|
422
|
-
this._security = module.security;
|
|
423
|
-
}
|
|
424
|
-
else if (this._security !== module.security) {
|
|
425
|
-
this._security = route_security_enum_1.DynamoNTS_RouteSecurity.both;
|
|
426
|
-
}
|
|
427
|
-
});
|
|
428
|
-
if (!this._security) {
|
|
429
|
-
let msg = `Could not set security for the server! (${this.security})`;
|
|
430
|
-
msg += '\n RoutingModules:';
|
|
642
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
643
|
+
if (this.logFn && this.deepLog)
|
|
644
|
+
console.log('\nfn:. setSecurity');
|
|
431
645
|
this._routingModules.forEach((module) => {
|
|
432
|
-
|
|
646
|
+
if (!module.security) {
|
|
647
|
+
fsm_dynamo_1.Dynamo_Log.error(`RoutingModule security is not set for ${module.route}\n`);
|
|
648
|
+
}
|
|
649
|
+
else if (!this._security) {
|
|
650
|
+
this._security = module.security;
|
|
651
|
+
}
|
|
652
|
+
else if (this._security !== module.security) {
|
|
653
|
+
this._security = route_security_enum_1.DynamoNTS_RouteSecurity.both;
|
|
654
|
+
}
|
|
433
655
|
});
|
|
434
|
-
if (this.
|
|
435
|
-
msg
|
|
656
|
+
if (!this._security) {
|
|
657
|
+
let msg = `Could not set security for the server! (${this.security})`;
|
|
658
|
+
msg += '\n RoutingModules:';
|
|
659
|
+
this._routingModules.forEach((module) => {
|
|
660
|
+
msg += `\n ${module.route} (security: ${module.security})`;
|
|
661
|
+
});
|
|
662
|
+
if (this._routingModules.length === 0) {
|
|
663
|
+
msg += '\n - no RoutingModule found -\n';
|
|
664
|
+
}
|
|
665
|
+
fsm_dynamo_1.Dynamo_Log.warn(msg);
|
|
436
666
|
}
|
|
437
|
-
|
|
438
|
-
}
|
|
667
|
+
});
|
|
439
668
|
}
|
|
440
669
|
}
|
|
441
670
|
exports.DynamoNTS_App = DynamoNTS_App;
|