opticore-webapp 1.0.24 → 1.0.25
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/README.md +26 -0
- package/dist/index.cjs +30 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +57 -29
- package/dist/utils/translations/messages.exception.en.json +4 -1
- package/dist/utils/translations/messages.exception.fr.json +4 -1
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<p align="center"><a href="https://opticorejs.com" target="_blank">
|
|
2
|
+
<img src="" alt="OptiCoreJs Logo">
|
|
3
|
+
</a></p>
|
|
4
|
+
|
|
5
|
+
[Opticore-webApp]() is a **OptiCoreJs package** for web applications. Opticore-webApp is used by OptiCoreJs template starter.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
```
|
|
9
|
+
npm install opticore-webapp
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
```
|
|
14
|
+
const app: WebServer = new WebServer(appXpr, logger, localLanguage, envPath, corsOptions);
|
|
15
|
+
```
|
|
16
|
+
#### NB :
|
|
17
|
+
* `appXpr`: An express() calling.
|
|
18
|
+
* `logger`: A logger file configuration. You must use it like this (const logger: LoggerCore = new LoggerCore(loggerConfig(envPath) as LoggerConfigInterface);) envPath is an environment from an .env file located in a specific folder
|
|
19
|
+
* `localLanguage` : A local language define in .env file
|
|
20
|
+
* `envPath` : A .env path
|
|
21
|
+
* `corsOptions` : A cors options defined
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
const server = app.onStartServer(routers, mySQL.databaseConnexionChecker as () => void);
|
|
25
|
+
|
|
26
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
UStopServer: () => UStopServer,
|
|
33
34
|
WebServer: () => WebServerCore,
|
|
34
35
|
envPath: () => envPath
|
|
35
36
|
});
|
|
@@ -529,7 +530,6 @@ var WebServerCore = class {
|
|
|
529
530
|
}
|
|
530
531
|
);
|
|
531
532
|
}
|
|
532
|
-
//, kernelModule: KernelModuleType
|
|
533
533
|
onListeningOnServerEvent(serverWeb) {
|
|
534
534
|
serverWeb.on(import_opticore_catch_exception_error4.CEventNameError.error, (err) => {
|
|
535
535
|
this.serverListenEvent.onEventError(err);
|
|
@@ -583,8 +583,37 @@ var WebServerCore = class {
|
|
|
583
583
|
// src/utils/envPath.utils.ts
|
|
584
584
|
var import_process = __toESM(require("process"), 1);
|
|
585
585
|
var envPath = import_process.default.cwd() + "/config/env/.env";
|
|
586
|
+
|
|
587
|
+
// src/utils/stopServer.utils.ts
|
|
588
|
+
var import_dotenv = __toESM(require("dotenv"), 1);
|
|
589
|
+
var import_child_process = require("child_process");
|
|
590
|
+
var import_opticore_translator5 = require("opticore-translator");
|
|
591
|
+
|
|
592
|
+
// src/application/service/logger.service.ts
|
|
593
|
+
var import_opticore_logger2 = require("opticore-logger");
|
|
594
|
+
var SLogger = () => {
|
|
595
|
+
return new import_opticore_logger2.LoggerCore();
|
|
596
|
+
};
|
|
597
|
+
|
|
598
|
+
// src/utils/stopServer.utils.ts
|
|
599
|
+
var UStopServer = () => {
|
|
600
|
+
import_dotenv.default.config();
|
|
601
|
+
const port = process.env.PORT;
|
|
602
|
+
try {
|
|
603
|
+
const pid = (0, import_child_process.execSync)(`lsof -i :${port} -t`, { encoding: "utf-8" }).trim();
|
|
604
|
+
if (pid) {
|
|
605
|
+
(0, import_child_process.execSync)(`kill ${pid}`);
|
|
606
|
+
SLogger().success("serverPortKill", import_opticore_translator5.TranslationLoader.t("serverPortKill", "en", { port }));
|
|
607
|
+
} else {
|
|
608
|
+
SLogger().warn("pidOnPortNotFound", import_opticore_translator5.TranslationLoader.t("pidOnPortNotFound", "en", { port }));
|
|
609
|
+
}
|
|
610
|
+
} catch (error) {
|
|
611
|
+
SLogger().error("noProcessRunningOnPort", import_opticore_translator5.TranslationLoader.t("noProcessRunningOnPort", "en", { port }));
|
|
612
|
+
}
|
|
613
|
+
};
|
|
586
614
|
// Annotate the CommonJS export names for ESM import in node:
|
|
587
615
|
0 && (module.exports = {
|
|
616
|
+
UStopServer,
|
|
588
617
|
WebServer,
|
|
589
618
|
envPath
|
|
590
619
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -38,8 +38,10 @@ declare class WebServerCore {
|
|
|
38
38
|
|
|
39
39
|
declare const envPath: string;
|
|
40
40
|
|
|
41
|
+
declare const UStopServer: () => void;
|
|
42
|
+
|
|
41
43
|
type KernelModuleType = [{
|
|
42
44
|
featureRoute: IRouteDefinition[];
|
|
43
45
|
}[], () => void];
|
|
44
46
|
|
|
45
|
-
export { type IRouteDefinition, type KernelModuleType, type TFeatureRoutes, WebServerCore as WebServer, envPath };
|
|
47
|
+
export { type IRouteDefinition, type KernelModuleType, type TFeatureRoutes, UStopServer, WebServerCore as WebServer, envPath };
|
package/dist/index.d.ts
CHANGED
|
@@ -38,8 +38,10 @@ declare class WebServerCore {
|
|
|
38
38
|
|
|
39
39
|
declare const envPath: string;
|
|
40
40
|
|
|
41
|
+
declare const UStopServer: () => void;
|
|
42
|
+
|
|
41
43
|
type KernelModuleType = [{
|
|
42
44
|
featureRoute: IRouteDefinition[];
|
|
43
45
|
}[], () => void];
|
|
44
46
|
|
|
45
|
-
export { type IRouteDefinition, type KernelModuleType, type TFeatureRoutes, WebServerCore as WebServer, envPath };
|
|
47
|
+
export { type IRouteDefinition, type KernelModuleType, type TFeatureRoutes, UStopServer, WebServerCore as WebServer, envPath };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/core/webServer.core.ts
|
|
2
2
|
import * as path2 from "path";
|
|
3
|
-
import
|
|
3
|
+
import process4 from "node:process";
|
|
4
4
|
import { createRequire } from "module";
|
|
5
5
|
import corsOrigin from "cors";
|
|
6
6
|
import {
|
|
@@ -17,7 +17,7 @@ import { getEnvironnementValue as getEnvironnementValue3 } from "opticore-env-ac
|
|
|
17
17
|
import { TranslationLoader as TranslationLoader4 } from "opticore-translator";
|
|
18
18
|
|
|
19
19
|
// src/core/handlers/eventProcess.handler.ts
|
|
20
|
-
import
|
|
20
|
+
import process2 from "node:process";
|
|
21
21
|
import EventEmitter from "node:events";
|
|
22
22
|
import { express } from "opticore-express";
|
|
23
23
|
import {
|
|
@@ -32,42 +32,42 @@ function eventProcessHandler(localeLanguage) {
|
|
|
32
32
|
errorEmitter.on(eventName.error, (error) => {
|
|
33
33
|
serverListenEvent.listenerError(error);
|
|
34
34
|
});
|
|
35
|
-
|
|
35
|
+
process2.on(event.beforeExit, (code) => {
|
|
36
36
|
setTimeout(() => {
|
|
37
37
|
serverListenEvent.processBeforeExit(code);
|
|
38
38
|
}, 100);
|
|
39
39
|
});
|
|
40
|
-
|
|
40
|
+
process2.on(event.disconnect, () => {
|
|
41
41
|
serverListenEvent.processDisconnected();
|
|
42
42
|
});
|
|
43
|
-
|
|
43
|
+
process2.on(event.exit, (code) => {
|
|
44
44
|
serverListenEvent.exited(code);
|
|
45
45
|
});
|
|
46
|
-
|
|
46
|
+
process2.on(event.rejectionHandled, (promise) => {
|
|
47
47
|
serverListenEvent.promiseRejectionHandled(promise);
|
|
48
48
|
});
|
|
49
|
-
|
|
49
|
+
process2.on(event.uncaughtException, (error) => {
|
|
50
50
|
serverListenEvent.uncaughtException(error);
|
|
51
51
|
});
|
|
52
|
-
|
|
52
|
+
process2.on(event.uncaughtExceptionMonitor, (error) => {
|
|
53
53
|
serverListenEvent.uncaughtExceptionMonitor(error);
|
|
54
54
|
});
|
|
55
|
-
|
|
55
|
+
process2.on(event.unhandledRejection, (reason, promise) => {
|
|
56
56
|
serverListenEvent.unhandledRejection(reason, promise);
|
|
57
57
|
});
|
|
58
|
-
|
|
58
|
+
process2.on(event.warning, (warning) => {
|
|
59
59
|
serverListenEvent.warning(warning);
|
|
60
60
|
});
|
|
61
|
-
|
|
61
|
+
process2.on(event.message, (message) => {
|
|
62
62
|
serverListenEvent.message(message);
|
|
63
63
|
});
|
|
64
|
-
|
|
64
|
+
process2.on(event.multipleResolves, (type, promise, reason) => {
|
|
65
65
|
serverListenEvent.multipleResolves(type, promise, reason);
|
|
66
66
|
});
|
|
67
|
-
|
|
67
|
+
process2.on(event.sigint, () => {
|
|
68
68
|
serverListenEvent.processInterrupted();
|
|
69
69
|
});
|
|
70
|
-
|
|
70
|
+
process2.on(event.sigterm, (signal) => {
|
|
71
71
|
serverListenEvent.sigtermSignalReceived(signal);
|
|
72
72
|
});
|
|
73
73
|
app.use((err, req, res, next) => {
|
|
@@ -76,7 +76,7 @@ function eventProcessHandler(localeLanguage) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/application/service/core.service.ts
|
|
79
|
-
import
|
|
79
|
+
import process3 from "node:process";
|
|
80
80
|
import chalk from "chalk";
|
|
81
81
|
import * as path from "path";
|
|
82
82
|
import * as fs from "fs";
|
|
@@ -185,7 +185,7 @@ var CoreService = class {
|
|
|
185
185
|
* Returns an Object containing a node version, openssl, and v0
|
|
186
186
|
*/
|
|
187
187
|
getVersions() {
|
|
188
|
-
const { node, openssl, v8 } =
|
|
188
|
+
const { node, openssl, v8 } = process3.versions;
|
|
189
189
|
const data = {
|
|
190
190
|
"node version": node,
|
|
191
191
|
"openssl": openssl,
|
|
@@ -205,14 +205,14 @@ var CoreService = class {
|
|
|
205
205
|
* and Memory usage system
|
|
206
206
|
*/
|
|
207
207
|
getUsageMemory() {
|
|
208
|
-
const memoryData =
|
|
208
|
+
const memoryData = process3.memoryUsage();
|
|
209
209
|
const data = {
|
|
210
210
|
[`${TranslationLoader2.t("totalMemoryAllocated", this.localLanguage)}}`]: this.formatMemoryUsage(memoryData.rss),
|
|
211
211
|
[`${TranslationLoader2.t("sizeAllocatedHeap", this.localLanguage)}`]: this.formatMemoryUsage(memoryData.heapTotal),
|
|
212
212
|
[`${TranslationLoader2.t("memoryUsedExecution", this.localLanguage)}`]: this.formatMemoryUsage(memoryData.heapUsed),
|
|
213
213
|
[`${TranslationLoader2.t("externalMemory", this.localLanguage)}`]: this.formatMemoryUsage(memoryData.external),
|
|
214
|
-
[`${TranslationLoader2.t("memoryUsageUser", this.localLanguage)}`]: this.formatMemoryUsage(
|
|
215
|
-
[`${TranslationLoader2.t("memoryUsageSystem", this.localLanguage)}`]: this.formatMemoryUsage(
|
|
214
|
+
[`${TranslationLoader2.t("memoryUsageUser", this.localLanguage)}`]: this.formatMemoryUsage(process3.cpuUsage().user),
|
|
215
|
+
[`${TranslationLoader2.t("memoryUsageSystem", this.localLanguage)}`]: this.formatMemoryUsage(process3.cpuUsage().system)
|
|
216
216
|
};
|
|
217
217
|
return {
|
|
218
218
|
"rss": data[`${TranslationLoader2.t("totalMemoryAllocated", this.localLanguage)}}`],
|
|
@@ -227,11 +227,11 @@ var CoreService = class {
|
|
|
227
227
|
* Return an Object containing a project path and running server time
|
|
228
228
|
*/
|
|
229
229
|
getProjectInfo() {
|
|
230
|
-
const startTime =
|
|
231
|
-
const endTime =
|
|
230
|
+
const startTime = process3.hrtime();
|
|
231
|
+
const endTime = process3.hrtime(startTime);
|
|
232
232
|
const executionTime = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
233
233
|
return {
|
|
234
|
-
"projectPath": path.join(
|
|
234
|
+
"projectPath": path.join(process3.cwd()),
|
|
235
235
|
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
236
236
|
};
|
|
237
237
|
}
|
|
@@ -241,7 +241,7 @@ var CoreService = class {
|
|
|
241
241
|
* @private
|
|
242
242
|
*/
|
|
243
243
|
getEnvFileLoading(filePath) {
|
|
244
|
-
const fullPath = path.resolve(
|
|
244
|
+
const fullPath = path.resolve(process3.cwd(), filePath);
|
|
245
245
|
if (fs.existsSync(fullPath)) {
|
|
246
246
|
const env = fs.readFileSync(fullPath, "utf-8");
|
|
247
247
|
const lines = env.split("\n");
|
|
@@ -249,7 +249,7 @@ var CoreService = class {
|
|
|
249
249
|
const match = line.match(/^([^#=]+)=([^#]+)$/);
|
|
250
250
|
if (match) {
|
|
251
251
|
const key = match[1].trim();
|
|
252
|
-
|
|
252
|
+
process3.env[key] = match[2].trim();
|
|
253
253
|
}
|
|
254
254
|
});
|
|
255
255
|
}
|
|
@@ -261,7 +261,7 @@ var CoreService = class {
|
|
|
261
261
|
*/
|
|
262
262
|
getServerRunningMode(development, production) {
|
|
263
263
|
this.getEnvFileLoading(".env");
|
|
264
|
-
const isDevelopment =
|
|
264
|
+
const isDevelopment = process3.env.NODE_ENV === "development";
|
|
265
265
|
if (isDevelopment) {
|
|
266
266
|
return `${TranslationLoader2.t("serverRunning", this.localLanguage)} ${colors3.bgBlue(`${colors3.bold(`${development}`)}`)} mode`;
|
|
267
267
|
} else {
|
|
@@ -483,7 +483,7 @@ var WebServerCore = class {
|
|
|
483
483
|
this.serverListenEvent.portUndefined();
|
|
484
484
|
} else {
|
|
485
485
|
dbConnexion();
|
|
486
|
-
this.expressApp.use(express2.static(path2.join(
|
|
486
|
+
this.expressApp.use(express2.static(path2.join(process4.cwd(), "public/template")));
|
|
487
487
|
this.registerRoutes(routers);
|
|
488
488
|
}
|
|
489
489
|
} catch (err) {
|
|
@@ -500,7 +500,6 @@ var WebServerCore = class {
|
|
|
500
500
|
}
|
|
501
501
|
);
|
|
502
502
|
}
|
|
503
|
-
//, kernelModule: KernelModuleType
|
|
504
503
|
onListeningOnServerEvent(serverWeb) {
|
|
505
504
|
serverWeb.on(eventName2.error, (err) => {
|
|
506
505
|
this.serverListenEvent.onEventError(err);
|
|
@@ -552,9 +551,38 @@ var WebServerCore = class {
|
|
|
552
551
|
};
|
|
553
552
|
|
|
554
553
|
// src/utils/envPath.utils.ts
|
|
555
|
-
import
|
|
556
|
-
var envPath =
|
|
554
|
+
import process5 from "process";
|
|
555
|
+
var envPath = process5.cwd() + "/config/env/.env";
|
|
556
|
+
|
|
557
|
+
// src/utils/stopServer.utils.ts
|
|
558
|
+
import dotenv from "dotenv";
|
|
559
|
+
import { execSync } from "child_process";
|
|
560
|
+
import { TranslationLoader as TranslationLoader5 } from "opticore-translator";
|
|
561
|
+
|
|
562
|
+
// src/application/service/logger.service.ts
|
|
563
|
+
import { LoggerCore as LoggerCore2 } from "opticore-logger";
|
|
564
|
+
var SLogger = () => {
|
|
565
|
+
return new LoggerCore2();
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
// src/utils/stopServer.utils.ts
|
|
569
|
+
var UStopServer = () => {
|
|
570
|
+
dotenv.config();
|
|
571
|
+
const port = process.env.PORT;
|
|
572
|
+
try {
|
|
573
|
+
const pid = execSync(`lsof -i :${port} -t`, { encoding: "utf-8" }).trim();
|
|
574
|
+
if (pid) {
|
|
575
|
+
execSync(`kill ${pid}`);
|
|
576
|
+
SLogger().success("serverPortKill", TranslationLoader5.t("serverPortKill", "en", { port }));
|
|
577
|
+
} else {
|
|
578
|
+
SLogger().warn("pidOnPortNotFound", TranslationLoader5.t("pidOnPortNotFound", "en", { port }));
|
|
579
|
+
}
|
|
580
|
+
} catch (error) {
|
|
581
|
+
SLogger().error("noProcessRunningOnPort", TranslationLoader5.t("noProcessRunningOnPort", "en", { port }));
|
|
582
|
+
}
|
|
583
|
+
};
|
|
557
584
|
export {
|
|
585
|
+
UStopServer,
|
|
558
586
|
WebServerCore as WebServer,
|
|
559
587
|
envPath
|
|
560
588
|
};
|
|
@@ -86,5 +86,8 @@
|
|
|
86
86
|
"errorHost": "The host can't be empty or blank. Please define a string host in .env",
|
|
87
87
|
"accessDeniedToDBCon": "Access denied for user {user}. Database credentials in .env file are User: {user} and Password: {password}. {user}''{password}'@'localhost'. Try to set user and password in .env file",
|
|
88
88
|
"unknownDB": "Database {database} is unknown. Please try to use Database CLI to create your database, or do it manually in your Database Management System",
|
|
89
|
-
"errorDBHost": "A database host
|
|
89
|
+
"errorDBHost": "A database host {host} does not allow connection. Please either set the host like this: {localhost} in your .env file",
|
|
90
|
+
"serverPortKill": "Server which started on port {port} has been stopped successfully.",
|
|
91
|
+
"pidOnPortNotFound": "No process found on port {port}.",
|
|
92
|
+
"noProcessRunningOnPort": "Error: No process running on port {port}"
|
|
90
93
|
}
|
|
@@ -86,5 +86,8 @@
|
|
|
86
86
|
"errorHost": "L'hôte ne peut être vide. Veuillez définir une chaîne d'hôte dans .env.",
|
|
87
87
|
"accessDeniedToDBCon": "Accès refusé pour l'utilisateur {user}. Les identifiants de la base de données dans le fichier .env sont : utilisateur : {user} et le mot de passe : {password}. {user}''{password}'@'localhost'. Essayez de définir l'utilisateur et le mot de passe dans le fichier .env",
|
|
88
88
|
"unknownDB": "La base de données {database} est inconnue. Veuillez utiliser l'interface de ligne de commande de la base de données pour la créer, ou le faire manuellement dans votre système de gestion de bases de données.",
|
|
89
|
-
"errorDBHost": "L'hôte de la base de données
|
|
89
|
+
"errorDBHost": "L'hôte de la base de données {host} n'autorise pas la connexion. Veuillez définir l'hôte comme suit : {localhost} dans votre fichier .env",
|
|
90
|
+
"serverPortKill": "Serveur qui a démarré sur le port {port} a été arrêté avec succès.",
|
|
91
|
+
"pidOnPortNotFound": "Aucun processus trouvé sur le port {port}.",
|
|
92
|
+
"noProcessRunningOnPort": "Erreur : Aucun processus en cours sur le port {port}."
|
|
90
93
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opticore-webapp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"description": "wep server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"chalk": "^5.4.1",
|
|
29
29
|
"cors": "^2.8.5",
|
|
30
30
|
"dotenv": "^16.4.7",
|
|
31
|
-
"gradient-string": "^
|
|
31
|
+
"gradient-string": "^3.0.0",
|
|
32
32
|
"opticore-catch-exception-error": "^1.0.18",
|
|
33
|
-
"opticore-env-access": "^1.0.
|
|
33
|
+
"opticore-env-access": "^1.0.6",
|
|
34
34
|
"opticore-express": "^1.0.3",
|
|
35
35
|
"opticore-http-response": "^1.0.3",
|
|
36
|
-
"opticore-logger": "^1.0.
|
|
36
|
+
"opticore-logger": "^1.0.14",
|
|
37
37
|
"opticore-request-call-event": "^1.0.1",
|
|
38
38
|
"opticore-router": "^1.0.11",
|
|
39
39
|
"opticore-translator": "^1.0.8",
|