opticore-webapp 1.0.17 → 1.0.18
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 +168 -44
- package/dist/index.d.cts +10 -4
- package/dist/index.d.ts +10 -4
- package/dist/index.js +168 -40
- package/package.json +5 -5
- 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 +1 -1
- package/src/core/webServer.core.ts +41 -21
package/dist/index.cjs
CHANGED
|
@@ -42,12 +42,11 @@ 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
48
|
var import_opticore_requests_called_events = require("opticore-requests-called-events");
|
|
49
|
-
var
|
|
50
|
-
var import_opticore_translator3 = require("opticore-translator");
|
|
49
|
+
var import_opticore_translator4 = require("opticore-translator");
|
|
51
50
|
|
|
52
51
|
// src/core/handlers/eventProcess.handler.ts
|
|
53
52
|
var import_node_process = __toESM(require("process"), 1);
|
|
@@ -57,49 +56,50 @@ var import_opticore_catch_exception_error = require("opticore-catch-exception-er
|
|
|
57
56
|
function eventProcessHandler(localeLanguage) {
|
|
58
57
|
const errorEmitter = new import_node_events.default();
|
|
59
58
|
const app = (0, import_opticore_express.express)();
|
|
59
|
+
const serverListenEvent = new import_opticore_catch_exception_error.ServerListenEventError(localeLanguage);
|
|
60
60
|
errorEmitter.on(import_opticore_catch_exception_error.CEventNameError.error, (error) => {
|
|
61
|
-
|
|
61
|
+
serverListenEvent.listenerError(error);
|
|
62
62
|
});
|
|
63
63
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.beforeExit, (code) => {
|
|
64
64
|
setTimeout(() => {
|
|
65
|
-
|
|
65
|
+
serverListenEvent.processBeforeExit(code);
|
|
66
66
|
}, 100);
|
|
67
67
|
});
|
|
68
68
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.disconnect, () => {
|
|
69
|
-
|
|
69
|
+
serverListenEvent.processDisconnected();
|
|
70
70
|
});
|
|
71
71
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.exit, (code) => {
|
|
72
|
-
|
|
72
|
+
serverListenEvent.exited(code);
|
|
73
73
|
});
|
|
74
74
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.rejectionHandled, (promise) => {
|
|
75
|
-
|
|
75
|
+
serverListenEvent.promiseRejectionHandled(promise);
|
|
76
76
|
});
|
|
77
77
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.uncaughtException, (error) => {
|
|
78
|
-
|
|
78
|
+
serverListenEvent.uncaughtException(error);
|
|
79
79
|
});
|
|
80
80
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.uncaughtExceptionMonitor, (error) => {
|
|
81
|
-
|
|
81
|
+
serverListenEvent.uncaughtExceptionMonitor(error);
|
|
82
82
|
});
|
|
83
83
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.unhandledRejection, (reason, promise) => {
|
|
84
|
-
|
|
84
|
+
serverListenEvent.unhandledRejection(reason, promise);
|
|
85
85
|
});
|
|
86
86
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.warning, (warning) => {
|
|
87
|
-
|
|
87
|
+
serverListenEvent.warning(warning);
|
|
88
88
|
});
|
|
89
89
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.message, (message) => {
|
|
90
|
-
|
|
90
|
+
serverListenEvent.message(message);
|
|
91
91
|
});
|
|
92
92
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.multipleResolves, (type, promise, reason) => {
|
|
93
|
-
|
|
93
|
+
serverListenEvent.multipleResolves(type, promise, reason);
|
|
94
94
|
});
|
|
95
95
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.sigint, () => {
|
|
96
|
-
|
|
96
|
+
serverListenEvent.processInterrupted();
|
|
97
97
|
});
|
|
98
98
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.sigterm, (signal) => {
|
|
99
|
-
|
|
99
|
+
serverListenEvent.sigtermSignalReceived(signal);
|
|
100
100
|
});
|
|
101
101
|
app.use((err, req, res, next) => {
|
|
102
|
-
|
|
102
|
+
serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -142,7 +142,7 @@ var LogMessageUtils = class {
|
|
|
142
142
|
|
|
143
143
|
// src/core/helpers/modulesLoaded.utils.ts
|
|
144
144
|
var import_opticore_translator = require("opticore-translator");
|
|
145
|
-
function modulesLoadedUtils(allAppRoutes, dbConChecker, localeLanguage
|
|
145
|
+
function modulesLoadedUtils(allAppRoutes, dbConChecker, localeLanguage) {
|
|
146
146
|
LogMessageUtils.success(
|
|
147
147
|
`${import_opticore_translator.TranslationLoader.t("kernel", localeLanguage, loggerConfig)}`,
|
|
148
148
|
`${import_opticore_translator.TranslationLoader.t("loadKernel", localeLanguage, loggerConfig)}`,
|
|
@@ -276,7 +276,7 @@ var CoreService = class {
|
|
|
276
276
|
console.log(`${`Memory usage by system :`} ${import_ansi_colors3.default.cyan(`${import_ansi_colors3.default.bold(`${system}`)}`)}`);
|
|
277
277
|
console.log(``);
|
|
278
278
|
}
|
|
279
|
-
coreListenerEventLoaderModuleService(kernelModule, localeLanguage,
|
|
279
|
+
coreListenerEventLoaderModuleService(kernelModule, localeLanguage, loggerConfig2) {
|
|
280
280
|
let router = [];
|
|
281
281
|
let dbCon;
|
|
282
282
|
kernelModule.forEach((module2) => {
|
|
@@ -293,8 +293,8 @@ var CoreService = class {
|
|
|
293
293
|
})();
|
|
294
294
|
} else {
|
|
295
295
|
const stackTrace = new import_opticore_catch_exception_error2.StackTraceError(
|
|
296
|
-
import_opticore_translator2.TranslationLoader.t("loadedModulesError", localeLanguage,
|
|
297
|
-
import_opticore_translator2.TranslationLoader.t("loadedModules", localeLanguage,
|
|
296
|
+
import_opticore_translator2.TranslationLoader.t("loadedModulesError", localeLanguage, loggerConfig2),
|
|
297
|
+
import_opticore_translator2.TranslationLoader.t("loadedModules", localeLanguage, loggerConfig2),
|
|
298
298
|
import_opticore_http_response.HttpStatusCode.NOT_ACCEPTABLE,
|
|
299
299
|
true
|
|
300
300
|
);
|
|
@@ -303,62 +303,189 @@ var CoreService = class {
|
|
|
303
303
|
}
|
|
304
304
|
};
|
|
305
305
|
|
|
306
|
+
// src/application/service/serverStartError.service.ts
|
|
307
|
+
var import_assert = __toESM(require("assert"), 1);
|
|
308
|
+
var import_opticore_catch_exception_error3 = require("opticore-catch-exception-error");
|
|
309
|
+
var import_opticore_http_response2 = require("opticore-http-response");
|
|
310
|
+
var import_opticore_translator3 = require("opticore-translator");
|
|
311
|
+
var SServerStartError = (err) => {
|
|
312
|
+
switch (err.name) {
|
|
313
|
+
case import_opticore_catch_exception_error3.CErrorName.typeError:
|
|
314
|
+
(void 0).javaScriptErrors.typeError(err);
|
|
315
|
+
break;
|
|
316
|
+
case import_opticore_catch_exception_error3.CErrorName.error:
|
|
317
|
+
(void 0).javaScriptErrors.allError(err);
|
|
318
|
+
break;
|
|
319
|
+
case import_opticore_catch_exception_error3.CErrorName.evalError:
|
|
320
|
+
(void 0).javaScriptErrors.evalError(err);
|
|
321
|
+
break;
|
|
322
|
+
case import_opticore_catch_exception_error3.CErrorName.referenceError:
|
|
323
|
+
(void 0).javaScriptErrors.referenceError(err);
|
|
324
|
+
break;
|
|
325
|
+
case import_opticore_catch_exception_error3.CErrorName.rangeError:
|
|
326
|
+
(void 0).javaScriptErrors.rangeError(err);
|
|
327
|
+
break;
|
|
328
|
+
case import_opticore_catch_exception_error3.CErrorName.syntaxError:
|
|
329
|
+
(void 0).javaScriptErrors.syntaxError(err);
|
|
330
|
+
break;
|
|
331
|
+
case import_opticore_catch_exception_error3.CErrorName.uriError:
|
|
332
|
+
(void 0).javaScriptErrors.uRIError(err);
|
|
333
|
+
break;
|
|
334
|
+
case import_opticore_catch_exception_error3.CErrorName.eacces:
|
|
335
|
+
(void 0).systemErrors.eAcces(err);
|
|
336
|
+
break;
|
|
337
|
+
case import_opticore_catch_exception_error3.CErrorName.eaddrinuse:
|
|
338
|
+
(void 0).systemErrors.eAddrInUse(err);
|
|
339
|
+
break;
|
|
340
|
+
case import_opticore_catch_exception_error3.CErrorName.econnrefused:
|
|
341
|
+
(void 0).systemErrors.eConnRefused(err);
|
|
342
|
+
break;
|
|
343
|
+
case import_opticore_catch_exception_error3.CErrorName.econnreset:
|
|
344
|
+
(void 0).systemErrors.eConnReset(err);
|
|
345
|
+
break;
|
|
346
|
+
case import_opticore_catch_exception_error3.CErrorName.eexist:
|
|
347
|
+
(void 0).systemErrors.eExist(err);
|
|
348
|
+
break;
|
|
349
|
+
case import_opticore_catch_exception_error3.CErrorName.eisdir:
|
|
350
|
+
(void 0).systemErrors.eIsDir(err);
|
|
351
|
+
break;
|
|
352
|
+
case import_opticore_catch_exception_error3.CErrorName.emfile:
|
|
353
|
+
(void 0).systemErrors.eMFile(err);
|
|
354
|
+
break;
|
|
355
|
+
case import_opticore_catch_exception_error3.CErrorName.enoent:
|
|
356
|
+
(void 0).systemErrors.eNoEnt(err);
|
|
357
|
+
break;
|
|
358
|
+
case import_opticore_catch_exception_error3.CErrorName.enotdir:
|
|
359
|
+
(void 0).systemErrors.eNotDir(err);
|
|
360
|
+
break;
|
|
361
|
+
case import_opticore_catch_exception_error3.CErrorName.enotEmpty:
|
|
362
|
+
(void 0).systemErrors.eNotEmpty(err);
|
|
363
|
+
break;
|
|
364
|
+
case import_opticore_catch_exception_error3.CErrorName.eperm:
|
|
365
|
+
(void 0).systemErrors.ePerm(err);
|
|
366
|
+
break;
|
|
367
|
+
case import_opticore_catch_exception_error3.CErrorName.epipe:
|
|
368
|
+
(void 0).systemErrors.ePipe(err);
|
|
369
|
+
break;
|
|
370
|
+
case import_opticore_catch_exception_error3.CErrorName.etimedout:
|
|
371
|
+
(void 0).systemErrors.eTimedOut(err);
|
|
372
|
+
break;
|
|
373
|
+
case import_opticore_catch_exception_error3.CErrorName.assertionError:
|
|
374
|
+
(void 0).stackTrace = (void 0).traceError(err.message, err.name, import_opticore_http_response2.HttpStatusCode.NOT_ACCEPTABLE);
|
|
375
|
+
err instanceof import_assert.default.AssertionError ? (void 0).logger.error(
|
|
376
|
+
import_opticore_translator3.TranslationLoader.t((void 0).stackTrace.name, (void 0).localLanguage),
|
|
377
|
+
"AssertionError",
|
|
378
|
+
(void 0).stackTrace.name,
|
|
379
|
+
(void 0).stackTrace.stack,
|
|
380
|
+
import_opticore_http_response2.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
381
|
+
) : (void 0).logger.error(
|
|
382
|
+
import_opticore_translator3.TranslationLoader.t((void 0).stackTrace.name, (void 0).localLanguage),
|
|
383
|
+
"Another Error",
|
|
384
|
+
(void 0).stackTrace.name,
|
|
385
|
+
(void 0).stackTrace.stack,
|
|
386
|
+
import_opticore_http_response2.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
387
|
+
);
|
|
388
|
+
break;
|
|
389
|
+
case import_opticore_catch_exception_error3.CErrorName.errOsslEvpUnsupported:
|
|
390
|
+
(void 0).openSSLErrors.errOsSLEvpUnsupported(err);
|
|
391
|
+
break;
|
|
392
|
+
case import_opticore_catch_exception_error3.CErrorName.errOsslBadDecrypt:
|
|
393
|
+
(void 0).openSSLErrors.errOsSLBadDecrypt(err);
|
|
394
|
+
break;
|
|
395
|
+
case import_opticore_catch_exception_error3.CErrorName.errOsslWrongFinalBlockLength:
|
|
396
|
+
(void 0).openSSLErrors.errOsSLWrongFinalBlockLength(err);
|
|
397
|
+
break;
|
|
398
|
+
case import_opticore_catch_exception_error3.CErrorName.errInvalidArgType:
|
|
399
|
+
(void 0).internalErrors.errInvalidArgType(err);
|
|
400
|
+
break;
|
|
401
|
+
case import_opticore_catch_exception_error3.CErrorName.errInvalidCallback:
|
|
402
|
+
(void 0).internalErrors.errInvalidCallback(err);
|
|
403
|
+
break;
|
|
404
|
+
case import_opticore_catch_exception_error3.CErrorName.errHttpHeadersSent:
|
|
405
|
+
(void 0).internalErrors.errHttpHeadersSent(err);
|
|
406
|
+
break;
|
|
407
|
+
case import_opticore_catch_exception_error3.CErrorName.errStreamDestroyed:
|
|
408
|
+
(void 0).internalErrors.errStreamDestroyed(err);
|
|
409
|
+
break;
|
|
410
|
+
case import_opticore_catch_exception_error3.CErrorName.errTlsCertAltnameInvalid:
|
|
411
|
+
(void 0).internalErrors.errTlsCertAltNameInvalid(err);
|
|
412
|
+
break;
|
|
413
|
+
case import_opticore_catch_exception_error3.CErrorName.errUnsupportedEsmUrlScheme:
|
|
414
|
+
(void 0).internalErrors.errUnsupportedEsmUrlScheme(err);
|
|
415
|
+
break;
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
306
419
|
// src/core/webServer.core.ts
|
|
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
426
|
port;
|
|
313
427
|
host;
|
|
314
|
-
|
|
428
|
+
serverListenEvent;
|
|
429
|
+
javaScriptErrors;
|
|
430
|
+
internalErrors;
|
|
431
|
+
assertionErrors;
|
|
432
|
+
openSSLErrors;
|
|
433
|
+
systemErrors;
|
|
434
|
+
constructor(app, loggerConfig2, localLanguage, corsOriginOptions) {
|
|
315
435
|
this.port = Number(import_opticore_env_access.getEnvVariable.appPort);
|
|
316
436
|
this.host = import_opticore_env_access.getEnvVariable.appHost;
|
|
317
437
|
this.routerExpressApp = app;
|
|
318
|
-
this.loggerConfig =
|
|
438
|
+
this.loggerConfig = loggerConfig2;
|
|
439
|
+
this.localLanguage = localLanguage;
|
|
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
456
|
this.port,
|
|
330
457
|
this.host,
|
|
331
458
|
() => {
|
|
332
459
|
try {
|
|
333
460
|
if (this.host === "" && this.port === 0) {
|
|
334
|
-
|
|
461
|
+
this.serverListenEvent.hostPortUndefined(this.port);
|
|
335
462
|
} else if (this.host === "") {
|
|
336
|
-
|
|
463
|
+
this.serverListenEvent.hostUndefined(this.host);
|
|
337
464
|
} else if (this.port === 0) {
|
|
338
|
-
|
|
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(
|
|
488
|
+
serverWeb.on(import_opticore_catch_exception_error4.CEventNameError.request, (req, res) => {
|
|
362
489
|
(0, import_opticore_requests_called_events.requestCallsEvent)(req, res, this.host, this.port, dateTimeFormattedUtils);
|
|
363
490
|
});
|
|
364
491
|
}
|
|
@@ -366,7 +493,7 @@ var WebServerCore = class {
|
|
|
366
493
|
const require2 = (0, import_module.createRequire)(importMetaUrl);
|
|
367
494
|
const packagePath = path2.dirname(require2.resolve("opticore-webapp"));
|
|
368
495
|
const translateMsgJsonFilePath = path2.join(packagePath, "utils", "translations");
|
|
369
|
-
|
|
496
|
+
import_opticore_translator4.TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
370
497
|
}
|
|
371
498
|
registerRoutes(allFeatureRoutes) {
|
|
372
499
|
allFeatureRoutes.map((router) => {
|
|
@@ -375,8 +502,8 @@ var WebServerCore = class {
|
|
|
375
502
|
});
|
|
376
503
|
});
|
|
377
504
|
}
|
|
378
|
-
stackTraceErrorHandling(
|
|
379
|
-
eventProcessHandler(
|
|
505
|
+
stackTraceErrorHandling(localLanguage) {
|
|
506
|
+
eventProcessHandler(localLanguage);
|
|
380
507
|
}
|
|
381
508
|
infoWebApp() {
|
|
382
509
|
this.serverUtility.infoServer(
|
|
@@ -390,9 +517,6 @@ var WebServerCore = class {
|
|
|
390
517
|
this.serverUtility.getUsageMemory().system
|
|
391
518
|
);
|
|
392
519
|
}
|
|
393
|
-
traceError(props, name, status2) {
|
|
394
|
-
return new import_opticore_catch_exception_error3.StackTraceError(props, name, status2, true);
|
|
395
|
-
}
|
|
396
520
|
};
|
|
397
521
|
// Annotate the CommonJS export names for ESM import in node:
|
|
398
522
|
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
17
|
private readonly port;
|
|
17
18
|
private readonly host;
|
|
18
|
-
|
|
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, 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
17
|
private readonly port;
|
|
17
18
|
private readonly host;
|
|
18
|
-
|
|
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, 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,17 @@ 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
15
|
import { getEnvVariable } from "opticore-env-access";
|
|
12
16
|
import { requestCallsEvent } from "opticore-requests-called-events";
|
|
13
|
-
import {
|
|
14
|
-
import { TranslationLoader as TranslationLoader3 } from "opticore-translator";
|
|
17
|
+
import { TranslationLoader as TranslationLoader4 } from "opticore-translator";
|
|
15
18
|
|
|
16
19
|
// src/core/handlers/eventProcess.handler.ts
|
|
17
20
|
import process from "node:process";
|
|
@@ -25,49 +28,50 @@ import {
|
|
|
25
28
|
function eventProcessHandler(localeLanguage) {
|
|
26
29
|
const errorEmitter = new EventEmitter();
|
|
27
30
|
const app = express();
|
|
31
|
+
const serverListenEvent = new ServerListenEventError(localeLanguage);
|
|
28
32
|
errorEmitter.on(eventName.error, (error) => {
|
|
29
|
-
|
|
33
|
+
serverListenEvent.listenerError(error);
|
|
30
34
|
});
|
|
31
35
|
process.on(event.beforeExit, (code) => {
|
|
32
36
|
setTimeout(() => {
|
|
33
|
-
|
|
37
|
+
serverListenEvent.processBeforeExit(code);
|
|
34
38
|
}, 100);
|
|
35
39
|
});
|
|
36
40
|
process.on(event.disconnect, () => {
|
|
37
|
-
|
|
41
|
+
serverListenEvent.processDisconnected();
|
|
38
42
|
});
|
|
39
43
|
process.on(event.exit, (code) => {
|
|
40
|
-
|
|
44
|
+
serverListenEvent.exited(code);
|
|
41
45
|
});
|
|
42
46
|
process.on(event.rejectionHandled, (promise) => {
|
|
43
|
-
|
|
47
|
+
serverListenEvent.promiseRejectionHandled(promise);
|
|
44
48
|
});
|
|
45
49
|
process.on(event.uncaughtException, (error) => {
|
|
46
|
-
|
|
50
|
+
serverListenEvent.uncaughtException(error);
|
|
47
51
|
});
|
|
48
52
|
process.on(event.uncaughtExceptionMonitor, (error) => {
|
|
49
|
-
|
|
53
|
+
serverListenEvent.uncaughtExceptionMonitor(error);
|
|
50
54
|
});
|
|
51
55
|
process.on(event.unhandledRejection, (reason, promise) => {
|
|
52
|
-
|
|
56
|
+
serverListenEvent.unhandledRejection(reason, promise);
|
|
53
57
|
});
|
|
54
58
|
process.on(event.warning, (warning) => {
|
|
55
|
-
|
|
59
|
+
serverListenEvent.warning(warning);
|
|
56
60
|
});
|
|
57
61
|
process.on(event.message, (message) => {
|
|
58
|
-
|
|
62
|
+
serverListenEvent.message(message);
|
|
59
63
|
});
|
|
60
64
|
process.on(event.multipleResolves, (type, promise, reason) => {
|
|
61
|
-
|
|
65
|
+
serverListenEvent.multipleResolves(type, promise, reason);
|
|
62
66
|
});
|
|
63
67
|
process.on(event.sigint, () => {
|
|
64
|
-
|
|
68
|
+
serverListenEvent.processInterrupted();
|
|
65
69
|
});
|
|
66
70
|
process.on(event.sigterm, (signal) => {
|
|
67
|
-
|
|
71
|
+
serverListenEvent.sigtermSignalReceived(signal);
|
|
68
72
|
});
|
|
69
73
|
app.use((err, req, res, next) => {
|
|
70
|
-
|
|
74
|
+
serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
71
75
|
});
|
|
72
76
|
}
|
|
73
77
|
|
|
@@ -110,7 +114,7 @@ var LogMessageUtils = class {
|
|
|
110
114
|
|
|
111
115
|
// src/core/helpers/modulesLoaded.utils.ts
|
|
112
116
|
import { TranslationLoader } from "opticore-translator";
|
|
113
|
-
function modulesLoadedUtils(allAppRoutes, dbConChecker, localeLanguage
|
|
117
|
+
function modulesLoadedUtils(allAppRoutes, dbConChecker, localeLanguage) {
|
|
114
118
|
LogMessageUtils.success(
|
|
115
119
|
`${TranslationLoader.t("kernel", localeLanguage, loggerConfig)}`,
|
|
116
120
|
`${TranslationLoader.t("loadKernel", localeLanguage, loggerConfig)}`,
|
|
@@ -244,7 +248,7 @@ var CoreService = class {
|
|
|
244
248
|
console.log(`${`Memory usage by system :`} ${colors3.cyan(`${colors3.bold(`${system}`)}`)}`);
|
|
245
249
|
console.log(``);
|
|
246
250
|
}
|
|
247
|
-
coreListenerEventLoaderModuleService(kernelModule, localeLanguage,
|
|
251
|
+
coreListenerEventLoaderModuleService(kernelModule, localeLanguage, loggerConfig2) {
|
|
248
252
|
let router = [];
|
|
249
253
|
let dbCon;
|
|
250
254
|
kernelModule.forEach((module) => {
|
|
@@ -261,8 +265,8 @@ var CoreService = class {
|
|
|
261
265
|
})();
|
|
262
266
|
} else {
|
|
263
267
|
const stackTrace = new StackTraceError(
|
|
264
|
-
TranslationLoader2.t("loadedModulesError", localeLanguage,
|
|
265
|
-
TranslationLoader2.t("loadedModules", localeLanguage,
|
|
268
|
+
TranslationLoader2.t("loadedModulesError", localeLanguage, loggerConfig2),
|
|
269
|
+
TranslationLoader2.t("loadedModules", localeLanguage, loggerConfig2),
|
|
266
270
|
status.NOT_ACCEPTABLE,
|
|
267
271
|
true
|
|
268
272
|
);
|
|
@@ -271,56 +275,183 @@ var CoreService = class {
|
|
|
271
275
|
}
|
|
272
276
|
};
|
|
273
277
|
|
|
278
|
+
// src/application/service/serverStartError.service.ts
|
|
279
|
+
import assert from "assert";
|
|
280
|
+
import { CErrorName } from "opticore-catch-exception-error";
|
|
281
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
282
|
+
import { TranslationLoader as TranslationLoader3 } from "opticore-translator";
|
|
283
|
+
var SServerStartError = (err) => {
|
|
284
|
+
switch (err.name) {
|
|
285
|
+
case CErrorName.typeError:
|
|
286
|
+
(void 0).javaScriptErrors.typeError(err);
|
|
287
|
+
break;
|
|
288
|
+
case CErrorName.error:
|
|
289
|
+
(void 0).javaScriptErrors.allError(err);
|
|
290
|
+
break;
|
|
291
|
+
case CErrorName.evalError:
|
|
292
|
+
(void 0).javaScriptErrors.evalError(err);
|
|
293
|
+
break;
|
|
294
|
+
case CErrorName.referenceError:
|
|
295
|
+
(void 0).javaScriptErrors.referenceError(err);
|
|
296
|
+
break;
|
|
297
|
+
case CErrorName.rangeError:
|
|
298
|
+
(void 0).javaScriptErrors.rangeError(err);
|
|
299
|
+
break;
|
|
300
|
+
case CErrorName.syntaxError:
|
|
301
|
+
(void 0).javaScriptErrors.syntaxError(err);
|
|
302
|
+
break;
|
|
303
|
+
case CErrorName.uriError:
|
|
304
|
+
(void 0).javaScriptErrors.uRIError(err);
|
|
305
|
+
break;
|
|
306
|
+
case CErrorName.eacces:
|
|
307
|
+
(void 0).systemErrors.eAcces(err);
|
|
308
|
+
break;
|
|
309
|
+
case CErrorName.eaddrinuse:
|
|
310
|
+
(void 0).systemErrors.eAddrInUse(err);
|
|
311
|
+
break;
|
|
312
|
+
case CErrorName.econnrefused:
|
|
313
|
+
(void 0).systemErrors.eConnRefused(err);
|
|
314
|
+
break;
|
|
315
|
+
case CErrorName.econnreset:
|
|
316
|
+
(void 0).systemErrors.eConnReset(err);
|
|
317
|
+
break;
|
|
318
|
+
case CErrorName.eexist:
|
|
319
|
+
(void 0).systemErrors.eExist(err);
|
|
320
|
+
break;
|
|
321
|
+
case CErrorName.eisdir:
|
|
322
|
+
(void 0).systemErrors.eIsDir(err);
|
|
323
|
+
break;
|
|
324
|
+
case CErrorName.emfile:
|
|
325
|
+
(void 0).systemErrors.eMFile(err);
|
|
326
|
+
break;
|
|
327
|
+
case CErrorName.enoent:
|
|
328
|
+
(void 0).systemErrors.eNoEnt(err);
|
|
329
|
+
break;
|
|
330
|
+
case CErrorName.enotdir:
|
|
331
|
+
(void 0).systemErrors.eNotDir(err);
|
|
332
|
+
break;
|
|
333
|
+
case CErrorName.enotEmpty:
|
|
334
|
+
(void 0).systemErrors.eNotEmpty(err);
|
|
335
|
+
break;
|
|
336
|
+
case CErrorName.eperm:
|
|
337
|
+
(void 0).systemErrors.ePerm(err);
|
|
338
|
+
break;
|
|
339
|
+
case CErrorName.epipe:
|
|
340
|
+
(void 0).systemErrors.ePipe(err);
|
|
341
|
+
break;
|
|
342
|
+
case CErrorName.etimedout:
|
|
343
|
+
(void 0).systemErrors.eTimedOut(err);
|
|
344
|
+
break;
|
|
345
|
+
case CErrorName.assertionError:
|
|
346
|
+
(void 0).stackTrace = (void 0).traceError(err.message, err.name, HttpStatusCode.NOT_ACCEPTABLE);
|
|
347
|
+
err instanceof assert.AssertionError ? (void 0).logger.error(
|
|
348
|
+
TranslationLoader3.t((void 0).stackTrace.name, (void 0).localLanguage),
|
|
349
|
+
"AssertionError",
|
|
350
|
+
(void 0).stackTrace.name,
|
|
351
|
+
(void 0).stackTrace.stack,
|
|
352
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
353
|
+
) : (void 0).logger.error(
|
|
354
|
+
TranslationLoader3.t((void 0).stackTrace.name, (void 0).localLanguage),
|
|
355
|
+
"Another Error",
|
|
356
|
+
(void 0).stackTrace.name,
|
|
357
|
+
(void 0).stackTrace.stack,
|
|
358
|
+
HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
359
|
+
);
|
|
360
|
+
break;
|
|
361
|
+
case CErrorName.errOsslEvpUnsupported:
|
|
362
|
+
(void 0).openSSLErrors.errOsSLEvpUnsupported(err);
|
|
363
|
+
break;
|
|
364
|
+
case CErrorName.errOsslBadDecrypt:
|
|
365
|
+
(void 0).openSSLErrors.errOsSLBadDecrypt(err);
|
|
366
|
+
break;
|
|
367
|
+
case CErrorName.errOsslWrongFinalBlockLength:
|
|
368
|
+
(void 0).openSSLErrors.errOsSLWrongFinalBlockLength(err);
|
|
369
|
+
break;
|
|
370
|
+
case CErrorName.errInvalidArgType:
|
|
371
|
+
(void 0).internalErrors.errInvalidArgType(err);
|
|
372
|
+
break;
|
|
373
|
+
case CErrorName.errInvalidCallback:
|
|
374
|
+
(void 0).internalErrors.errInvalidCallback(err);
|
|
375
|
+
break;
|
|
376
|
+
case CErrorName.errHttpHeadersSent:
|
|
377
|
+
(void 0).internalErrors.errHttpHeadersSent(err);
|
|
378
|
+
break;
|
|
379
|
+
case CErrorName.errStreamDestroyed:
|
|
380
|
+
(void 0).internalErrors.errStreamDestroyed(err);
|
|
381
|
+
break;
|
|
382
|
+
case CErrorName.errTlsCertAltnameInvalid:
|
|
383
|
+
(void 0).internalErrors.errTlsCertAltNameInvalid(err);
|
|
384
|
+
break;
|
|
385
|
+
case CErrorName.errUnsupportedEsmUrlScheme:
|
|
386
|
+
(void 0).internalErrors.errUnsupportedEsmUrlScheme(err);
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
|
|
274
391
|
// src/core/webServer.core.ts
|
|
275
392
|
var WebServerCore = class {
|
|
276
393
|
serverUtility = new CoreService();
|
|
277
394
|
expressApp = express2();
|
|
395
|
+
localLanguage;
|
|
278
396
|
loggerConfig;
|
|
279
397
|
routerExpressApp;
|
|
280
398
|
port;
|
|
281
399
|
host;
|
|
282
|
-
|
|
400
|
+
serverListenEvent;
|
|
401
|
+
javaScriptErrors;
|
|
402
|
+
internalErrors;
|
|
403
|
+
assertionErrors;
|
|
404
|
+
openSSLErrors;
|
|
405
|
+
systemErrors;
|
|
406
|
+
constructor(app, loggerConfig2, localLanguage, corsOriginOptions) {
|
|
283
407
|
this.port = Number(getEnvVariable.appPort);
|
|
284
408
|
this.host = getEnvVariable.appHost;
|
|
285
409
|
this.routerExpressApp = app;
|
|
286
|
-
this.loggerConfig =
|
|
410
|
+
this.loggerConfig = loggerConfig2;
|
|
411
|
+
this.localLanguage = localLanguage;
|
|
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
428
|
this.port,
|
|
298
429
|
this.host,
|
|
299
430
|
() => {
|
|
300
431
|
try {
|
|
301
432
|
if (this.host === "" && this.port === 0) {
|
|
302
|
-
|
|
433
|
+
this.serverListenEvent.hostPortUndefined(this.port);
|
|
303
434
|
} else if (this.host === "") {
|
|
304
|
-
|
|
435
|
+
this.serverListenEvent.hostUndefined(this.host);
|
|
305
436
|
} else if (this.port === 0) {
|
|
306
|
-
|
|
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
|
});
|
|
@@ -334,7 +465,7 @@ var WebServerCore = class {
|
|
|
334
465
|
const require2 = createRequire(import.meta.url);
|
|
335
466
|
const packagePath = path2.dirname(require2.resolve("opticore-webapp"));
|
|
336
467
|
const translateMsgJsonFilePath = path2.join(packagePath, "utils", "translations");
|
|
337
|
-
|
|
468
|
+
TranslationLoader4.loadTranslations(translateMsgJsonFilePath);
|
|
338
469
|
}
|
|
339
470
|
registerRoutes(allFeatureRoutes) {
|
|
340
471
|
allFeatureRoutes.map((router) => {
|
|
@@ -343,8 +474,8 @@ var WebServerCore = class {
|
|
|
343
474
|
});
|
|
344
475
|
});
|
|
345
476
|
}
|
|
346
|
-
stackTraceErrorHandling(
|
|
347
|
-
eventProcessHandler(
|
|
477
|
+
stackTraceErrorHandling(localLanguage) {
|
|
478
|
+
eventProcessHandler(localLanguage);
|
|
348
479
|
}
|
|
349
480
|
infoWebApp() {
|
|
350
481
|
this.serverUtility.infoServer(
|
|
@@ -358,9 +489,6 @@ var WebServerCore = class {
|
|
|
358
489
|
this.serverUtility.getUsageMemory().system
|
|
359
490
|
);
|
|
360
491
|
}
|
|
361
|
-
traceError(props, name, status2) {
|
|
362
|
-
return new StackTraceError2(props, name, status2, true);
|
|
363
|
-
}
|
|
364
492
|
};
|
|
365
493
|
export {
|
|
366
494
|
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.18",
|
|
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.
|
|
32
|
+
"opticore-catch-exception-error": "^1.0.17",
|
|
33
33
|
"opticore-env-access": "^1.0.2",
|
|
34
34
|
"opticore-express": "^1.0.3",
|
|
35
35
|
"opticore-http-response": "^1.0.3",
|
|
36
36
|
"opticore-logger": "^1.0.13",
|
|
37
37
|
"opticore-requests-called-events": "^1.0.0",
|
|
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 = 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,7 +7,7 @@ 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
12
|
`${TranslationLoader.t("kernel", localeLanguage, loggerConfig)}`,
|
|
13
13
|
`${TranslationLoader.t("loadKernel", localeLanguage, loggerConfig)}`,
|
|
@@ -6,13 +6,18 @@ 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
19
|
import { getEnvVariable } from "opticore-env-access";
|
|
14
20
|
import { requestCallsEvent } from "opticore-requests-called-events";
|
|
15
|
-
import { HttpStatusCode } from "opticore-http-response";
|
|
16
21
|
import { TranslationLoader } from "opticore-translator";
|
|
17
22
|
import { LoggerCore } from "opticore-logger";
|
|
18
23
|
|
|
@@ -20,23 +25,33 @@ import { IRouteDefinition } from "@webApp/domains/interfaces/routeDefinition.int
|
|
|
20
25
|
import { eventProcessHandler } from "@webApp/core/handlers/eventProcess.handler";
|
|
21
26
|
import { CoreService } from "@webApp/application/service/core.service";
|
|
22
27
|
import { dateTimeFormattedUtils as currentDate } from "@webApp/core/helpers/dateTimeFormatted.utils";
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
import { SServerStartError } from "@webApp/application/service/serverStartError.service";
|
|
25
29
|
|
|
26
30
|
|
|
27
31
|
export class WebServerCore {
|
|
28
32
|
private serverUtility: CoreService = new CoreService();
|
|
33
|
+
|
|
29
34
|
private expressApp = express();
|
|
35
|
+
|
|
36
|
+
private readonly localLanguage: string;
|
|
30
37
|
private readonly loggerConfig: LoggerCore;
|
|
31
38
|
private readonly routerExpressApp: express.Application;
|
|
32
39
|
private readonly port: number;
|
|
33
40
|
private readonly host: string;
|
|
34
41
|
|
|
35
|
-
|
|
42
|
+
private serverListenEvent: ServerListenEventError;
|
|
43
|
+
private javaScriptErrors: JavaScriptErrors;
|
|
44
|
+
private internalErrors: InternalErrors;
|
|
45
|
+
private assertionErrors: AssertionErrors;
|
|
46
|
+
private openSSLErrors: OpenSSLErrors;
|
|
47
|
+
private systemErrors: SystemErrors;
|
|
48
|
+
|
|
49
|
+
constructor(app: express.Application, loggerConfig: LoggerCore, localLanguage: string, corsOriginOptions?: Partial<CorsOptions>) {
|
|
36
50
|
this.port = Number(getEnvVariable.appPort);
|
|
37
51
|
this.host = getEnvVariable.appHost;
|
|
38
52
|
this.routerExpressApp = app;
|
|
39
53
|
this.loggerConfig = loggerConfig;
|
|
54
|
+
this.localLanguage = localLanguage;
|
|
40
55
|
|
|
41
56
|
this.expressApp.use(express.json());
|
|
42
57
|
this.expressApp.use(express.raw());
|
|
@@ -44,40 +59,48 @@ export class WebServerCore {
|
|
|
44
59
|
this.expressApp.use(express.urlencoded({ extended: true }));
|
|
45
60
|
this.expressApp.use(corsOrigin(corsOriginOptions));
|
|
46
61
|
|
|
47
|
-
this.
|
|
62
|
+
this.serverListenEvent = new ServerListenEventError(localLanguage);
|
|
63
|
+
this.javaScriptErrors = new JavaScriptErrors(localLanguage);
|
|
64
|
+
this.assertionErrors = new AssertionErrors(localLanguage);
|
|
65
|
+
this.internalErrors = new InternalErrors(localLanguage);
|
|
66
|
+
this.openSSLErrors = new OpenSSLErrors(localLanguage);
|
|
67
|
+
this.systemErrors = new SystemErrors(localLanguage);
|
|
68
|
+
|
|
69
|
+
this.stackTraceErrorHandling(localLanguage);
|
|
48
70
|
this.translationWebAppLoader();
|
|
49
71
|
}
|
|
50
72
|
|
|
51
|
-
|
|
73
|
+
|
|
74
|
+
public onStartServer(routers: { featureRoute: IRouteDefinition[] }[]) {
|
|
52
75
|
return this.expressApp.listen(
|
|
53
76
|
this.port,
|
|
54
77
|
this.host,
|
|
55
78
|
(): void => {
|
|
56
79
|
try {
|
|
57
80
|
if (this.host === "" && this.port === 0) {
|
|
58
|
-
|
|
81
|
+
this.serverListenEvent.hostPortUndefined(this.port);
|
|
59
82
|
} else if (this.host === "") {
|
|
60
|
-
|
|
83
|
+
this.serverListenEvent.hostUndefined(this.host);
|
|
61
84
|
} else if (this.port === 0) {
|
|
62
|
-
|
|
85
|
+
this.serverListenEvent.portUndefined();
|
|
63
86
|
} else {
|
|
64
87
|
this.registerRoutes(routers);
|
|
65
88
|
}
|
|
66
89
|
} catch (err: any) {
|
|
67
|
-
|
|
90
|
+
SServerStartError(err);
|
|
68
91
|
}
|
|
69
92
|
}
|
|
70
93
|
);
|
|
71
94
|
}
|
|
72
95
|
|
|
73
96
|
//, kernelModule: KernelModuleType
|
|
74
|
-
public onListeningOnServerEvent(serverWeb: serverWebApp,
|
|
97
|
+
public onListeningOnServerEvent(serverWeb: serverWebApp, localLanguage: string): void {
|
|
75
98
|
serverWeb.on(eventName.error, (err: Error): void => {
|
|
76
|
-
|
|
99
|
+
this.serverListenEvent.onEventError(err);
|
|
77
100
|
}).on(eventName.close, (): void => {
|
|
78
|
-
|
|
101
|
+
this.serverListenEvent.serverClosing();
|
|
79
102
|
}).on(eventName.drop, (): void => {
|
|
80
|
-
|
|
103
|
+
this.serverListenEvent.dropNewConnection();
|
|
81
104
|
}).on(eventName.listening, (): void => {
|
|
82
105
|
this.infoWebApp();
|
|
83
106
|
//this.serverUtility.coreListenerEventLoaderModuleService(kernelModule);
|
|
@@ -95,7 +118,7 @@ export class WebServerCore {
|
|
|
95
118
|
const packagePath: string = path.dirname(require.resolve("opticore-webapp"));
|
|
96
119
|
|
|
97
120
|
const translateMsgJsonFilePath: string = path.join(packagePath, "utils", "translations");
|
|
98
|
-
TranslationLoader.loadTranslations(translateMsgJsonFilePath
|
|
121
|
+
TranslationLoader.loadTranslations(translateMsgJsonFilePath);
|
|
99
122
|
}
|
|
100
123
|
private registerRoutes(allFeatureRoutes: { featureRoute: IRouteDefinition[] }[]): void {
|
|
101
124
|
allFeatureRoutes.map((router: {featureRoute: IRouteDefinition[]} ): void => {
|
|
@@ -104,8 +127,8 @@ export class WebServerCore {
|
|
|
104
127
|
});
|
|
105
128
|
});
|
|
106
129
|
}
|
|
107
|
-
private stackTraceErrorHandling(
|
|
108
|
-
eventProcessHandler(
|
|
130
|
+
private stackTraceErrorHandling(localLanguage: string): void {
|
|
131
|
+
eventProcessHandler(localLanguage);
|
|
109
132
|
}
|
|
110
133
|
private infoWebApp(): void {
|
|
111
134
|
this.serverUtility.infoServer(
|
|
@@ -119,7 +142,4 @@ export class WebServerCore {
|
|
|
119
142
|
this.serverUtility.getUsageMemory().system
|
|
120
143
|
);
|
|
121
144
|
}
|
|
122
|
-
private traceError(props: string, name: string, status: number): StackTraceError {
|
|
123
|
-
return new StackTraceError(props, name, status, true);
|
|
124
|
-
}
|
|
125
145
|
}
|