opticore-webapp 1.0.18 → 1.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +98 -69
- package/dist/index.d.cts +13 -11
- package/dist/index.d.ts +13 -11
- package/dist/index.js +99 -70
- package/package.json +3 -3
- package/public/template/index.html +23 -0
- package/src/application/service/core.service.ts +0 -184
- package/src/application/service/serverStartError.service.ts +0 -112
- package/src/core/config/.gitkeep +0 -0
- package/src/core/events/.gitkeep +0 -0
- package/src/core/handlers/eventProcess.handler.ts +0 -112
- package/src/core/helpers/dateTimeFormatted.utils.ts +0 -6
- package/src/core/helpers/logMessage.utils.ts +0 -20
- package/src/core/helpers/modulesLoaded.utils.ts +0 -23
- package/src/core/webServer.core.ts +0 -145
- package/src/domains/interfaces/routeDefinition.interface.ts +0 -6
- package/src/domains/types/kernelModule.type.ts +0 -3
- package/src/index.ts +0 -11
- package/src/utils/translations/messages.exception.en.json +0 -78
- package/src/utils/translations/messages.exception.fr.json +0 -78
- package/tsup.config.ts +0 -11
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/core/webServer.core.ts
|
|
2
2
|
import * as path2 from "path";
|
|
3
|
+
import process3 from "node:process";
|
|
3
4
|
import { createRequire } from "module";
|
|
4
5
|
import corsOrigin from "cors";
|
|
5
6
|
import {
|
|
@@ -12,8 +13,7 @@ import {
|
|
|
12
13
|
SystemErrors
|
|
13
14
|
} from "opticore-catch-exception-error";
|
|
14
15
|
import { express as express2 } from "opticore-express";
|
|
15
|
-
import {
|
|
16
|
-
import { requestCallsEvent } from "opticore-requests-called-events";
|
|
16
|
+
import { getEnvironnementValue } from "opticore-env-access";
|
|
17
17
|
import { TranslationLoader as TranslationLoader4 } from "opticore-translator";
|
|
18
18
|
|
|
19
19
|
// src/core/handlers/eventProcess.handler.ts
|
|
@@ -82,7 +82,6 @@ import * as path from "path";
|
|
|
82
82
|
import * as fs from "fs";
|
|
83
83
|
import colors3 from "ansi-colors";
|
|
84
84
|
import { HttpStatusCode as status } from "opticore-http-response";
|
|
85
|
-
import { StackTraceError } from "opticore-catch-exception-error";
|
|
86
85
|
|
|
87
86
|
// src/core/helpers/modulesLoaded.utils.ts
|
|
88
87
|
import colors2 from "ansi-colors";
|
|
@@ -116,17 +115,25 @@ var LogMessageUtils = class {
|
|
|
116
115
|
import { TranslationLoader } from "opticore-translator";
|
|
117
116
|
function modulesLoadedUtils(allAppRoutes, dbConChecker, localeLanguage) {
|
|
118
117
|
LogMessageUtils.success(
|
|
119
|
-
`${TranslationLoader.t("kernel", localeLanguage
|
|
120
|
-
`${TranslationLoader.t("loadKernel", localeLanguage
|
|
121
|
-
`${TranslationLoader.t("moduleAppLoaded", localeLanguage
|
|
118
|
+
`${TranslationLoader.t("kernel", localeLanguage)}`,
|
|
119
|
+
`${TranslationLoader.t("loadKernel", localeLanguage)}`,
|
|
120
|
+
`${TranslationLoader.t("moduleAppLoaded", localeLanguage)}`
|
|
122
121
|
);
|
|
123
|
-
console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", localeLanguage
|
|
124
|
-
allAppRoutes ? console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", localeLanguage
|
|
125
|
-
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`)}`) : "";
|
|
126
125
|
}
|
|
127
126
|
|
|
128
127
|
// src/application/service/core.service.ts
|
|
129
128
|
import { TranslationLoader as TranslationLoader2 } from "opticore-translator";
|
|
129
|
+
|
|
130
|
+
// src/application/service/traceError.service.ts
|
|
131
|
+
import { StackTraceError } from "opticore-catch-exception-error";
|
|
132
|
+
var STraceError = (props, name, httpCode, isOperational) => {
|
|
133
|
+
return new StackTraceError(props, name, httpCode, isOperational);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/application/service/core.service.ts
|
|
130
137
|
var CoreService = class {
|
|
131
138
|
/**
|
|
132
139
|
*
|
|
@@ -248,7 +255,7 @@ var CoreService = class {
|
|
|
248
255
|
console.log(`${`Memory usage by system :`} ${colors3.cyan(`${colors3.bold(`${system}`)}`)}`);
|
|
249
256
|
console.log(``);
|
|
250
257
|
}
|
|
251
|
-
coreListenerEventLoaderModuleService(kernelModule,
|
|
258
|
+
coreListenerEventLoaderModuleService(kernelModule, localLanguage, loggerConfig) {
|
|
252
259
|
let router = [];
|
|
253
260
|
let dbCon;
|
|
254
261
|
kernelModule.forEach((module) => {
|
|
@@ -259,14 +266,14 @@ var CoreService = class {
|
|
|
259
266
|
}
|
|
260
267
|
});
|
|
261
268
|
if (router && dbCon) {
|
|
262
|
-
modulesLoadedUtils(router, dbCon);
|
|
269
|
+
modulesLoadedUtils(router, dbCon, localLanguage);
|
|
263
270
|
(() => {
|
|
264
271
|
dbCon();
|
|
265
272
|
})();
|
|
266
273
|
} else {
|
|
267
|
-
const stackTrace =
|
|
268
|
-
TranslationLoader2.t("loadedModulesError",
|
|
269
|
-
TranslationLoader2.t("loadedModules",
|
|
274
|
+
const stackTrace = STraceError(
|
|
275
|
+
TranslationLoader2.t("loadedModulesError", localLanguage, loggerConfig),
|
|
276
|
+
TranslationLoader2.t("loadedModules", localLanguage, loggerConfig),
|
|
270
277
|
status.NOT_ACCEPTABLE,
|
|
271
278
|
true
|
|
272
279
|
);
|
|
@@ -280,135 +287,141 @@ import assert from "assert";
|
|
|
280
287
|
import { CErrorName } from "opticore-catch-exception-error";
|
|
281
288
|
import { HttpStatusCode } from "opticore-http-response";
|
|
282
289
|
import { TranslationLoader as TranslationLoader3 } from "opticore-translator";
|
|
283
|
-
var SServerStartError = (err) => {
|
|
290
|
+
var SServerStartError = (err, javaScriptErrors, systemErrors, openSSLErrors, internalErrors, logger, localLanguage) => {
|
|
284
291
|
switch (err.name) {
|
|
285
292
|
case CErrorName.typeError:
|
|
286
|
-
|
|
293
|
+
javaScriptErrors.typeError(err);
|
|
287
294
|
break;
|
|
288
295
|
case CErrorName.error:
|
|
289
|
-
|
|
296
|
+
javaScriptErrors.allError(err);
|
|
290
297
|
break;
|
|
291
298
|
case CErrorName.evalError:
|
|
292
|
-
|
|
299
|
+
javaScriptErrors.evalError(err);
|
|
293
300
|
break;
|
|
294
301
|
case CErrorName.referenceError:
|
|
295
|
-
|
|
302
|
+
javaScriptErrors.referenceError(err);
|
|
296
303
|
break;
|
|
297
304
|
case CErrorName.rangeError:
|
|
298
|
-
|
|
305
|
+
javaScriptErrors.rangeError(err);
|
|
299
306
|
break;
|
|
300
307
|
case CErrorName.syntaxError:
|
|
301
|
-
|
|
308
|
+
javaScriptErrors.syntaxError(err);
|
|
302
309
|
break;
|
|
303
310
|
case CErrorName.uriError:
|
|
304
|
-
|
|
311
|
+
javaScriptErrors.uRIError(err);
|
|
305
312
|
break;
|
|
306
313
|
case CErrorName.eacces:
|
|
307
|
-
|
|
314
|
+
systemErrors.eAcces(err);
|
|
308
315
|
break;
|
|
309
316
|
case CErrorName.eaddrinuse:
|
|
310
|
-
|
|
317
|
+
systemErrors.eAddrInUse(err);
|
|
311
318
|
break;
|
|
312
319
|
case CErrorName.econnrefused:
|
|
313
|
-
|
|
320
|
+
systemErrors.eConnRefused(err);
|
|
314
321
|
break;
|
|
315
322
|
case CErrorName.econnreset:
|
|
316
|
-
|
|
323
|
+
systemErrors.eConnReset(err);
|
|
317
324
|
break;
|
|
318
325
|
case CErrorName.eexist:
|
|
319
|
-
|
|
326
|
+
systemErrors.eExist(err);
|
|
320
327
|
break;
|
|
321
328
|
case CErrorName.eisdir:
|
|
322
|
-
|
|
329
|
+
systemErrors.eIsDir(err);
|
|
323
330
|
break;
|
|
324
331
|
case CErrorName.emfile:
|
|
325
|
-
|
|
332
|
+
systemErrors.eMFile(err);
|
|
326
333
|
break;
|
|
327
334
|
case CErrorName.enoent:
|
|
328
|
-
|
|
335
|
+
systemErrors.eNoEnt(err);
|
|
329
336
|
break;
|
|
330
337
|
case CErrorName.enotdir:
|
|
331
|
-
|
|
338
|
+
systemErrors.eNotDir(err);
|
|
332
339
|
break;
|
|
333
340
|
case CErrorName.enotEmpty:
|
|
334
|
-
|
|
341
|
+
systemErrors.eNotEmpty(err);
|
|
335
342
|
break;
|
|
336
343
|
case CErrorName.eperm:
|
|
337
|
-
|
|
344
|
+
systemErrors.ePerm(err);
|
|
338
345
|
break;
|
|
339
346
|
case CErrorName.epipe:
|
|
340
|
-
|
|
347
|
+
systemErrors.ePipe(err);
|
|
341
348
|
break;
|
|
342
349
|
case CErrorName.etimedout:
|
|
343
|
-
|
|
350
|
+
systemErrors.eTimedOut(err);
|
|
344
351
|
break;
|
|
345
352
|
case CErrorName.assertionError:
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
353
|
+
const stackTrace = STraceError(
|
|
354
|
+
err.message,
|
|
355
|
+
err.name,
|
|
356
|
+
HttpStatusCode.NOT_ACCEPTABLE,
|
|
357
|
+
true
|
|
358
|
+
);
|
|
359
|
+
err instanceof assert.AssertionError ? logger.error(
|
|
360
|
+
TranslationLoader3.t(stackTrace.name, localLanguage),
|
|
349
361
|
"AssertionError",
|
|
350
|
-
|
|
351
|
-
|
|
362
|
+
stackTrace.name,
|
|
363
|
+
stackTrace.stack,
|
|
352
364
|
HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
353
|
-
) :
|
|
354
|
-
TranslationLoader3.t(
|
|
365
|
+
) : logger.error(
|
|
366
|
+
TranslationLoader3.t(stackTrace.name, localLanguage),
|
|
355
367
|
"Another Error",
|
|
356
|
-
|
|
357
|
-
|
|
368
|
+
stackTrace.name,
|
|
369
|
+
stackTrace.stack,
|
|
358
370
|
HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
359
371
|
);
|
|
360
372
|
break;
|
|
361
373
|
case CErrorName.errOsslEvpUnsupported:
|
|
362
|
-
|
|
374
|
+
openSSLErrors.errOsSLEvpUnsupported(err);
|
|
363
375
|
break;
|
|
364
376
|
case CErrorName.errOsslBadDecrypt:
|
|
365
|
-
|
|
377
|
+
openSSLErrors.errOsSLBadDecrypt(err);
|
|
366
378
|
break;
|
|
367
379
|
case CErrorName.errOsslWrongFinalBlockLength:
|
|
368
|
-
|
|
380
|
+
openSSLErrors.errOsSLWrongFinalBlockLength(err);
|
|
369
381
|
break;
|
|
370
382
|
case CErrorName.errInvalidArgType:
|
|
371
|
-
|
|
383
|
+
internalErrors.errInvalidArgType(err);
|
|
372
384
|
break;
|
|
373
385
|
case CErrorName.errInvalidCallback:
|
|
374
|
-
|
|
386
|
+
internalErrors.errInvalidCallback(err);
|
|
375
387
|
break;
|
|
376
388
|
case CErrorName.errHttpHeadersSent:
|
|
377
|
-
|
|
389
|
+
internalErrors.errHttpHeadersSent(err);
|
|
378
390
|
break;
|
|
379
391
|
case CErrorName.errStreamDestroyed:
|
|
380
|
-
|
|
392
|
+
internalErrors.errStreamDestroyed(err);
|
|
381
393
|
break;
|
|
382
394
|
case CErrorName.errTlsCertAltnameInvalid:
|
|
383
|
-
|
|
395
|
+
internalErrors.errTlsCertAltNameInvalid(err);
|
|
384
396
|
break;
|
|
385
397
|
case CErrorName.errUnsupportedEsmUrlScheme:
|
|
386
|
-
|
|
398
|
+
internalErrors.errUnsupportedEsmUrlScheme(err);
|
|
387
399
|
break;
|
|
388
400
|
}
|
|
389
401
|
};
|
|
390
402
|
|
|
391
403
|
// src/core/webServer.core.ts
|
|
404
|
+
import { requestCallsEvent } from "opticore-request-call-event";
|
|
392
405
|
var WebServerCore = class {
|
|
393
406
|
serverUtility = new CoreService();
|
|
394
407
|
expressApp = express2();
|
|
395
408
|
localLanguage;
|
|
396
409
|
loggerConfig;
|
|
397
410
|
routerExpressApp;
|
|
398
|
-
|
|
399
|
-
|
|
411
|
+
getEnvironnement;
|
|
412
|
+
environnementPath;
|
|
400
413
|
serverListenEvent;
|
|
401
414
|
javaScriptErrors;
|
|
402
415
|
internalErrors;
|
|
403
416
|
assertionErrors;
|
|
404
417
|
openSSLErrors;
|
|
405
418
|
systemErrors;
|
|
406
|
-
constructor(app,
|
|
407
|
-
this.
|
|
408
|
-
this.host = getEnvVariable.appHost;
|
|
419
|
+
constructor(app, loggerConfig, localLanguage, environnementPath, corsOriginOptions) {
|
|
420
|
+
this.getEnvironnement = getEnvironnementValue(environnementPath);
|
|
409
421
|
this.routerExpressApp = app;
|
|
410
|
-
this.loggerConfig =
|
|
422
|
+
this.loggerConfig = loggerConfig;
|
|
411
423
|
this.localLanguage = localLanguage;
|
|
424
|
+
this.environnementPath = environnementPath;
|
|
412
425
|
this.expressApp.use(express2.json());
|
|
413
426
|
this.expressApp.use(express2.raw());
|
|
414
427
|
this.expressApp.use(express2.text());
|
|
@@ -425,21 +438,29 @@ var WebServerCore = class {
|
|
|
425
438
|
}
|
|
426
439
|
onStartServer(routers) {
|
|
427
440
|
return this.expressApp.listen(
|
|
428
|
-
this.
|
|
429
|
-
this.host,
|
|
441
|
+
Number(this.getEnvironnement.appPort),
|
|
430
442
|
() => {
|
|
431
443
|
try {
|
|
432
|
-
if (this.
|
|
433
|
-
this.serverListenEvent.hostPortUndefined(this.
|
|
434
|
-
} else if (this.
|
|
435
|
-
this.serverListenEvent.hostUndefined(this.
|
|
436
|
-
} else if (this.
|
|
444
|
+
if (this.getEnvironnement.appHost === "" && Number(this.getEnvironnement.appPort) === 0) {
|
|
445
|
+
this.serverListenEvent.hostPortUndefined(Number(this.getEnvironnement.appPort));
|
|
446
|
+
} else if (this.getEnvironnement.appHost === "") {
|
|
447
|
+
this.serverListenEvent.hostUndefined(this.getEnvironnement.appHost);
|
|
448
|
+
} else if (Number(this.getEnvironnement.appPort) === 0) {
|
|
437
449
|
this.serverListenEvent.portUndefined();
|
|
438
450
|
} else {
|
|
451
|
+
this.expressApp.use(express2.static(path2.join(process3.cwd(), "public/template")));
|
|
439
452
|
this.registerRoutes(routers);
|
|
440
453
|
}
|
|
441
454
|
} catch (err) {
|
|
442
|
-
SServerStartError(
|
|
455
|
+
SServerStartError(
|
|
456
|
+
err,
|
|
457
|
+
this.javaScriptErrors,
|
|
458
|
+
this.systemErrors,
|
|
459
|
+
this.openSSLErrors,
|
|
460
|
+
this.internalErrors,
|
|
461
|
+
this.loggerConfig,
|
|
462
|
+
this.localLanguage
|
|
463
|
+
);
|
|
443
464
|
}
|
|
444
465
|
}
|
|
445
466
|
);
|
|
@@ -458,7 +479,15 @@ var WebServerCore = class {
|
|
|
458
479
|
}
|
|
459
480
|
onRequestOnServerEvent(serverWeb) {
|
|
460
481
|
serverWeb.on(eventName2.request, (req, res) => {
|
|
461
|
-
requestCallsEvent(
|
|
482
|
+
requestCallsEvent(
|
|
483
|
+
req,
|
|
484
|
+
res,
|
|
485
|
+
this.getEnvironnement.appHost,
|
|
486
|
+
Number(this.getEnvironnement.appPort),
|
|
487
|
+
dateTimeFormattedUtils,
|
|
488
|
+
this.environnementPath,
|
|
489
|
+
this.localLanguage
|
|
490
|
+
);
|
|
462
491
|
});
|
|
463
492
|
}
|
|
464
493
|
translationWebAppLoader() {
|
|
@@ -481,8 +510,8 @@ var WebServerCore = class {
|
|
|
481
510
|
this.serverUtility.infoServer(
|
|
482
511
|
this.serverUtility.getVersions().nodeVersion,
|
|
483
512
|
this.serverUtility.getProjectInfo().startingTime,
|
|
484
|
-
|
|
485
|
-
Number(
|
|
513
|
+
this.getEnvironnement.appHost,
|
|
514
|
+
Number(this.getEnvironnement.appPort),
|
|
486
515
|
this.serverUtility.getUsageMemory().rss,
|
|
487
516
|
this.serverUtility.getUsageMemory().heapUsed,
|
|
488
517
|
this.serverUtility.getUsageMemory().user,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opticore-webapp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"description": "wep server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"dotenv": "^16.4.7",
|
|
31
31
|
"gradient-string": "^2.0.2",
|
|
32
32
|
"opticore-catch-exception-error": "^1.0.17",
|
|
33
|
-
"opticore-env-access": "^1.0.
|
|
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
39
|
"opticore-translator": "^1.0.7",
|
|
40
40
|
"opticore-validator": "^1.0.3"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="fr">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>OptiCore</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
background-color: #f0f0f0;
|
|
11
|
+
text-align: center;
|
|
12
|
+
padding: 50px;
|
|
13
|
+
}
|
|
14
|
+
h1 {
|
|
15
|
+
color: #333;
|
|
16
|
+
}
|
|
17
|
+
</style>
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<h1>Bienvenue sur la vue par défaut !</h1>
|
|
21
|
+
<p>Ceci est une page HTML servie par Express.js.</p>
|
|
22
|
+
</body>
|
|
23
|
+
</html>
|
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import process from "node:process";
|
|
2
|
-
import chalk from 'chalk';
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
import * as fs from "fs";
|
|
5
|
-
import colors from "ansi-colors";
|
|
6
|
-
|
|
7
|
-
import { HttpStatusCode as status } from "opticore-http-response";
|
|
8
|
-
import { StackTraceError } from "opticore-catch-exception-error";
|
|
9
|
-
import { Router } from "opticore-express";
|
|
10
|
-
|
|
11
|
-
import { KernelModuleType } from "@webApp/domains/types/kernelModule.type";
|
|
12
|
-
import { modulesLoadedUtils as loadedModules } from "@webApp/core/helpers/modulesLoaded.utils";
|
|
13
|
-
import { TranslationLoader } from "opticore-translator";
|
|
14
|
-
import { LoggerCore } from "opticore-logger";
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export class CoreService {
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @param data
|
|
23
|
-
* @private
|
|
24
|
-
* Return a string converted in MegaBytes
|
|
25
|
-
*/
|
|
26
|
-
private formatMemoryUsage(data: any): string {
|
|
27
|
-
return `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns an Object containing a node version, openssl, and v0
|
|
32
|
-
*/
|
|
33
|
-
public getVersions() {
|
|
34
|
-
const { node, openssl, v8 }: NodeJS.ProcessVersions = process.versions;
|
|
35
|
-
const data = {
|
|
36
|
-
"node version" : node,
|
|
37
|
-
"openssl": openssl,
|
|
38
|
-
"v8": v8
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
"nodeVersion" : data["node version"],
|
|
43
|
-
"openssl": data.openssl,
|
|
44
|
-
"v8": data.v8
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Return an Object containing a Resident Set Size - total memory allocated for the process execution
|
|
50
|
-
* Total size of the allocated heap
|
|
51
|
-
* Actual memory used during the execution
|
|
52
|
-
* Memory usage user
|
|
53
|
-
* and Memory usage system
|
|
54
|
-
*/
|
|
55
|
-
public getUsageMemory() {
|
|
56
|
-
const memoryData: NodeJS.MemoryUsage = process.memoryUsage();
|
|
57
|
-
const data = {
|
|
58
|
-
"Resident Set Size - total memory allocated for the process execution": this.formatMemoryUsage(memoryData.rss),
|
|
59
|
-
"Total size of the allocated heap": this.formatMemoryUsage(memoryData.heapTotal),
|
|
60
|
-
"Actual memory used during the execution": this.formatMemoryUsage(memoryData.heapUsed),
|
|
61
|
-
"V8 external memory": this.formatMemoryUsage(memoryData.external),
|
|
62
|
-
"Memory usage user": this.formatMemoryUsage(process.cpuUsage().user),
|
|
63
|
-
"Memory usage system": this.formatMemoryUsage(process.cpuUsage().system),
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
"rss": data["Resident Set Size - total memory allocated for the process execution"],
|
|
68
|
-
"heapTotal": data["Total size of the allocated heap"],
|
|
69
|
-
"heapUsed": data["Actual memory used during the execution"],
|
|
70
|
-
"external": data["V8 external memory"],
|
|
71
|
-
"user": data["Memory usage user"],
|
|
72
|
-
"system": data["Memory usage system"]
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Return an Object containing a project path and running server time
|
|
78
|
-
*/
|
|
79
|
-
public getProjectInfo() {
|
|
80
|
-
const startTime:[number, number] = process.hrtime();
|
|
81
|
-
const endTime:[number, number] = process.hrtime(startTime);
|
|
82
|
-
const executionTime: number = (endTime[0] * 1e9 + endTime[1]) / 1e6; // Convertir en millisecondes
|
|
83
|
-
return {
|
|
84
|
-
"projectPath": path.join(process.cwd()),
|
|
85
|
-
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
*
|
|
91
|
-
* @param filePath
|
|
92
|
-
* @private
|
|
93
|
-
*/
|
|
94
|
-
private getEnvFileLoading(filePath: string): void {
|
|
95
|
-
const fullPath: string = path.resolve(process.cwd(), filePath);
|
|
96
|
-
if (fs.existsSync(fullPath)) {
|
|
97
|
-
const env: string = fs.readFileSync(fullPath, 'utf-8');
|
|
98
|
-
const lines: string[] = env.split('\n');
|
|
99
|
-
|
|
100
|
-
lines.forEach((line: string): void => {
|
|
101
|
-
const match: RegExpMatchArray | null = line.match(/^([^#=]+)=([^#]+)$/);
|
|
102
|
-
if (match) {
|
|
103
|
-
const key: string = match[1].trim();
|
|
104
|
-
process.env[key] = match[2].trim();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
*
|
|
112
|
-
* @param development
|
|
113
|
-
* @param production
|
|
114
|
-
*/
|
|
115
|
-
public getServerRunningMode(development: string, production: string, ): string {
|
|
116
|
-
/**
|
|
117
|
-
* Load environment variables from the .env file
|
|
118
|
-
*/
|
|
119
|
-
this.getEnvFileLoading('.env');
|
|
120
|
-
|
|
121
|
-
const isDevelopment: boolean = process.env.NODE_ENV === 'development';
|
|
122
|
-
if (isDevelopment) {
|
|
123
|
-
return `The server is running in ${colors.bgBlue(`${colors.bold(`${development}`)}`)} mode`;
|
|
124
|
-
} else {
|
|
125
|
-
return `The server is running in ${colors.bgBlue(`${colors.bold(`${production}`)}`)} mode`;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public infoServer(nodeVersion: string, startingTime: any, host: string, port: number, rss: string, heapUsed: string, user: string, system: string): void {
|
|
130
|
-
// Padding length
|
|
131
|
-
const paddingLength = 52;
|
|
132
|
-
|
|
133
|
-
// Creating padded messages
|
|
134
|
-
const msg0: string = ' '.padEnd(paddingLength, ' ');
|
|
135
|
-
const msg1: string = ' [OK] Web server listening';
|
|
136
|
-
const msg2Value: string = `${colors.bgBlue(`${colors.bold(`${nodeVersion}`)}`)}`;
|
|
137
|
-
const msg2: string = ` The Web server is using Node.js version`;
|
|
138
|
-
const msg3Value: string = `${colors.bgBlue(`${colors.bold(`${startingTime}`)}`)}`;
|
|
139
|
-
const msg3: string = ` Startup time:`;
|
|
140
|
-
const msg4: string = ` ${this.getServerRunningMode('development', 'production')}`;
|
|
141
|
-
const msg5: string = ` ${colors.underline(`http://${host}:${port}`)}`;
|
|
142
|
-
|
|
143
|
-
// display the message
|
|
144
|
-
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, ' ')));
|
|
145
|
-
console.log(chalk.bgGreen.white(msg1.padEnd(paddingLength, ' ')));
|
|
146
|
-
console.log(chalk.bgGreen.white(msg2, msg2Value.padEnd(30.5, ' ')));
|
|
147
|
-
console.log(chalk.bgGreen.white(msg3, msg3Value.padEnd(56, ' ')));
|
|
148
|
-
console.log(chalk.bgGreen.white(msg4.padEnd(71, ' ')));
|
|
149
|
-
console.log(chalk.bgGreen.white(msg5.padEnd(61, ' ')));
|
|
150
|
-
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, ' ')));
|
|
151
|
-
console.log(``);
|
|
152
|
-
console.log(`${(`Resident Set Size - total memory allocated for the process execution :`)} ${colors.cyan(`${colors.bold(`${rss}`)}`)}`);
|
|
153
|
-
console.log(`${(`Actual memory used during the execution :`)} ${colors.cyan(`${colors.bold(`${heapUsed}`)}`)}`);
|
|
154
|
-
console.log(`${(`Memory usage by user :`)} ${colors.cyan(`${colors.bold(`${user}`)}`)}`);
|
|
155
|
-
console.log(`${(`Memory usage by system :`)} ${colors.cyan(`${colors.bold(`${system}`)}`)}`);
|
|
156
|
-
console.log(``);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
public coreListenerEventLoaderModuleService<T extends KernelModuleType>(kernelModule: T, localeLanguage: string, loggerConfig: LoggerCore) {
|
|
160
|
-
let router: Router[] = [];
|
|
161
|
-
let dbCon: (() => void) | undefined;
|
|
162
|
-
|
|
163
|
-
kernelModule.forEach((module): void => {
|
|
164
|
-
if (Array.isArray(module)) {
|
|
165
|
-
router = module as Router[];
|
|
166
|
-
} else if (typeof module === "function") {
|
|
167
|
-
dbCon = module as () => void;
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
if (router && dbCon) {
|
|
172
|
-
loadedModules(router, dbCon);
|
|
173
|
-
((): void => { dbCon(); })();
|
|
174
|
-
} else {
|
|
175
|
-
const stackTrace: StackTraceError = new StackTraceError(
|
|
176
|
-
TranslationLoader.t("loadedModulesError", localeLanguage, loggerConfig),
|
|
177
|
-
TranslationLoader.t("loadedModules", localeLanguage, loggerConfig),
|
|
178
|
-
status.NOT_ACCEPTABLE,
|
|
179
|
-
true
|
|
180
|
-
);
|
|
181
|
-
throw new Error(stackTrace.message);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
@@ -1,112 +0,0 @@
|
|
|
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
|
-
}
|