@futdevpro/nts-dynamo 1.6.19 → 1.6.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_constants/mocks/app-extended-server.mock.d.ts +29 -0
- package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -0
- package/lib/_constants/mocks/app-extended-server.mock.js +99 -0
- package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -0
- package/lib/_constants/mocks/app-server.mock.d.ts +1 -1
- package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/app-server.mock.js +9 -5
- package/lib/_constants/mocks/app-server.mock.js.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.d.ts +1 -0
- package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
- package/lib/_constants/mocks/socket-server.mock.js +4 -1
- package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
- package/lib/_models/control-models/app-system-controls.control-model copy.d.ts +7 -0
- package/lib/_models/control-models/app-system-controls.control-model copy.d.ts.map +1 -0
- package/lib/_models/control-models/app-system-controls.control-model copy.js +13 -0
- package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -0
- package/lib/_models/control-models/app-system-controls.control-model.d.ts +8 -0
- package/lib/_models/control-models/app-system-controls.control-model.d.ts.map +1 -0
- package/lib/_models/control-models/app-system-controls.control-model.js +14 -0
- package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -0
- package/lib/_models/control-models/system-control.control-model.d.ts +6 -0
- package/lib/_models/control-models/system-control.control-model.d.ts.map +1 -0
- package/lib/_models/control-models/system-control.control-model.js +15 -0
- package/lib/_models/control-models/system-control.control-model.js.map +1 -0
- package/lib/_services/base/db.service.d.ts +1 -2
- package/lib/_services/base/db.service.d.ts.map +1 -1
- package/lib/_services/base/db.service.js +23 -15
- package/lib/_services/base/db.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.d.ts +9 -0
- package/lib/_services/server/app-extended.server.d.ts.map +1 -1
- package/lib/_services/server/app-extended.server.js +230 -81
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app-extended.server.spec.d.ts +2 -0
- package/lib/_services/server/app-extended.server.spec.d.ts.map +1 -0
- package/lib/_services/server/app-extended.server.spec.js +39 -0
- package/lib/_services/server/app-extended.server.spec.js.map +1 -0
- package/lib/_services/server/app.server.d.ts +17 -17
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +401 -275
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/server/app.server.spec.js +17 -5
- package/lib/_services/server/app.server.spec.js.map +1 -1
- package/lib/_services/shared.service.spec.js +7 -1
- package/lib/_services/shared.service.spec.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +5 -3
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +32 -7
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/_constants/mocks/app-extended-server.mock.ts +113 -0
- package/src/_constants/mocks/app-server.mock.ts +7 -5
- package/src/_constants/mocks/socket-server.mock.ts +5 -1
- package/src/_models/control-models/app-system-controls.control-model copy.ts +9 -0
- package/src/_models/control-models/app-system-controls.control-model.ts +9 -0
- package/src/_models/control-models/system-control.control-model.ts +13 -0
- package/src/_services/base/db.service.ts +25 -15
- package/src/_services/server/app-extended.server.spec.ts +45 -0
- package/src/_services/server/app-extended.server.ts +208 -41
- package/src/_services/server/app.server.spec.ts +17 -7
- package/src/_services/server/app.server.ts +277 -167
- package/src/_services/shared.service.spec.ts +10 -1
- package/src/_services/socket/socket-server.service.ts +36 -11
|
@@ -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,160 +169,223 @@ 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.
|
|
180
|
-
this.initDone = false;
|
|
181
|
-
this.haveMongoose = false;
|
|
182
|
-
this.mongooseStarted = false;
|
|
183
|
-
this.haveHttpServer = false;
|
|
184
|
-
this.httpServerStarted = false;
|
|
185
|
-
this.haveHttpsServer = false;
|
|
186
|
-
this.httpsServerStarted = false;
|
|
181
|
+
this.systemControls = new app_system_controls_control_model_1.DynamoNTS_AppSystemControls();
|
|
187
182
|
this.constructErrors = [];
|
|
188
183
|
this.mongoose = Mongoose;
|
|
189
184
|
this._routingModules = [];
|
|
190
185
|
/* protected get routingModules(): DynamoNTS_RoutingModule[] { return this._routingModules; } */
|
|
191
186
|
this._rootServices = [];
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
this.
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
if (this.getRoutingModules) {
|
|
207
|
-
this._routingModules = this.getRoutingModules();
|
|
208
|
-
}
|
|
209
|
-
if (this.createEntries) {
|
|
210
|
-
this.createEntries();
|
|
211
|
-
}
|
|
212
|
-
console.log(`\n\n\nStarting ${this._params.name}... `);
|
|
213
|
-
if (this._params.title) {
|
|
214
|
-
console.log(this._params.title);
|
|
215
|
-
}
|
|
216
|
-
console.log(`Version: ${this._params.version}\n`);
|
|
217
|
-
this.startDB();
|
|
218
|
-
this.getGlobalServiceCollection();
|
|
219
|
-
this.debugLog = global_settings_const_1.dynamoNTS_globalSettings.logSetup;
|
|
220
|
-
this.setSecurity();
|
|
221
|
-
if ((_a = this._routingModules) === null || _a === void 0 ? void 0 : _a.length) {
|
|
222
|
-
this.initExpresses();
|
|
223
|
-
this.startExpresses();
|
|
224
|
-
if (this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
225
|
-
this.mountOpenRoutes();
|
|
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();
|
|
226
200
|
}
|
|
227
|
-
|
|
228
|
-
|
|
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();
|
|
229
206
|
}
|
|
230
|
-
if (this.
|
|
231
|
-
|
|
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.`);
|
|
232
246
|
}
|
|
233
247
|
}
|
|
234
|
-
|
|
235
|
-
this.
|
|
236
|
-
|
|
237
|
-
if (this.postProcess) {
|
|
238
|
-
this.postProcess();
|
|
248
|
+
catch (error) {
|
|
249
|
+
this.constructErrors.push(error);
|
|
250
|
+
fsm_dynamo_1.Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
|
|
239
251
|
}
|
|
240
|
-
|
|
241
|
-
this.ready();
|
|
242
|
-
}
|
|
243
|
-
catch (error) {
|
|
244
|
-
this.constructErrors.push(error);
|
|
245
|
-
fsm_dynamo_1.Dynamo_Log.error('\nApplication start failed.\n', error);
|
|
246
|
-
}
|
|
252
|
+
});
|
|
247
253
|
}
|
|
248
254
|
ready(timeout = 4 * fsm_dynamo_1.second) {
|
|
255
|
+
var _a, _b;
|
|
249
256
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
+
});
|
|
269
|
+
}
|
|
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());
|
|
266
284
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
285
|
+
yield (0, fsm_dynamo_1.wait)(100);
|
|
286
|
+
}
|
|
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(),
|
|
271
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
|
+
});
|
|
307
|
+
}
|
|
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
|
+
});
|
|
315
|
+
}
|
|
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.`;
|
|
272
327
|
}
|
|
273
|
-
if (
|
|
274
|
-
|
|
275
|
-
resolve();
|
|
328
|
+
if (this.systemControls.httpServer.init && !this.systemControls.httpServer.started) {
|
|
329
|
+
msg += `\nHTTP Server start failed.`;
|
|
276
330
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
let msg = 'Application start failed. TIMEOUT';
|
|
280
|
-
if (this.haveMongoose && !this.mongooseStarted) {
|
|
281
|
-
msg += '\nMongoose start failed.';
|
|
282
|
-
}
|
|
283
|
-
if (this.haveHttpServer && !this.httpServerStarted) {
|
|
284
|
-
msg += '\nHTTP Server start failed.';
|
|
285
|
-
}
|
|
286
|
-
if (this.haveHttpsServer && !this.httpsServerStarted) {
|
|
287
|
-
msg += '\nHTTPS Server start failed.';
|
|
288
|
-
}
|
|
289
|
-
reject({
|
|
290
|
-
message: 'Application start failed. TIMEOUT',
|
|
291
|
-
errors: this.constructErrors
|
|
292
|
-
});
|
|
331
|
+
if (this.systemControls.httpsServer.init && !this.systemControls.httpsServer.started) {
|
|
332
|
+
msg += `\nHTTPS Server start failed.`;
|
|
293
333
|
}
|
|
294
|
-
|
|
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
|
+
});
|
|
341
|
+
}
|
|
295
342
|
});
|
|
296
343
|
}
|
|
297
|
-
stop() {
|
|
344
|
+
stop(dontLog) {
|
|
298
345
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
346
|
+
if (this.logFn)
|
|
347
|
+
console.log('\nfn:. stop');
|
|
299
348
|
if (this.started) {
|
|
300
|
-
if (this.
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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;
|
|
304
361
|
}
|
|
305
|
-
if (this.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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;
|
|
309
385
|
}
|
|
310
|
-
if (
|
|
311
|
-
|
|
312
|
-
yield this.mongoose.deleteModel(modelName);
|
|
313
|
-
}));
|
|
314
|
-
yield this.mongoose.disconnect();
|
|
386
|
+
if (!dontLog) {
|
|
387
|
+
fsm_dynamo_1.Dynamo_Log.test(`${this._params.name} stopped successfully.`);
|
|
315
388
|
}
|
|
316
|
-
this.initDone = false;
|
|
317
|
-
this.haveHttpServer = false;
|
|
318
|
-
this.haveHttpsServer = false;
|
|
319
|
-
this.haveMongoose = false;
|
|
320
|
-
this.mongooseStarted = false;
|
|
321
|
-
this.httpServerStarted = false;
|
|
322
|
-
this.httpsServerStarted = false;
|
|
323
|
-
this.started = false;
|
|
324
|
-
fsm_dynamo_1.Dynamo_Log.success('\nServer stopped.\n');
|
|
325
389
|
}
|
|
326
390
|
});
|
|
327
391
|
}
|
|
@@ -329,140 +393,184 @@ class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
|
|
|
329
393
|
*
|
|
330
394
|
*/
|
|
331
395
|
startDB() {
|
|
332
|
-
this
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
this
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
+
}));
|
|
346
418
|
});
|
|
347
419
|
}
|
|
348
420
|
/**
|
|
349
421
|
*
|
|
350
422
|
*/
|
|
351
423
|
initExpresses() {
|
|
352
|
-
|
|
353
|
-
if (
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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();
|
|
374
451
|
}
|
|
375
|
-
this.
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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();
|
|
405
482
|
}
|
|
406
|
-
|
|
407
|
-
}
|
|
483
|
+
});
|
|
408
484
|
}
|
|
409
485
|
/**
|
|
410
486
|
*
|
|
411
487
|
*/
|
|
412
488
|
initOpenExpress() {
|
|
413
|
-
this
|
|
414
|
-
|
|
415
|
-
|
|
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
|
+
});
|
|
416
496
|
}
|
|
417
497
|
/**
|
|
418
498
|
*
|
|
419
499
|
*/
|
|
420
500
|
initSecureExpress() {
|
|
421
|
-
this
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
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
|
+
});
|
|
429
513
|
}
|
|
430
514
|
/**
|
|
431
515
|
*
|
|
432
516
|
*/
|
|
433
517
|
startExpresses() {
|
|
434
518
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
519
|
+
if (this.logFn && this.deepLog)
|
|
520
|
+
console.log('\nfn:. startExpresses');
|
|
435
521
|
try {
|
|
436
522
|
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.open) {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
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
|
+
});
|
|
450
547
|
});
|
|
451
548
|
}
|
|
452
549
|
if (this._security && this._security !== route_security_enum_1.DynamoNTS_RouteSecurity.secure) {
|
|
453
|
-
this.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
+
});
|
|
466
574
|
});
|
|
467
575
|
}
|
|
468
576
|
}
|
|
@@ -475,70 +583,88 @@ class DynamoNTS_App extends singleton_service_1.DynamoNTS_SingletonService {
|
|
|
475
583
|
*
|
|
476
584
|
*/
|
|
477
585
|
mountSecureRoutes() {
|
|
478
|
-
|
|
479
|
-
if (
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
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);
|
|
490
606
|
}
|
|
491
|
-
|
|
492
|
-
}
|
|
607
|
+
}));
|
|
493
608
|
});
|
|
494
609
|
}
|
|
495
610
|
/**
|
|
496
611
|
*
|
|
497
612
|
*/
|
|
498
613
|
mountOpenRoutes() {
|
|
499
|
-
|
|
500
|
-
if (
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
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);
|
|
511
634
|
}
|
|
512
|
-
|
|
513
|
-
}
|
|
635
|
+
}));
|
|
514
636
|
});
|
|
515
637
|
}
|
|
516
638
|
/**
|
|
517
639
|
*
|
|
518
640
|
*/
|
|
519
641
|
setSecurity() {
|
|
520
|
-
|
|
521
|
-
if (
|
|
522
|
-
|
|
523
|
-
}
|
|
524
|
-
else if (!this._security) {
|
|
525
|
-
this._security = module.security;
|
|
526
|
-
}
|
|
527
|
-
else if (this._security !== module.security) {
|
|
528
|
-
this._security = route_security_enum_1.DynamoNTS_RouteSecurity.both;
|
|
529
|
-
}
|
|
530
|
-
});
|
|
531
|
-
if (!this._security) {
|
|
532
|
-
let msg = `Could not set security for the server! (${this.security})`;
|
|
533
|
-
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');
|
|
534
645
|
this._routingModules.forEach((module) => {
|
|
535
|
-
|
|
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
|
+
}
|
|
536
655
|
});
|
|
537
|
-
if (this.
|
|
538
|
-
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);
|
|
539
666
|
}
|
|
540
|
-
|
|
541
|
-
}
|
|
667
|
+
});
|
|
542
668
|
}
|
|
543
669
|
}
|
|
544
670
|
exports.DynamoNTS_App = DynamoNTS_App;
|