opticore-webapp 1.0.17 → 1.0.19
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/dist/index.cjs +191 -59
- package/dist/index.d.cts +12 -6
- package/dist/index.d.ts +12 -6
- package/dist/index.js +192 -56
- package/package.json +7 -7
- package/src/application/service/serverStartError.service.ts +112 -0
- package/src/core/handlers/eventProcess.handler.ts +15 -14
- package/src/core/helpers/modulesLoaded.utils.ts +8 -8
- package/src/core/webServer.core.ts +64 -35
package/dist/index.cjs
CHANGED
|
@@ -42,12 +42,10 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
|
42
42
|
var path2 = __toESM(require("path"), 1);
|
|
43
43
|
var import_module = require("module");
|
|
44
44
|
var import_cors = __toESM(require("cors"), 1);
|
|
45
|
-
var
|
|
45
|
+
var import_opticore_catch_exception_error4 = require("opticore-catch-exception-error");
|
|
46
46
|
var import_opticore_express2 = require("opticore-express");
|
|
47
47
|
var import_opticore_env_access = require("opticore-env-access");
|
|
48
|
-
var
|
|
49
|
-
var import_opticore_http_response2 = require("opticore-http-response");
|
|
50
|
-
var import_opticore_translator3 = require("opticore-translator");
|
|
48
|
+
var import_opticore_translator4 = require("opticore-translator");
|
|
51
49
|
|
|
52
50
|
// src/core/handlers/eventProcess.handler.ts
|
|
53
51
|
var import_node_process = __toESM(require("process"), 1);
|
|
@@ -57,49 +55,50 @@ var import_opticore_catch_exception_error = require("opticore-catch-exception-er
|
|
|
57
55
|
function eventProcessHandler(localeLanguage) {
|
|
58
56
|
const errorEmitter = new import_node_events.default();
|
|
59
57
|
const app = (0, import_opticore_express.express)();
|
|
58
|
+
const serverListenEvent = new import_opticore_catch_exception_error.ServerListenEventError(localeLanguage);
|
|
60
59
|
errorEmitter.on(import_opticore_catch_exception_error.CEventNameError.error, (error) => {
|
|
61
|
-
|
|
60
|
+
serverListenEvent.listenerError(error);
|
|
62
61
|
});
|
|
63
62
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.beforeExit, (code) => {
|
|
64
63
|
setTimeout(() => {
|
|
65
|
-
|
|
64
|
+
serverListenEvent.processBeforeExit(code);
|
|
66
65
|
}, 100);
|
|
67
66
|
});
|
|
68
67
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.disconnect, () => {
|
|
69
|
-
|
|
68
|
+
serverListenEvent.processDisconnected();
|
|
70
69
|
});
|
|
71
70
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.exit, (code) => {
|
|
72
|
-
|
|
71
|
+
serverListenEvent.exited(code);
|
|
73
72
|
});
|
|
74
73
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.rejectionHandled, (promise) => {
|
|
75
|
-
|
|
74
|
+
serverListenEvent.promiseRejectionHandled(promise);
|
|
76
75
|
});
|
|
77
76
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.uncaughtException, (error) => {
|
|
78
|
-
|
|
77
|
+
serverListenEvent.uncaughtException(error);
|
|
79
78
|
});
|
|
80
79
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.uncaughtExceptionMonitor, (error) => {
|
|
81
|
-
|
|
80
|
+
serverListenEvent.uncaughtExceptionMonitor(error);
|
|
82
81
|
});
|
|
83
82
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.unhandledRejection, (reason, promise) => {
|
|
84
|
-
|
|
83
|
+
serverListenEvent.unhandledRejection(reason, promise);
|
|
85
84
|
});
|
|
86
85
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.warning, (warning) => {
|
|
87
|
-
|
|
86
|
+
serverListenEvent.warning(warning);
|
|
88
87
|
});
|
|
89
88
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.message, (message) => {
|
|
90
|
-
|
|
89
|
+
serverListenEvent.message(message);
|
|
91
90
|
});
|
|
92
91
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.multipleResolves, (type, promise, reason) => {
|
|
93
|
-
|
|
92
|
+
serverListenEvent.multipleResolves(type, promise, reason);
|
|
94
93
|
});
|
|
95
94
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.sigint, () => {
|
|
96
|
-
|
|
95
|
+
serverListenEvent.processInterrupted();
|
|
97
96
|
});
|
|
98
97
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.sigterm, (signal) => {
|
|
99
|
-
|
|
98
|
+
serverListenEvent.sigtermSignalReceived(signal);
|
|
100
99
|
});
|
|
101
100
|
app.use((err, req, res, next) => {
|
|
102
|
-
|
|
101
|
+
serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
103
102
|
});
|
|
104
103
|
}
|
|
105
104
|
|
|
@@ -142,15 +141,15 @@ var LogMessageUtils = class {
|
|
|
142
141
|
|
|
143
142
|
// src/core/helpers/modulesLoaded.utils.ts
|
|
144
143
|
var import_opticore_translator = require("opticore-translator");
|
|
145
|
-
function modulesLoadedUtils(allAppRoutes, dbConChecker, localeLanguage
|
|
144
|
+
function modulesLoadedUtils(allAppRoutes, dbConChecker, localeLanguage) {
|
|
146
145
|
LogMessageUtils.success(
|
|
147
|
-
`${import_opticore_translator.TranslationLoader.t("kernel", localeLanguage
|
|
148
|
-
`${import_opticore_translator.TranslationLoader.t("loadKernel", localeLanguage
|
|
149
|
-
`${import_opticore_translator.TranslationLoader.t("moduleAppLoaded", localeLanguage
|
|
146
|
+
`${import_opticore_translator.TranslationLoader.t("kernel", localeLanguage)}`,
|
|
147
|
+
`${import_opticore_translator.TranslationLoader.t("loadKernel", localeLanguage)}`,
|
|
148
|
+
`${import_opticore_translator.TranslationLoader.t("moduleAppLoaded", localeLanguage)}`
|
|
150
149
|
);
|
|
151
|
-
console.log(`${import_ansi_colors2.default.whiteBright(` ${import_opticore_translator.TranslationLoader.t("content", localeLanguage
|
|
152
|
-
allAppRoutes ? console.log(`${import_ansi_colors2.default.whiteBright(` ${import_opticore_translator.TranslationLoader.t("content", localeLanguage
|
|
153
|
-
typeof dbConChecker == "function" ? console.log(`${import_ansi_colors2.default.whiteBright(` ${import_opticore_translator.TranslationLoader.t("content", localeLanguage
|
|
150
|
+
console.log(`${import_ansi_colors2.default.whiteBright(` ${import_opticore_translator.TranslationLoader.t("content", localeLanguage)}`)} ${import_ansi_colors2.default.green(`${import_opticore_translator.TranslationLoader.t("kernel", localeLanguage)} :`)} ${import_ansi_colors2.default.cyan(`${import_ansi_colors2.default.bold(`${import_opticore_translator.TranslationLoader.t("serverSide", localeLanguage)}`)}`)} ${import_opticore_translator.TranslationLoader.t("hasBeenLoadedSuccessfully", localeLanguage)} ${import_ansi_colors2.default.green(`\u2714`)}`);
|
|
151
|
+
allAppRoutes ? console.log(`${import_ansi_colors2.default.whiteBright(` ${import_opticore_translator.TranslationLoader.t("content", localeLanguage)}`)} ${import_ansi_colors2.default.green(`${import_opticore_translator.TranslationLoader.t("kernel", localeLanguage)} :`)} ${import_ansi_colors2.default.cyan(`${import_ansi_colors2.default.bold(`${import_opticore_translator.TranslationLoader.t("routerService", localeLanguage)}`)} `)} ${import_ansi_colors2.default.green(`\u2714`)}`) : console.log(`${import_ansi_colors2.default.red(`\u2718`)} ${import_ansi_colors2.default.bgRed(` ${import_ansi_colors2.default.bold(`${import_ansi_colors2.default.white(` ${import_opticore_translator.TranslationLoader.t("registerRoutes", localeLanguage)} `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${import_ansi_colors2.default.red(`${import_ansi_colors2.default.bold(` ${import_opticore_translator.TranslationLoader.t("fail", localeLanguage)} `)}`)} ] | [ ${import_ansi_colors2.default.bold(` ${import_opticore_translator.TranslationLoader.t("loading", localeLanguage)} `)} ] - ${import_ansi_colors2.default.red(` ${import_opticore_translator.TranslationLoader.t("routers", localeLanguage)} `)} - ${import_opticore_translator.TranslationLoader.t("registerLoadingFailed", localeLanguage)} `);
|
|
152
|
+
typeof dbConChecker == "function" ? console.log(`${import_ansi_colors2.default.whiteBright(` ${import_opticore_translator.TranslationLoader.t("content", localeLanguage)}`)} ${import_ansi_colors2.default.green(`${import_opticore_translator.TranslationLoader.t("kernel", localeLanguage)} :`)} ${import_ansi_colors2.default.cyan(`${import_ansi_colors2.default.bold(`${import_opticore_translator.TranslationLoader.t("dbConnChecker", localeLanguage)}`)}`)} ${import_opticore_translator.TranslationLoader.t("hasBeenLoadedSuccessfully", localeLanguage)} ${import_ansi_colors2.default.green(`\u2714`)}`) : "";
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
// src/application/service/core.service.ts
|
|
@@ -303,70 +302,206 @@ var CoreService = class {
|
|
|
303
302
|
}
|
|
304
303
|
};
|
|
305
304
|
|
|
305
|
+
// src/application/service/serverStartError.service.ts
|
|
306
|
+
var import_assert = __toESM(require("assert"), 1);
|
|
307
|
+
var import_opticore_catch_exception_error3 = require("opticore-catch-exception-error");
|
|
308
|
+
var import_opticore_http_response2 = require("opticore-http-response");
|
|
309
|
+
var import_opticore_translator3 = require("opticore-translator");
|
|
310
|
+
var SServerStartError = (err) => {
|
|
311
|
+
switch (err.name) {
|
|
312
|
+
case import_opticore_catch_exception_error3.CErrorName.typeError:
|
|
313
|
+
(void 0).javaScriptErrors.typeError(err);
|
|
314
|
+
break;
|
|
315
|
+
case import_opticore_catch_exception_error3.CErrorName.error:
|
|
316
|
+
(void 0).javaScriptErrors.allError(err);
|
|
317
|
+
break;
|
|
318
|
+
case import_opticore_catch_exception_error3.CErrorName.evalError:
|
|
319
|
+
(void 0).javaScriptErrors.evalError(err);
|
|
320
|
+
break;
|
|
321
|
+
case import_opticore_catch_exception_error3.CErrorName.referenceError:
|
|
322
|
+
(void 0).javaScriptErrors.referenceError(err);
|
|
323
|
+
break;
|
|
324
|
+
case import_opticore_catch_exception_error3.CErrorName.rangeError:
|
|
325
|
+
(void 0).javaScriptErrors.rangeError(err);
|
|
326
|
+
break;
|
|
327
|
+
case import_opticore_catch_exception_error3.CErrorName.syntaxError:
|
|
328
|
+
(void 0).javaScriptErrors.syntaxError(err);
|
|
329
|
+
break;
|
|
330
|
+
case import_opticore_catch_exception_error3.CErrorName.uriError:
|
|
331
|
+
(void 0).javaScriptErrors.uRIError(err);
|
|
332
|
+
break;
|
|
333
|
+
case import_opticore_catch_exception_error3.CErrorName.eacces:
|
|
334
|
+
(void 0).systemErrors.eAcces(err);
|
|
335
|
+
break;
|
|
336
|
+
case import_opticore_catch_exception_error3.CErrorName.eaddrinuse:
|
|
337
|
+
(void 0).systemErrors.eAddrInUse(err);
|
|
338
|
+
break;
|
|
339
|
+
case import_opticore_catch_exception_error3.CErrorName.econnrefused:
|
|
340
|
+
(void 0).systemErrors.eConnRefused(err);
|
|
341
|
+
break;
|
|
342
|
+
case import_opticore_catch_exception_error3.CErrorName.econnreset:
|
|
343
|
+
(void 0).systemErrors.eConnReset(err);
|
|
344
|
+
break;
|
|
345
|
+
case import_opticore_catch_exception_error3.CErrorName.eexist:
|
|
346
|
+
(void 0).systemErrors.eExist(err);
|
|
347
|
+
break;
|
|
348
|
+
case import_opticore_catch_exception_error3.CErrorName.eisdir:
|
|
349
|
+
(void 0).systemErrors.eIsDir(err);
|
|
350
|
+
break;
|
|
351
|
+
case import_opticore_catch_exception_error3.CErrorName.emfile:
|
|
352
|
+
(void 0).systemErrors.eMFile(err);
|
|
353
|
+
break;
|
|
354
|
+
case import_opticore_catch_exception_error3.CErrorName.enoent:
|
|
355
|
+
(void 0).systemErrors.eNoEnt(err);
|
|
356
|
+
break;
|
|
357
|
+
case import_opticore_catch_exception_error3.CErrorName.enotdir:
|
|
358
|
+
(void 0).systemErrors.eNotDir(err);
|
|
359
|
+
break;
|
|
360
|
+
case import_opticore_catch_exception_error3.CErrorName.enotEmpty:
|
|
361
|
+
(void 0).systemErrors.eNotEmpty(err);
|
|
362
|
+
break;
|
|
363
|
+
case import_opticore_catch_exception_error3.CErrorName.eperm:
|
|
364
|
+
(void 0).systemErrors.ePerm(err);
|
|
365
|
+
break;
|
|
366
|
+
case import_opticore_catch_exception_error3.CErrorName.epipe:
|
|
367
|
+
(void 0).systemErrors.ePipe(err);
|
|
368
|
+
break;
|
|
369
|
+
case import_opticore_catch_exception_error3.CErrorName.etimedout:
|
|
370
|
+
(void 0).systemErrors.eTimedOut(err);
|
|
371
|
+
break;
|
|
372
|
+
case import_opticore_catch_exception_error3.CErrorName.assertionError:
|
|
373
|
+
(void 0).stackTrace = (void 0).traceError(err.message, err.name, import_opticore_http_response2.HttpStatusCode.NOT_ACCEPTABLE);
|
|
374
|
+
err instanceof import_assert.default.AssertionError ? (void 0).logger.error(
|
|
375
|
+
import_opticore_translator3.TranslationLoader.t((void 0).stackTrace.name, (void 0).localLanguage),
|
|
376
|
+
"AssertionError",
|
|
377
|
+
(void 0).stackTrace.name,
|
|
378
|
+
(void 0).stackTrace.stack,
|
|
379
|
+
import_opticore_http_response2.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
380
|
+
) : (void 0).logger.error(
|
|
381
|
+
import_opticore_translator3.TranslationLoader.t((void 0).stackTrace.name, (void 0).localLanguage),
|
|
382
|
+
"Another Error",
|
|
383
|
+
(void 0).stackTrace.name,
|
|
384
|
+
(void 0).stackTrace.stack,
|
|
385
|
+
import_opticore_http_response2.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
386
|
+
);
|
|
387
|
+
break;
|
|
388
|
+
case import_opticore_catch_exception_error3.CErrorName.errOsslEvpUnsupported:
|
|
389
|
+
(void 0).openSSLErrors.errOsSLEvpUnsupported(err);
|
|
390
|
+
break;
|
|
391
|
+
case import_opticore_catch_exception_error3.CErrorName.errOsslBadDecrypt:
|
|
392
|
+
(void 0).openSSLErrors.errOsSLBadDecrypt(err);
|
|
393
|
+
break;
|
|
394
|
+
case import_opticore_catch_exception_error3.CErrorName.errOsslWrongFinalBlockLength:
|
|
395
|
+
(void 0).openSSLErrors.errOsSLWrongFinalBlockLength(err);
|
|
396
|
+
break;
|
|
397
|
+
case import_opticore_catch_exception_error3.CErrorName.errInvalidArgType:
|
|
398
|
+
(void 0).internalErrors.errInvalidArgType(err);
|
|
399
|
+
break;
|
|
400
|
+
case import_opticore_catch_exception_error3.CErrorName.errInvalidCallback:
|
|
401
|
+
(void 0).internalErrors.errInvalidCallback(err);
|
|
402
|
+
break;
|
|
403
|
+
case import_opticore_catch_exception_error3.CErrorName.errHttpHeadersSent:
|
|
404
|
+
(void 0).internalErrors.errHttpHeadersSent(err);
|
|
405
|
+
break;
|
|
406
|
+
case import_opticore_catch_exception_error3.CErrorName.errStreamDestroyed:
|
|
407
|
+
(void 0).internalErrors.errStreamDestroyed(err);
|
|
408
|
+
break;
|
|
409
|
+
case import_opticore_catch_exception_error3.CErrorName.errTlsCertAltnameInvalid:
|
|
410
|
+
(void 0).internalErrors.errTlsCertAltNameInvalid(err);
|
|
411
|
+
break;
|
|
412
|
+
case import_opticore_catch_exception_error3.CErrorName.errUnsupportedEsmUrlScheme:
|
|
413
|
+
(void 0).internalErrors.errUnsupportedEsmUrlScheme(err);
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
};
|
|
417
|
+
|
|
306
418
|
// src/core/webServer.core.ts
|
|
419
|
+
var import_opticore_request_call_event = require("opticore-request-call-event");
|
|
307
420
|
var WebServerCore = class {
|
|
308
421
|
serverUtility = new CoreService();
|
|
309
422
|
expressApp = (0, import_opticore_express2.express)();
|
|
423
|
+
localLanguage;
|
|
310
424
|
loggerConfig;
|
|
311
425
|
routerExpressApp;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
426
|
+
getEnvironnement;
|
|
427
|
+
environnementPath;
|
|
428
|
+
serverListenEvent;
|
|
429
|
+
javaScriptErrors;
|
|
430
|
+
internalErrors;
|
|
431
|
+
assertionErrors;
|
|
432
|
+
openSSLErrors;
|
|
433
|
+
systemErrors;
|
|
434
|
+
constructor(app, loggerConfig, localLanguage, environnementPath, corsOriginOptions) {
|
|
435
|
+
this.getEnvironnement = (0, import_opticore_env_access.getEnvironnementValue)(environnementPath);
|
|
317
436
|
this.routerExpressApp = app;
|
|
318
437
|
this.loggerConfig = loggerConfig;
|
|
438
|
+
this.localLanguage = localLanguage;
|
|
439
|
+
this.environnementPath = environnementPath;
|
|
319
440
|
this.expressApp.use(import_opticore_express2.express.json());
|
|
320
441
|
this.expressApp.use(import_opticore_express2.express.raw());
|
|
321
442
|
this.expressApp.use(import_opticore_express2.express.text());
|
|
322
443
|
this.expressApp.use(import_opticore_express2.express.urlencoded({ extended: true }));
|
|
323
444
|
this.expressApp.use((0, import_cors.default)(corsOriginOptions));
|
|
324
|
-
this.
|
|
445
|
+
this.serverListenEvent = new import_opticore_catch_exception_error4.ServerListenEventError(localLanguage);
|
|
446
|
+
this.javaScriptErrors = new import_opticore_catch_exception_error4.JavaScriptErrors(localLanguage);
|
|
447
|
+
this.assertionErrors = new import_opticore_catch_exception_error4.AssertionErrors(localLanguage);
|
|
448
|
+
this.internalErrors = new import_opticore_catch_exception_error4.InternalErrors(localLanguage);
|
|
449
|
+
this.openSSLErrors = new import_opticore_catch_exception_error4.OpenSSLErrors(localLanguage);
|
|
450
|
+
this.systemErrors = new import_opticore_catch_exception_error4.SystemErrors(localLanguage);
|
|
451
|
+
this.stackTraceErrorHandling(localLanguage);
|
|
325
452
|
this.translationWebAppLoader();
|
|
326
453
|
}
|
|
327
|
-
onStartServer(routers
|
|
454
|
+
onStartServer(routers) {
|
|
328
455
|
return this.expressApp.listen(
|
|
329
|
-
this.
|
|
330
|
-
this.
|
|
456
|
+
this.getEnvironnement.appHost,
|
|
457
|
+
this.getEnvironnement.appPort,
|
|
331
458
|
() => {
|
|
332
459
|
try {
|
|
333
|
-
if (this.
|
|
334
|
-
|
|
335
|
-
} else if (this.
|
|
336
|
-
|
|
337
|
-
} else if (this.
|
|
338
|
-
|
|
460
|
+
if (this.getEnvironnement.appHost === "" && this.getEnvironnement.appPort === 0) {
|
|
461
|
+
this.serverListenEvent.hostPortUndefined(this.getEnvironnement.appPort);
|
|
462
|
+
} else if (this.getEnvironnement.appHost === "") {
|
|
463
|
+
this.serverListenEvent.hostUndefined(this.getEnvironnement.appHost);
|
|
464
|
+
} else if (this.getEnvironnement.appPort === 0) {
|
|
465
|
+
this.serverListenEvent.portUndefined();
|
|
339
466
|
} else {
|
|
340
467
|
this.registerRoutes(routers);
|
|
341
468
|
}
|
|
342
469
|
} catch (err) {
|
|
343
|
-
|
|
470
|
+
SServerStartError(err);
|
|
344
471
|
}
|
|
345
472
|
}
|
|
346
473
|
);
|
|
347
474
|
}
|
|
348
475
|
//, kernelModule: KernelModuleType
|
|
349
|
-
onListeningOnServerEvent(serverWeb,
|
|
350
|
-
serverWeb.on(
|
|
351
|
-
|
|
352
|
-
}).on(
|
|
353
|
-
|
|
354
|
-
}).on(
|
|
355
|
-
|
|
356
|
-
}).on(
|
|
476
|
+
onListeningOnServerEvent(serverWeb, localLanguage) {
|
|
477
|
+
serverWeb.on(import_opticore_catch_exception_error4.CEventNameError.error, (err) => {
|
|
478
|
+
this.serverListenEvent.onEventError(err);
|
|
479
|
+
}).on(import_opticore_catch_exception_error4.CEventNameError.close, () => {
|
|
480
|
+
this.serverListenEvent.serverClosing();
|
|
481
|
+
}).on(import_opticore_catch_exception_error4.CEventNameError.drop, () => {
|
|
482
|
+
this.serverListenEvent.dropNewConnection();
|
|
483
|
+
}).on(import_opticore_catch_exception_error4.CEventNameError.listening, () => {
|
|
357
484
|
this.infoWebApp();
|
|
358
485
|
});
|
|
359
486
|
}
|
|
360
487
|
onRequestOnServerEvent(serverWeb) {
|
|
361
|
-
serverWeb.on(
|
|
362
|
-
(0,
|
|
488
|
+
serverWeb.on(import_opticore_catch_exception_error4.CEventNameError.request, (req, res) => {
|
|
489
|
+
(0, import_opticore_request_call_event.requestCallsEvent)(
|
|
490
|
+
req,
|
|
491
|
+
res,
|
|
492
|
+
this.getEnvironnement.appHost,
|
|
493
|
+
this.getEnvironnement.appPort,
|
|
494
|
+
dateTimeFormattedUtils,
|
|
495
|
+
this.environnementPath,
|
|
496
|
+
this.localLanguage
|
|
497
|
+
);
|
|
363
498
|
});
|
|
364
499
|
}
|
|
365
500
|
translationWebAppLoader() {
|
|
366
501
|
const require2 = (0, import_module.createRequire)(importMetaUrl);
|
|
367
502
|
const packagePath = path2.dirname(require2.resolve("opticore-webapp"));
|
|
368
503
|
const translateMsgJsonFilePath = path2.join(packagePath, "utils", "translations");
|
|
369
|
-
|
|
504
|
+
import_opticore_translator4.TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
370
505
|
}
|
|
371
506
|
registerRoutes(allFeatureRoutes) {
|
|
372
507
|
allFeatureRoutes.map((router) => {
|
|
@@ -375,24 +510,21 @@ var WebServerCore = class {
|
|
|
375
510
|
});
|
|
376
511
|
});
|
|
377
512
|
}
|
|
378
|
-
stackTraceErrorHandling(
|
|
379
|
-
eventProcessHandler(
|
|
513
|
+
stackTraceErrorHandling(localLanguage) {
|
|
514
|
+
eventProcessHandler(localLanguage);
|
|
380
515
|
}
|
|
381
516
|
infoWebApp() {
|
|
382
517
|
this.serverUtility.infoServer(
|
|
383
518
|
this.serverUtility.getVersions().nodeVersion,
|
|
384
519
|
this.serverUtility.getProjectInfo().startingTime,
|
|
385
|
-
|
|
386
|
-
Number(
|
|
520
|
+
this.getEnvironnement.appHost,
|
|
521
|
+
Number(this.getEnvironnement.appPort),
|
|
387
522
|
this.serverUtility.getUsageMemory().rss,
|
|
388
523
|
this.serverUtility.getUsageMemory().heapUsed,
|
|
389
524
|
this.serverUtility.getUsageMemory().user,
|
|
390
525
|
this.serverUtility.getUsageMemory().system
|
|
391
526
|
);
|
|
392
527
|
}
|
|
393
|
-
traceError(props, name, status2) {
|
|
394
|
-
return new import_opticore_catch_exception_error3.StackTraceError(props, name, status2, true);
|
|
395
|
-
}
|
|
396
528
|
};
|
|
397
529
|
// Annotate the CommonJS export names for ESM import in node:
|
|
398
530
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -11,21 +11,27 @@ interface IRouteDefinition {
|
|
|
11
11
|
declare class WebServerCore {
|
|
12
12
|
private serverUtility;
|
|
13
13
|
private expressApp;
|
|
14
|
+
private readonly localLanguage;
|
|
14
15
|
private readonly loggerConfig;
|
|
15
16
|
private readonly routerExpressApp;
|
|
16
|
-
private readonly
|
|
17
|
-
private readonly
|
|
18
|
-
|
|
17
|
+
private readonly getEnvironnement;
|
|
18
|
+
private readonly environnementPath;
|
|
19
|
+
private serverListenEvent;
|
|
20
|
+
private javaScriptErrors;
|
|
21
|
+
private internalErrors;
|
|
22
|
+
private assertionErrors;
|
|
23
|
+
private openSSLErrors;
|
|
24
|
+
private systemErrors;
|
|
25
|
+
constructor(app: express.Application, loggerConfig: LoggerCore, localLanguage: string, environnementPath: any, corsOriginOptions?: Partial<CorsOptions>);
|
|
19
26
|
onStartServer(routers: {
|
|
20
27
|
featureRoute: IRouteDefinition[];
|
|
21
|
-
}[]
|
|
22
|
-
onListeningOnServerEvent(serverWeb: Server,
|
|
28
|
+
}[]): any;
|
|
29
|
+
onListeningOnServerEvent(serverWeb: Server, localLanguage: string): void;
|
|
23
30
|
onRequestOnServerEvent(serverWeb: Server): void;
|
|
24
31
|
private translationWebAppLoader;
|
|
25
32
|
private registerRoutes;
|
|
26
33
|
private stackTraceErrorHandling;
|
|
27
34
|
private infoWebApp;
|
|
28
|
-
private traceError;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
type KernelModuleType = [{
|
package/dist/index.d.ts
CHANGED
|
@@ -11,21 +11,27 @@ interface IRouteDefinition {
|
|
|
11
11
|
declare class WebServerCore {
|
|
12
12
|
private serverUtility;
|
|
13
13
|
private expressApp;
|
|
14
|
+
private readonly localLanguage;
|
|
14
15
|
private readonly loggerConfig;
|
|
15
16
|
private readonly routerExpressApp;
|
|
16
|
-
private readonly
|
|
17
|
-
private readonly
|
|
18
|
-
|
|
17
|
+
private readonly getEnvironnement;
|
|
18
|
+
private readonly environnementPath;
|
|
19
|
+
private serverListenEvent;
|
|
20
|
+
private javaScriptErrors;
|
|
21
|
+
private internalErrors;
|
|
22
|
+
private assertionErrors;
|
|
23
|
+
private openSSLErrors;
|
|
24
|
+
private systemErrors;
|
|
25
|
+
constructor(app: express.Application, loggerConfig: LoggerCore, localLanguage: string, environnementPath: any, corsOriginOptions?: Partial<CorsOptions>);
|
|
19
26
|
onStartServer(routers: {
|
|
20
27
|
featureRoute: IRouteDefinition[];
|
|
21
|
-
}[]
|
|
22
|
-
onListeningOnServerEvent(serverWeb: Server,
|
|
28
|
+
}[]): any;
|
|
29
|
+
onListeningOnServerEvent(serverWeb: Server, localLanguage: string): void;
|
|
23
30
|
onRequestOnServerEvent(serverWeb: Server): void;
|
|
24
31
|
private translationWebAppLoader;
|
|
25
32
|
private registerRoutes;
|
|
26
33
|
private stackTraceErrorHandling;
|
|
27
34
|
private infoWebApp;
|
|
28
|
-
private traceError;
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
type KernelModuleType = [{
|
package/dist/index.js
CHANGED
|
@@ -4,14 +4,16 @@ import { createRequire } from "module";
|
|
|
4
4
|
import corsOrigin from "cors";
|
|
5
5
|
import {
|
|
6
6
|
CEventNameError as eventName2,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
ServerListenEventError as ServerListenEventError2,
|
|
8
|
+
JavaScriptErrors,
|
|
9
|
+
InternalErrors,
|
|
10
|
+
AssertionErrors,
|
|
11
|
+
OpenSSLErrors,
|
|
12
|
+
SystemErrors
|
|
9
13
|
} from "opticore-catch-exception-error";
|
|
10
14
|
import { express as express2 } from "opticore-express";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { HttpStatusCode } from "opticore-http-response";
|
|
14
|
-
import { TranslationLoader as TranslationLoader3 } from "opticore-translator";
|
|
15
|
+
import { getEnvironnementValue } from "opticore-env-access";
|
|
16
|
+
import { TranslationLoader as TranslationLoader4 } from "opticore-translator";
|
|
15
17
|
|
|
16
18
|
// src/core/handlers/eventProcess.handler.ts
|
|
17
19
|
import process from "node:process";
|
|
@@ -25,49 +27,50 @@ import {
|
|
|
25
27
|
function eventProcessHandler(localeLanguage) {
|
|
26
28
|
const errorEmitter = new EventEmitter();
|
|
27
29
|
const app = express();
|
|
30
|
+
const serverListenEvent = new ServerListenEventError(localeLanguage);
|
|
28
31
|
errorEmitter.on(eventName.error, (error) => {
|
|
29
|
-
|
|
32
|
+
serverListenEvent.listenerError(error);
|
|
30
33
|
});
|
|
31
34
|
process.on(event.beforeExit, (code) => {
|
|
32
35
|
setTimeout(() => {
|
|
33
|
-
|
|
36
|
+
serverListenEvent.processBeforeExit(code);
|
|
34
37
|
}, 100);
|
|
35
38
|
});
|
|
36
39
|
process.on(event.disconnect, () => {
|
|
37
|
-
|
|
40
|
+
serverListenEvent.processDisconnected();
|
|
38
41
|
});
|
|
39
42
|
process.on(event.exit, (code) => {
|
|
40
|
-
|
|
43
|
+
serverListenEvent.exited(code);
|
|
41
44
|
});
|
|
42
45
|
process.on(event.rejectionHandled, (promise) => {
|
|
43
|
-
|
|
46
|
+
serverListenEvent.promiseRejectionHandled(promise);
|
|
44
47
|
});
|
|
45
48
|
process.on(event.uncaughtException, (error) => {
|
|
46
|
-
|
|
49
|
+
serverListenEvent.uncaughtException(error);
|
|
47
50
|
});
|
|
48
51
|
process.on(event.uncaughtExceptionMonitor, (error) => {
|
|
49
|
-
|
|
52
|
+
serverListenEvent.uncaughtExceptionMonitor(error);
|
|
50
53
|
});
|
|
51
54
|
process.on(event.unhandledRejection, (reason, promise) => {
|
|
52
|
-
|
|
55
|
+
serverListenEvent.unhandledRejection(reason, promise);
|
|
53
56
|
});
|
|
54
57
|
process.on(event.warning, (warning) => {
|
|
55
|
-
|
|
58
|
+
serverListenEvent.warning(warning);
|
|
56
59
|
});
|
|
57
60
|
process.on(event.message, (message) => {
|
|
58
|
-
|
|
61
|
+
serverListenEvent.message(message);
|
|
59
62
|
});
|
|
60
63
|
process.on(event.multipleResolves, (type, promise, reason) => {
|
|
61
|
-
|
|
64
|
+
serverListenEvent.multipleResolves(type, promise, reason);
|
|
62
65
|
});
|
|
63
66
|
process.on(event.sigint, () => {
|
|
64
|
-
|
|
67
|
+
serverListenEvent.processInterrupted();
|
|
65
68
|
});
|
|
66
69
|
process.on(event.sigterm, (signal) => {
|
|
67
|
-
|
|
70
|
+
serverListenEvent.sigtermSignalReceived(signal);
|
|
68
71
|
});
|
|
69
72
|
app.use((err, req, res, next) => {
|
|
70
|
-
|
|
73
|
+
serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
71
74
|
});
|
|
72
75
|
}
|
|
73
76
|
|
|
@@ -110,15 +113,15 @@ var LogMessageUtils = class {
|
|
|
110
113
|
|
|
111
114
|
// src/core/helpers/modulesLoaded.utils.ts
|
|
112
115
|
import { TranslationLoader } from "opticore-translator";
|
|
113
|
-
function modulesLoadedUtils(allAppRoutes, dbConChecker, localeLanguage
|
|
116
|
+
function modulesLoadedUtils(allAppRoutes, dbConChecker, localeLanguage) {
|
|
114
117
|
LogMessageUtils.success(
|
|
115
|
-
`${TranslationLoader.t("kernel", localeLanguage
|
|
116
|
-
`${TranslationLoader.t("loadKernel", localeLanguage
|
|
117
|
-
`${TranslationLoader.t("moduleAppLoaded", localeLanguage
|
|
118
|
+
`${TranslationLoader.t("kernel", localeLanguage)}`,
|
|
119
|
+
`${TranslationLoader.t("loadKernel", localeLanguage)}`,
|
|
120
|
+
`${TranslationLoader.t("moduleAppLoaded", localeLanguage)}`
|
|
118
121
|
);
|
|
119
|
-
console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", localeLanguage
|
|
120
|
-
allAppRoutes ? console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", localeLanguage
|
|
121
|
-
typeof dbConChecker == "function" ? console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", localeLanguage
|
|
122
|
+
console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", localeLanguage)}`)} ${colors2.green(`${TranslationLoader.t("kernel", localeLanguage)} :`)} ${colors2.cyan(`${colors2.bold(`${TranslationLoader.t("serverSide", localeLanguage)}`)}`)} ${TranslationLoader.t("hasBeenLoadedSuccessfully", localeLanguage)} ${colors2.green(`\u2714`)}`);
|
|
123
|
+
allAppRoutes ? console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", localeLanguage)}`)} ${colors2.green(`${TranslationLoader.t("kernel", localeLanguage)} :`)} ${colors2.cyan(`${colors2.bold(`${TranslationLoader.t("routerService", localeLanguage)}`)} `)} ${colors2.green(`\u2714`)}`) : console.log(`${colors2.red(`\u2718`)} ${colors2.bgRed(` ${colors2.bold(`${colors2.white(` ${TranslationLoader.t("registerRoutes", localeLanguage)} `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors2.red(`${colors2.bold(` ${TranslationLoader.t("fail", localeLanguage)} `)}`)} ] | [ ${colors2.bold(` ${TranslationLoader.t("loading", localeLanguage)} `)} ] - ${colors2.red(` ${TranslationLoader.t("routers", localeLanguage)} `)} - ${TranslationLoader.t("registerLoadingFailed", localeLanguage)} `);
|
|
124
|
+
typeof dbConChecker == "function" ? console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", localeLanguage)}`)} ${colors2.green(`${TranslationLoader.t("kernel", localeLanguage)} :`)} ${colors2.cyan(`${colors2.bold(`${TranslationLoader.t("dbConnChecker", localeLanguage)}`)}`)} ${TranslationLoader.t("hasBeenLoadedSuccessfully", localeLanguage)} ${colors2.green(`\u2714`)}`) : "";
|
|
122
125
|
}
|
|
123
126
|
|
|
124
127
|
// src/application/service/core.service.ts
|
|
@@ -271,70 +274,206 @@ var CoreService = class {
|
|
|
271
274
|
}
|
|
272
275
|
};
|
|
273
276
|
|
|
277
|
+
// src/application/service/serverStartError.service.ts
|
|
278
|
+
import assert from "assert";
|
|
279
|
+
import { CErrorName } from "opticore-catch-exception-error";
|
|
280
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
281
|
+
import { TranslationLoader as TranslationLoader3 } from "opticore-translator";
|
|
282
|
+
var SServerStartError = (err) => {
|
|
283
|
+
switch (err.name) {
|
|
284
|
+
case CErrorName.typeError:
|
|
285
|
+
(void 0).javaScriptErrors.typeError(err);
|
|
286
|
+
break;
|
|
287
|
+
case CErrorName.error:
|
|
288
|
+
(void 0).javaScriptErrors.allError(err);
|
|
289
|
+
break;
|
|
290
|
+
case CErrorName.evalError:
|
|
291
|
+
(void 0).javaScriptErrors.evalError(err);
|
|
292
|
+
break;
|
|
293
|
+
case CErrorName.referenceError:
|
|
294
|
+
(void 0).javaScriptErrors.referenceError(err);
|
|
295
|
+
break;
|
|
296
|
+
case CErrorName.rangeError:
|
|
297
|
+
(void 0).javaScriptErrors.rangeError(err);
|
|
298
|
+
break;
|
|
299
|
+
case CErrorName.syntaxError:
|
|
300
|
+
(void 0).javaScriptErrors.syntaxError(err);
|
|
301
|
+
break;
|
|
302
|
+
case CErrorName.uriError:
|
|
303
|
+
(void 0).javaScriptErrors.uRIError(err);
|
|
304
|
+
break;
|
|
305
|
+
case CErrorName.eacces:
|
|
306
|
+
(void 0).systemErrors.eAcces(err);
|
|
307
|
+
break;
|
|
308
|
+
case CErrorName.eaddrinuse:
|
|
309
|
+
(void 0).systemErrors.eAddrInUse(err);
|
|
310
|
+
break;
|
|
311
|
+
case CErrorName.econnrefused:
|
|
312
|
+
(void 0).systemErrors.eConnRefused(err);
|
|
313
|
+
break;
|
|
314
|
+
case CErrorName.econnreset:
|
|
315
|
+
(void 0).systemErrors.eConnReset(err);
|
|
316
|
+
break;
|
|
317
|
+
case CErrorName.eexist:
|
|
318
|
+
(void 0).systemErrors.eExist(err);
|
|
319
|
+
break;
|
|
320
|
+
case CErrorName.eisdir:
|
|
321
|
+
(void 0).systemErrors.eIsDir(err);
|
|
322
|
+
break;
|
|
323
|
+
case CErrorName.emfile:
|
|
324
|
+
(void 0).systemErrors.eMFile(err);
|
|
325
|
+
break;
|
|
326
|
+
case CErrorName.enoent:
|
|
327
|
+
(void 0).systemErrors.eNoEnt(err);
|
|
328
|
+
break;
|
|
329
|
+
case CErrorName.enotdir:
|
|
330
|
+
(void 0).systemErrors.eNotDir(err);
|
|
331
|
+
break;
|
|
332
|
+
case CErrorName.enotEmpty:
|
|
333
|
+
(void 0).systemErrors.eNotEmpty(err);
|
|
334
|
+
break;
|
|
335
|
+
case CErrorName.eperm:
|
|
336
|
+
(void 0).systemErrors.ePerm(err);
|
|
337
|
+
break;
|
|
338
|
+
case CErrorName.epipe:
|
|
339
|
+
(void 0).systemErrors.ePipe(err);
|
|
340
|
+
break;
|
|
341
|
+
case CErrorName.etimedout:
|
|
342
|
+
(void 0).systemErrors.eTimedOut(err);
|
|
343
|
+
break;
|
|
344
|
+
case CErrorName.assertionError:
|
|
345
|
+
(void 0).stackTrace = (void 0).traceError(err.message, err.name, HttpStatusCode.NOT_ACCEPTABLE);
|
|
346
|
+
err instanceof assert.AssertionError ? (void 0).logger.error(
|
|
347
|
+
TranslationLoader3.t((void 0).stackTrace.name, (void 0).localLanguage),
|
|
348
|
+
"AssertionError",
|
|
349
|
+
(void 0).stackTrace.name,
|
|
350
|
+
(void 0).stackTrace.stack,
|
|
351
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
352
|
+
) : (void 0).logger.error(
|
|
353
|
+
TranslationLoader3.t((void 0).stackTrace.name, (void 0).localLanguage),
|
|
354
|
+
"Another Error",
|
|
355
|
+
(void 0).stackTrace.name,
|
|
356
|
+
(void 0).stackTrace.stack,
|
|
357
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
358
|
+
);
|
|
359
|
+
break;
|
|
360
|
+
case CErrorName.errOsslEvpUnsupported:
|
|
361
|
+
(void 0).openSSLErrors.errOsSLEvpUnsupported(err);
|
|
362
|
+
break;
|
|
363
|
+
case CErrorName.errOsslBadDecrypt:
|
|
364
|
+
(void 0).openSSLErrors.errOsSLBadDecrypt(err);
|
|
365
|
+
break;
|
|
366
|
+
case CErrorName.errOsslWrongFinalBlockLength:
|
|
367
|
+
(void 0).openSSLErrors.errOsSLWrongFinalBlockLength(err);
|
|
368
|
+
break;
|
|
369
|
+
case CErrorName.errInvalidArgType:
|
|
370
|
+
(void 0).internalErrors.errInvalidArgType(err);
|
|
371
|
+
break;
|
|
372
|
+
case CErrorName.errInvalidCallback:
|
|
373
|
+
(void 0).internalErrors.errInvalidCallback(err);
|
|
374
|
+
break;
|
|
375
|
+
case CErrorName.errHttpHeadersSent:
|
|
376
|
+
(void 0).internalErrors.errHttpHeadersSent(err);
|
|
377
|
+
break;
|
|
378
|
+
case CErrorName.errStreamDestroyed:
|
|
379
|
+
(void 0).internalErrors.errStreamDestroyed(err);
|
|
380
|
+
break;
|
|
381
|
+
case CErrorName.errTlsCertAltnameInvalid:
|
|
382
|
+
(void 0).internalErrors.errTlsCertAltNameInvalid(err);
|
|
383
|
+
break;
|
|
384
|
+
case CErrorName.errUnsupportedEsmUrlScheme:
|
|
385
|
+
(void 0).internalErrors.errUnsupportedEsmUrlScheme(err);
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
|
|
274
390
|
// src/core/webServer.core.ts
|
|
391
|
+
import { requestCallsEvent } from "opticore-request-call-event";
|
|
275
392
|
var WebServerCore = class {
|
|
276
393
|
serverUtility = new CoreService();
|
|
277
394
|
expressApp = express2();
|
|
395
|
+
localLanguage;
|
|
278
396
|
loggerConfig;
|
|
279
397
|
routerExpressApp;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
398
|
+
getEnvironnement;
|
|
399
|
+
environnementPath;
|
|
400
|
+
serverListenEvent;
|
|
401
|
+
javaScriptErrors;
|
|
402
|
+
internalErrors;
|
|
403
|
+
assertionErrors;
|
|
404
|
+
openSSLErrors;
|
|
405
|
+
systemErrors;
|
|
406
|
+
constructor(app, loggerConfig, localLanguage, environnementPath, corsOriginOptions) {
|
|
407
|
+
this.getEnvironnement = getEnvironnementValue(environnementPath);
|
|
285
408
|
this.routerExpressApp = app;
|
|
286
409
|
this.loggerConfig = loggerConfig;
|
|
410
|
+
this.localLanguage = localLanguage;
|
|
411
|
+
this.environnementPath = environnementPath;
|
|
287
412
|
this.expressApp.use(express2.json());
|
|
288
413
|
this.expressApp.use(express2.raw());
|
|
289
414
|
this.expressApp.use(express2.text());
|
|
290
415
|
this.expressApp.use(express2.urlencoded({ extended: true }));
|
|
291
416
|
this.expressApp.use(corsOrigin(corsOriginOptions));
|
|
292
|
-
this.
|
|
417
|
+
this.serverListenEvent = new ServerListenEventError2(localLanguage);
|
|
418
|
+
this.javaScriptErrors = new JavaScriptErrors(localLanguage);
|
|
419
|
+
this.assertionErrors = new AssertionErrors(localLanguage);
|
|
420
|
+
this.internalErrors = new InternalErrors(localLanguage);
|
|
421
|
+
this.openSSLErrors = new OpenSSLErrors(localLanguage);
|
|
422
|
+
this.systemErrors = new SystemErrors(localLanguage);
|
|
423
|
+
this.stackTraceErrorHandling(localLanguage);
|
|
293
424
|
this.translationWebAppLoader();
|
|
294
425
|
}
|
|
295
|
-
onStartServer(routers
|
|
426
|
+
onStartServer(routers) {
|
|
296
427
|
return this.expressApp.listen(
|
|
297
|
-
this.
|
|
298
|
-
this.
|
|
428
|
+
this.getEnvironnement.appHost,
|
|
429
|
+
this.getEnvironnement.appPort,
|
|
299
430
|
() => {
|
|
300
431
|
try {
|
|
301
|
-
if (this.
|
|
302
|
-
|
|
303
|
-
} else if (this.
|
|
304
|
-
|
|
305
|
-
} else if (this.
|
|
306
|
-
|
|
432
|
+
if (this.getEnvironnement.appHost === "" && this.getEnvironnement.appPort === 0) {
|
|
433
|
+
this.serverListenEvent.hostPortUndefined(this.getEnvironnement.appPort);
|
|
434
|
+
} else if (this.getEnvironnement.appHost === "") {
|
|
435
|
+
this.serverListenEvent.hostUndefined(this.getEnvironnement.appHost);
|
|
436
|
+
} else if (this.getEnvironnement.appPort === 0) {
|
|
437
|
+
this.serverListenEvent.portUndefined();
|
|
307
438
|
} else {
|
|
308
439
|
this.registerRoutes(routers);
|
|
309
440
|
}
|
|
310
441
|
} catch (err) {
|
|
311
|
-
|
|
442
|
+
SServerStartError(err);
|
|
312
443
|
}
|
|
313
444
|
}
|
|
314
445
|
);
|
|
315
446
|
}
|
|
316
447
|
//, kernelModule: KernelModuleType
|
|
317
|
-
onListeningOnServerEvent(serverWeb,
|
|
448
|
+
onListeningOnServerEvent(serverWeb, localLanguage) {
|
|
318
449
|
serverWeb.on(eventName2.error, (err) => {
|
|
319
|
-
|
|
450
|
+
this.serverListenEvent.onEventError(err);
|
|
320
451
|
}).on(eventName2.close, () => {
|
|
321
|
-
|
|
452
|
+
this.serverListenEvent.serverClosing();
|
|
322
453
|
}).on(eventName2.drop, () => {
|
|
323
|
-
|
|
454
|
+
this.serverListenEvent.dropNewConnection();
|
|
324
455
|
}).on(eventName2.listening, () => {
|
|
325
456
|
this.infoWebApp();
|
|
326
457
|
});
|
|
327
458
|
}
|
|
328
459
|
onRequestOnServerEvent(serverWeb) {
|
|
329
460
|
serverWeb.on(eventName2.request, (req, res) => {
|
|
330
|
-
requestCallsEvent(
|
|
461
|
+
requestCallsEvent(
|
|
462
|
+
req,
|
|
463
|
+
res,
|
|
464
|
+
this.getEnvironnement.appHost,
|
|
465
|
+
this.getEnvironnement.appPort,
|
|
466
|
+
dateTimeFormattedUtils,
|
|
467
|
+
this.environnementPath,
|
|
468
|
+
this.localLanguage
|
|
469
|
+
);
|
|
331
470
|
});
|
|
332
471
|
}
|
|
333
472
|
translationWebAppLoader() {
|
|
334
473
|
const require2 = createRequire(import.meta.url);
|
|
335
474
|
const packagePath = path2.dirname(require2.resolve("opticore-webapp"));
|
|
336
475
|
const translateMsgJsonFilePath = path2.join(packagePath, "utils", "translations");
|
|
337
|
-
|
|
476
|
+
TranslationLoader4.loadTranslations(translateMsgJsonFilePath);
|
|
338
477
|
}
|
|
339
478
|
registerRoutes(allFeatureRoutes) {
|
|
340
479
|
allFeatureRoutes.map((router) => {
|
|
@@ -343,24 +482,21 @@ var WebServerCore = class {
|
|
|
343
482
|
});
|
|
344
483
|
});
|
|
345
484
|
}
|
|
346
|
-
stackTraceErrorHandling(
|
|
347
|
-
eventProcessHandler(
|
|
485
|
+
stackTraceErrorHandling(localLanguage) {
|
|
486
|
+
eventProcessHandler(localLanguage);
|
|
348
487
|
}
|
|
349
488
|
infoWebApp() {
|
|
350
489
|
this.serverUtility.infoServer(
|
|
351
490
|
this.serverUtility.getVersions().nodeVersion,
|
|
352
491
|
this.serverUtility.getProjectInfo().startingTime,
|
|
353
|
-
|
|
354
|
-
Number(
|
|
492
|
+
this.getEnvironnement.appHost,
|
|
493
|
+
Number(this.getEnvironnement.appPort),
|
|
355
494
|
this.serverUtility.getUsageMemory().rss,
|
|
356
495
|
this.serverUtility.getUsageMemory().heapUsed,
|
|
357
496
|
this.serverUtility.getUsageMemory().user,
|
|
358
497
|
this.serverUtility.getUsageMemory().system
|
|
359
498
|
);
|
|
360
499
|
}
|
|
361
|
-
traceError(props, name, status2) {
|
|
362
|
-
return new StackTraceError2(props, name, status2, true);
|
|
363
|
-
}
|
|
364
500
|
};
|
|
365
501
|
export {
|
|
366
502
|
WebServerCore as WebServer
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opticore-webapp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"description": "wep server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -29,23 +29,23 @@
|
|
|
29
29
|
"cors": "^2.8.5",
|
|
30
30
|
"dotenv": "^16.4.7",
|
|
31
31
|
"gradient-string": "^2.0.2",
|
|
32
|
-
"opticore-catch-exception-error": "^1.0.
|
|
33
|
-
"opticore-env-access": "^1.0.
|
|
32
|
+
"opticore-catch-exception-error": "^1.0.17",
|
|
33
|
+
"opticore-env-access": "^1.0.5",
|
|
34
34
|
"opticore-express": "^1.0.3",
|
|
35
35
|
"opticore-http-response": "^1.0.3",
|
|
36
36
|
"opticore-logger": "^1.0.13",
|
|
37
|
-
"opticore-
|
|
37
|
+
"opticore-request-call-event": "^1.0.1",
|
|
38
38
|
"opticore-router": "^1.0.10",
|
|
39
|
-
"opticore-translator": "^1.0.
|
|
39
|
+
"opticore-translator": "^1.0.7",
|
|
40
40
|
"opticore-validator": "^1.0.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@types/node": "^22.13.
|
|
43
|
+
"@types/node": "^22.13.10",
|
|
44
44
|
"@types/cors": "^2.8.17",
|
|
45
45
|
"@types/gradient-string": "^1.1.6",
|
|
46
46
|
"reflect-metadata": "^0.2.2",
|
|
47
47
|
"tslib": "^2.8.1",
|
|
48
|
-
"tsup": "^8.
|
|
48
|
+
"tsup": "^8.4.0",
|
|
49
49
|
"typescript": "^5.4.5"
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import assert from "assert";
|
|
2
|
+
import { CErrorName } from "opticore-catch-exception-error";
|
|
3
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
4
|
+
import { TranslationLoader } from "opticore-translator";
|
|
5
|
+
|
|
6
|
+
export const SServerStartError = (err: any) => {
|
|
7
|
+
switch (err.name) {
|
|
8
|
+
case CErrorName.typeError:
|
|
9
|
+
this.javaScriptErrors.typeError(err);
|
|
10
|
+
break;
|
|
11
|
+
case CErrorName.error:
|
|
12
|
+
this.javaScriptErrors.allError(err);
|
|
13
|
+
break;
|
|
14
|
+
case CErrorName.evalError:
|
|
15
|
+
this.javaScriptErrors.evalError(err);
|
|
16
|
+
break;
|
|
17
|
+
case CErrorName.referenceError:
|
|
18
|
+
this.javaScriptErrors.referenceError(err);
|
|
19
|
+
break;
|
|
20
|
+
case CErrorName.rangeError:
|
|
21
|
+
this.javaScriptErrors.rangeError(err);
|
|
22
|
+
break;
|
|
23
|
+
case CErrorName.syntaxError:
|
|
24
|
+
this.javaScriptErrors.syntaxError(err);
|
|
25
|
+
break;
|
|
26
|
+
case CErrorName.uriError:
|
|
27
|
+
this.javaScriptErrors.uRIError(err);
|
|
28
|
+
break;
|
|
29
|
+
case CErrorName.eacces:
|
|
30
|
+
this.systemErrors.eAcces(err);
|
|
31
|
+
break;
|
|
32
|
+
case CErrorName.eaddrinuse:
|
|
33
|
+
this.systemErrors.eAddrInUse(err);
|
|
34
|
+
break;
|
|
35
|
+
case CErrorName.econnrefused:
|
|
36
|
+
this.systemErrors.eConnRefused(err);
|
|
37
|
+
break;
|
|
38
|
+
case CErrorName.econnreset:
|
|
39
|
+
this.systemErrors.eConnReset(err);
|
|
40
|
+
break;
|
|
41
|
+
case CErrorName.eexist:
|
|
42
|
+
this.systemErrors.eExist(err);
|
|
43
|
+
break;
|
|
44
|
+
case CErrorName.eisdir:
|
|
45
|
+
this.systemErrors.eIsDir(err);
|
|
46
|
+
break;
|
|
47
|
+
case CErrorName.emfile:
|
|
48
|
+
this.systemErrors.eMFile(err);
|
|
49
|
+
break;
|
|
50
|
+
case CErrorName.enoent:
|
|
51
|
+
this.systemErrors.eNoEnt(err);
|
|
52
|
+
break;
|
|
53
|
+
case CErrorName.enotdir:
|
|
54
|
+
this.systemErrors.eNotDir(err);
|
|
55
|
+
break;
|
|
56
|
+
case CErrorName.enotEmpty:
|
|
57
|
+
this.systemErrors.eNotEmpty(err);
|
|
58
|
+
break;
|
|
59
|
+
case CErrorName.eperm:
|
|
60
|
+
this.systemErrors.ePerm(err);
|
|
61
|
+
break;
|
|
62
|
+
case CErrorName.epipe:
|
|
63
|
+
this.systemErrors.ePipe(err);
|
|
64
|
+
break;
|
|
65
|
+
case CErrorName.etimedout:
|
|
66
|
+
this.systemErrors.eTimedOut(err);
|
|
67
|
+
break;
|
|
68
|
+
case CErrorName.assertionError:
|
|
69
|
+
this.stackTrace = this.traceError(err.message, err.name, HttpStatusCode.NOT_ACCEPTABLE);
|
|
70
|
+
err instanceof assert.AssertionError
|
|
71
|
+
? this.logger.error(
|
|
72
|
+
TranslationLoader.t(this.stackTrace.name, this.localLanguage),
|
|
73
|
+
"AssertionError",
|
|
74
|
+
this.stackTrace.name,
|
|
75
|
+
this.stackTrace.stack,
|
|
76
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR)
|
|
77
|
+
: this.logger.error(
|
|
78
|
+
TranslationLoader.t(this.stackTrace.name, this.localLanguage),
|
|
79
|
+
"Another Error",
|
|
80
|
+
this.stackTrace.name,
|
|
81
|
+
this.stackTrace.stack,
|
|
82
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR);
|
|
83
|
+
break;
|
|
84
|
+
case CErrorName.errOsslEvpUnsupported:
|
|
85
|
+
this.openSSLErrors.errOsSLEvpUnsupported(err);
|
|
86
|
+
break;
|
|
87
|
+
case CErrorName.errOsslBadDecrypt:
|
|
88
|
+
this.openSSLErrors.errOsSLBadDecrypt(err);
|
|
89
|
+
break;
|
|
90
|
+
case CErrorName.errOsslWrongFinalBlockLength:
|
|
91
|
+
this.openSSLErrors.errOsSLWrongFinalBlockLength(err);
|
|
92
|
+
break;
|
|
93
|
+
case CErrorName.errInvalidArgType:
|
|
94
|
+
this.internalErrors.errInvalidArgType(err);
|
|
95
|
+
break;
|
|
96
|
+
case CErrorName.errInvalidCallback:
|
|
97
|
+
this.internalErrors.errInvalidCallback(err);
|
|
98
|
+
break;
|
|
99
|
+
case CErrorName.errHttpHeadersSent:
|
|
100
|
+
this.internalErrors.errHttpHeadersSent(err);
|
|
101
|
+
break;
|
|
102
|
+
case CErrorName.errStreamDestroyed:
|
|
103
|
+
this.internalErrors.errStreamDestroyed(err);
|
|
104
|
+
break;
|
|
105
|
+
case CErrorName.errTlsCertAltnameInvalid:
|
|
106
|
+
this.internalErrors.errTlsCertAltNameInvalid(err);
|
|
107
|
+
break;
|
|
108
|
+
case CErrorName.errUnsupportedEsmUrlScheme:
|
|
109
|
+
this.internalErrors.errUnsupportedEsmUrlScheme(err);
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -15,12 +15,13 @@ import {
|
|
|
15
15
|
export function eventProcessHandler(localeLanguage: string): void {
|
|
16
16
|
const errorEmitter = new EventEmitter();
|
|
17
17
|
const app = express();
|
|
18
|
+
const serverListenEvent: ServerListenEventError = new ServerListenEventError(localeLanguage);
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* Listener for error events
|
|
21
22
|
*/
|
|
22
23
|
errorEmitter.on(eventName.error, (error: Error): void => {
|
|
23
|
-
|
|
24
|
+
serverListenEvent.listenerError(error);
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
/**
|
|
@@ -29,7 +30,7 @@ export function eventProcessHandler(localeLanguage: string): void {
|
|
|
29
30
|
*/
|
|
30
31
|
process.on(event.beforeExit, (code: number): void => {
|
|
31
32
|
setTimeout((): void => {
|
|
32
|
-
|
|
33
|
+
serverListenEvent.processBeforeExit(code);
|
|
33
34
|
}, 100);
|
|
34
35
|
});
|
|
35
36
|
|
|
@@ -37,75 +38,75 @@ export function eventProcessHandler(localeLanguage: string): void {
|
|
|
37
38
|
*
|
|
38
39
|
*/
|
|
39
40
|
process.on(event.disconnect, (): void => {
|
|
40
|
-
|
|
41
|
+
serverListenEvent.processDisconnected();
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
/**
|
|
44
45
|
*
|
|
45
46
|
*/
|
|
46
47
|
process.on(event.exit, (code: number): void => {
|
|
47
|
-
|
|
48
|
+
serverListenEvent.exited(code);
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
52
|
*
|
|
52
53
|
*/
|
|
53
54
|
process.on(event.rejectionHandled, (promise: Promise<any>): void => {
|
|
54
|
-
|
|
55
|
+
serverListenEvent.promiseRejectionHandled(promise);
|
|
55
56
|
});
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
*
|
|
59
60
|
*/
|
|
60
61
|
process.on(event.uncaughtException, (error: any): void => {
|
|
61
|
-
|
|
62
|
+
serverListenEvent.uncaughtException(error);
|
|
62
63
|
});
|
|
63
64
|
|
|
64
65
|
/**
|
|
65
66
|
*
|
|
66
67
|
*/
|
|
67
68
|
process.on(event.uncaughtExceptionMonitor, (error: any): void => {
|
|
68
|
-
|
|
69
|
+
serverListenEvent.uncaughtExceptionMonitor(error);
|
|
69
70
|
});
|
|
70
71
|
|
|
71
72
|
/**
|
|
72
73
|
*
|
|
73
74
|
*/
|
|
74
75
|
process.on(event.unhandledRejection, (reason: any, promise: Promise<any>): void => {
|
|
75
|
-
|
|
76
|
+
serverListenEvent.unhandledRejection(reason, promise);
|
|
76
77
|
});
|
|
77
78
|
|
|
78
79
|
/**
|
|
79
80
|
*
|
|
80
81
|
*/
|
|
81
82
|
process.on(event.warning, (warning: any): void => {
|
|
82
|
-
|
|
83
|
+
serverListenEvent.warning(warning);
|
|
83
84
|
});
|
|
84
85
|
process.on(event.message, (message: any): void => {
|
|
85
|
-
|
|
86
|
+
serverListenEvent.message(message);
|
|
86
87
|
});
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
90
|
*
|
|
90
91
|
*/
|
|
91
92
|
process.on(event.multipleResolves, (type: string, promise: Promise<any>, reason: any): void => {
|
|
92
|
-
|
|
93
|
+
serverListenEvent.multipleResolves(type, promise, reason);
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
/**
|
|
96
97
|
* Handle specific signals
|
|
97
98
|
*/
|
|
98
99
|
process.on(event.sigint, (): void => {
|
|
99
|
-
|
|
100
|
+
serverListenEvent.processInterrupted();
|
|
100
101
|
});
|
|
101
102
|
process.on(event.sigterm, (signal: any): void => {
|
|
102
|
-
|
|
103
|
+
serverListenEvent.sigtermSignalReceived(signal);
|
|
103
104
|
});
|
|
104
105
|
|
|
105
106
|
/**
|
|
106
107
|
* Express error-handling middleware
|
|
107
108
|
*/
|
|
108
109
|
app.use((err: Error, req: Request, res: Response, next: NextFunction): void => {
|
|
109
|
-
|
|
110
|
+
serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
110
111
|
});
|
|
111
112
|
}
|
|
@@ -7,17 +7,17 @@ import { LoggerCore } from "opticore-logger";
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
export function modulesLoadedUtils(allAppRoutes: Router[], dbConChecker: () => void, localeLanguage: string
|
|
10
|
+
export function modulesLoadedUtils(allAppRoutes: Router[], dbConChecker: () => void, localeLanguage: string): void {
|
|
11
11
|
LogMessageUtils.success(
|
|
12
|
-
`${TranslationLoader.t("kernel", localeLanguage
|
|
13
|
-
`${TranslationLoader.t("loadKernel", localeLanguage
|
|
14
|
-
`${TranslationLoader.t("moduleAppLoaded", localeLanguage
|
|
12
|
+
`${TranslationLoader.t("kernel", localeLanguage)}`,
|
|
13
|
+
`${TranslationLoader.t("loadKernel", localeLanguage)}`,
|
|
14
|
+
`${TranslationLoader.t("moduleAppLoaded", localeLanguage)}`
|
|
15
15
|
);
|
|
16
|
-
console.log(`${colors.whiteBright(` ${TranslationLoader.t("content", localeLanguage
|
|
16
|
+
console.log(`${colors.whiteBright(` ${TranslationLoader.t("content", localeLanguage)}`)} ${colors.green(`${TranslationLoader.t("kernel", localeLanguage)} :`)} ${colors.cyan(`${colors.bold(`${TranslationLoader.t("serverSide", localeLanguage)}`)}`)} ${TranslationLoader.t("hasBeenLoadedSuccessfully", localeLanguage)} ${colors.green(`✔`)}`);
|
|
17
17
|
allAppRoutes
|
|
18
|
-
? console.log(`${colors.whiteBright(` ${TranslationLoader.t("content", localeLanguage
|
|
19
|
-
: console.log(`${colors.red(`✘`)} ${colors.bgRed(` ${colors.bold(`${colors.white(` ${TranslationLoader.t("registerRoutes", localeLanguage
|
|
18
|
+
? console.log(`${colors.whiteBright(` ${TranslationLoader.t("content", localeLanguage)}`)} ${colors.green(`${TranslationLoader.t("kernel", localeLanguage)} :`)} ${colors.cyan(`${colors.bold(`${TranslationLoader.t("routerService", localeLanguage)}`)} `)} ${colors.green(`✔`)}`)
|
|
19
|
+
: console.log(`${colors.red(`✘`)} ${colors.bgRed(` ${colors.bold(`${colors.white(` ${TranslationLoader.t("registerRoutes", localeLanguage)} `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors.red(`${colors.bold(` ${TranslationLoader.t("fail", localeLanguage)} `)}`)} ] | [ ${colors.bold(` ${TranslationLoader.t("loading", localeLanguage)} `)} ] - ${colors.red(` ${TranslationLoader.t("routers", localeLanguage)} `)} - ${TranslationLoader.t("registerLoadingFailed", localeLanguage)} `);
|
|
20
20
|
typeof dbConChecker == "function"
|
|
21
|
-
? console.log(`${colors.whiteBright(` ${TranslationLoader.t("content", localeLanguage
|
|
21
|
+
? console.log(`${colors.whiteBright(` ${TranslationLoader.t("content", localeLanguage)}`)} ${colors.green(`${TranslationLoader.t("kernel", localeLanguage)} :`)} ${colors.cyan(`${colors.bold(`${TranslationLoader.t("dbConnChecker", localeLanguage)}`)}`)} ${TranslationLoader.t("hasBeenLoadedSuccessfully", localeLanguage)} ${colors.green(`✔`)}`)
|
|
22
22
|
: "";
|
|
23
23
|
}
|
|
@@ -6,13 +6,17 @@ import { IncomingMessage, ServerResponse } from "node:http";
|
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
8
|
CEventNameError as eventName,
|
|
9
|
+
ServerListenEventError,
|
|
10
|
+
CErrorName,
|
|
11
|
+
JavaScriptErrors,
|
|
12
|
+
InternalErrors,
|
|
13
|
+
AssertionErrors,
|
|
14
|
+
OpenSSLErrors,
|
|
15
|
+
SystemErrors,
|
|
9
16
|
StackTraceError,
|
|
10
|
-
ServerListenEventError as eventErrorOnListeningServer
|
|
11
17
|
} from "opticore-catch-exception-error";
|
|
12
18
|
import { express } from "opticore-express";
|
|
13
|
-
import {
|
|
14
|
-
import { requestCallsEvent } from "opticore-requests-called-events";
|
|
15
|
-
import { HttpStatusCode } from "opticore-http-response";
|
|
19
|
+
import { getEnvironnementValue } from "opticore-env-access";
|
|
16
20
|
import { TranslationLoader } from "opticore-translator";
|
|
17
21
|
import { LoggerCore } from "opticore-logger";
|
|
18
22
|
|
|
@@ -20,23 +24,35 @@ import { IRouteDefinition } from "@webApp/domains/interfaces/routeDefinition.int
|
|
|
20
24
|
import { eventProcessHandler } from "@webApp/core/handlers/eventProcess.handler";
|
|
21
25
|
import { CoreService } from "@webApp/application/service/core.service";
|
|
22
26
|
import { dateTimeFormattedUtils as currentDate } from "@webApp/core/helpers/dateTimeFormatted.utils";
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
import { SServerStartError } from "@webApp/application/service/serverStartError.service";
|
|
28
|
+
import {requestCallsEvent} from "opticore-request-call-event";
|
|
25
29
|
|
|
26
30
|
|
|
27
31
|
export class WebServerCore {
|
|
28
32
|
private serverUtility: CoreService = new CoreService();
|
|
29
33
|
private expressApp = express();
|
|
34
|
+
|
|
35
|
+
private readonly localLanguage: string;
|
|
30
36
|
private readonly loggerConfig: LoggerCore;
|
|
31
37
|
private readonly routerExpressApp: express.Application;
|
|
32
|
-
private readonly
|
|
33
|
-
private readonly
|
|
38
|
+
private readonly getEnvironnement: any;
|
|
39
|
+
private readonly environnementPath: string;
|
|
40
|
+
|
|
41
|
+
private serverListenEvent: ServerListenEventError;
|
|
42
|
+
private javaScriptErrors: JavaScriptErrors;
|
|
43
|
+
private internalErrors: InternalErrors;
|
|
44
|
+
private assertionErrors: AssertionErrors;
|
|
45
|
+
private openSSLErrors: OpenSSLErrors;
|
|
46
|
+
private systemErrors: SystemErrors;
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
constructor(app: express.Application, loggerConfig: LoggerCore, localLanguage: string, environnementPath: any, corsOriginOptions?: Partial<CorsOptions>) {
|
|
50
|
+
this.getEnvironnement = getEnvironnementValue(environnementPath);
|
|
34
51
|
|
|
35
|
-
constructor(app: express.Application, loggerConfig: LoggerCore, localeLanguage: string, corsOriginOptions?: Partial<CorsOptions>) {
|
|
36
|
-
this.port = Number(getEnvVariable.appPort);
|
|
37
|
-
this.host = getEnvVariable.appHost;
|
|
38
52
|
this.routerExpressApp = app;
|
|
39
53
|
this.loggerConfig = loggerConfig;
|
|
54
|
+
this.localLanguage = localLanguage;
|
|
55
|
+
this.environnementPath = environnementPath;
|
|
40
56
|
|
|
41
57
|
this.expressApp.use(express.json());
|
|
42
58
|
this.expressApp.use(express.raw());
|
|
@@ -44,40 +60,48 @@ export class WebServerCore {
|
|
|
44
60
|
this.expressApp.use(express.urlencoded({ extended: true }));
|
|
45
61
|
this.expressApp.use(corsOrigin(corsOriginOptions));
|
|
46
62
|
|
|
47
|
-
this.
|
|
63
|
+
this.serverListenEvent = new ServerListenEventError(localLanguage);
|
|
64
|
+
this.javaScriptErrors = new JavaScriptErrors(localLanguage);
|
|
65
|
+
this.assertionErrors = new AssertionErrors(localLanguage);
|
|
66
|
+
this.internalErrors = new InternalErrors(localLanguage);
|
|
67
|
+
this.openSSLErrors = new OpenSSLErrors(localLanguage);
|
|
68
|
+
this.systemErrors = new SystemErrors(localLanguage);
|
|
69
|
+
|
|
70
|
+
this.stackTraceErrorHandling(localLanguage);
|
|
48
71
|
this.translationWebAppLoader();
|
|
49
72
|
}
|
|
50
73
|
|
|
51
|
-
|
|
74
|
+
|
|
75
|
+
public onStartServer(routers: { featureRoute: IRouteDefinition[] }[]) {
|
|
52
76
|
return this.expressApp.listen(
|
|
53
|
-
this.
|
|
54
|
-
this.
|
|
77
|
+
this.getEnvironnement.appHost,
|
|
78
|
+
this.getEnvironnement.appPort,
|
|
55
79
|
(): void => {
|
|
56
80
|
try {
|
|
57
|
-
if (this.
|
|
58
|
-
|
|
59
|
-
} else if (this.
|
|
60
|
-
|
|
61
|
-
} else if (this.
|
|
62
|
-
|
|
81
|
+
if (this.getEnvironnement.appHost === "" && this.getEnvironnement.appPort === 0) {
|
|
82
|
+
this.serverListenEvent.hostPortUndefined(this.getEnvironnement.appPort);
|
|
83
|
+
} else if (this.getEnvironnement.appHost === "") {
|
|
84
|
+
this.serverListenEvent.hostUndefined(this.getEnvironnement.appHost);
|
|
85
|
+
} else if (this.getEnvironnement.appPort === 0) {
|
|
86
|
+
this.serverListenEvent.portUndefined();
|
|
63
87
|
} else {
|
|
64
88
|
this.registerRoutes(routers);
|
|
65
89
|
}
|
|
66
90
|
} catch (err: any) {
|
|
67
|
-
|
|
91
|
+
SServerStartError(err);
|
|
68
92
|
}
|
|
69
93
|
}
|
|
70
94
|
);
|
|
71
95
|
}
|
|
72
96
|
|
|
73
97
|
//, kernelModule: KernelModuleType
|
|
74
|
-
public onListeningOnServerEvent(serverWeb: serverWebApp,
|
|
98
|
+
public onListeningOnServerEvent(serverWeb: serverWebApp, localLanguage: string): void {
|
|
75
99
|
serverWeb.on(eventName.error, (err: Error): void => {
|
|
76
|
-
|
|
100
|
+
this.serverListenEvent.onEventError(err);
|
|
77
101
|
}).on(eventName.close, (): void => {
|
|
78
|
-
|
|
102
|
+
this.serverListenEvent.serverClosing();
|
|
79
103
|
}).on(eventName.drop, (): void => {
|
|
80
|
-
|
|
104
|
+
this.serverListenEvent.dropNewConnection();
|
|
81
105
|
}).on(eventName.listening, (): void => {
|
|
82
106
|
this.infoWebApp();
|
|
83
107
|
//this.serverUtility.coreListenerEventLoaderModuleService(kernelModule);
|
|
@@ -86,7 +110,15 @@ export class WebServerCore {
|
|
|
86
110
|
|
|
87
111
|
public onRequestOnServerEvent(serverWeb: serverWebApp): void {
|
|
88
112
|
serverWeb.on(eventName.request, (req: IncomingMessage, res: ServerResponse): void => {
|
|
89
|
-
requestCallsEvent(
|
|
113
|
+
requestCallsEvent(
|
|
114
|
+
req,
|
|
115
|
+
res,
|
|
116
|
+
this.getEnvironnement.appHost,
|
|
117
|
+
this.getEnvironnement.appPort,
|
|
118
|
+
currentDate,
|
|
119
|
+
this.environnementPath,
|
|
120
|
+
this.localLanguage
|
|
121
|
+
);
|
|
90
122
|
});
|
|
91
123
|
}
|
|
92
124
|
|
|
@@ -95,7 +127,7 @@ export class WebServerCore {
|
|
|
95
127
|
const packagePath: string = path.dirname(require.resolve("opticore-webapp"));
|
|
96
128
|
|
|
97
129
|
const translateMsgJsonFilePath: string = path.join(packagePath, "utils", "translations");
|
|
98
|
-
TranslationLoader.loadTranslations(translateMsgJsonFilePath
|
|
130
|
+
TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
99
131
|
}
|
|
100
132
|
private registerRoutes(allFeatureRoutes: { featureRoute: IRouteDefinition[] }[]): void {
|
|
101
133
|
allFeatureRoutes.map((router: {featureRoute: IRouteDefinition[]} ): void => {
|
|
@@ -104,22 +136,19 @@ export class WebServerCore {
|
|
|
104
136
|
});
|
|
105
137
|
});
|
|
106
138
|
}
|
|
107
|
-
private stackTraceErrorHandling(
|
|
108
|
-
eventProcessHandler(
|
|
139
|
+
private stackTraceErrorHandling(localLanguage: string): void {
|
|
140
|
+
eventProcessHandler(localLanguage);
|
|
109
141
|
}
|
|
110
142
|
private infoWebApp(): void {
|
|
111
143
|
this.serverUtility.infoServer(
|
|
112
144
|
this.serverUtility.getVersions().nodeVersion,
|
|
113
145
|
this.serverUtility.getProjectInfo().startingTime,
|
|
114
|
-
|
|
115
|
-
Number(
|
|
146
|
+
this.getEnvironnement.appHost,
|
|
147
|
+
Number(this.getEnvironnement.appPort),
|
|
116
148
|
this.serverUtility.getUsageMemory().rss,
|
|
117
149
|
this.serverUtility.getUsageMemory().heapUsed,
|
|
118
150
|
this.serverUtility.getUsageMemory().user,
|
|
119
151
|
this.serverUtility.getUsageMemory().system
|
|
120
152
|
);
|
|
121
153
|
}
|
|
122
|
-
private traceError(props: string, name: string, status: number): StackTraceError {
|
|
123
|
-
return new StackTraceError(props, name, status, true);
|
|
124
|
-
}
|
|
125
154
|
}
|