opticore-webapp 1.0.66 → 1.0.67
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 +483 -305
- package/dist/index.d.cts +50 -67
- package/dist/index.d.ts +50 -67
- package/dist/index.js +496 -325
- package/dist/utils/translations/message.translation.en.json +32 -1
- package/dist/utils/translations/message.translation.fr.json +26 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -5,37 +5,110 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
5
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
// node_modules/tsup/assets/esm_shims.js
|
|
9
|
-
import { fileURLToPath } from "url";
|
|
10
|
-
import path from "path";
|
|
11
|
-
var getFilename = () => fileURLToPath(import.meta.url);
|
|
12
|
-
var getDirname = () => path.dirname(getFilename());
|
|
13
|
-
var __dirname = /* @__PURE__ */ getDirname();
|
|
14
|
-
|
|
15
8
|
// src/core/webServer.core.ts
|
|
16
|
-
import * as
|
|
17
|
-
import process4 from "
|
|
9
|
+
import * as path2 from "path";
|
|
10
|
+
import process4 from "process";
|
|
18
11
|
import corsOrigin from "cors";
|
|
19
12
|
import { CEventNameError as eventName2, ServerListenEventError as ServerListenEventError2 } from "opticore-catch-exception-error";
|
|
20
|
-
import { express
|
|
13
|
+
import { express } from "opticore-express";
|
|
21
14
|
import { getEnvironnementValue as getEnvironnementValue2 } from "opticore-env-access";
|
|
22
15
|
|
|
23
16
|
// src/core/handlers/eventProcess.handler.ts
|
|
24
|
-
import process from "
|
|
25
|
-
import EventEmitter from "
|
|
26
|
-
import { express } from "opticore-express";
|
|
17
|
+
import process from "process";
|
|
18
|
+
import EventEmitter from "events";
|
|
27
19
|
import {
|
|
28
20
|
ServerListenEventError,
|
|
29
21
|
CEventNameError as eventName,
|
|
30
22
|
CEvent as event
|
|
31
23
|
} from "opticore-catch-exception-error";
|
|
32
|
-
|
|
24
|
+
|
|
25
|
+
// src/utils/isTransformError.utils.ts
|
|
26
|
+
var isTransformErrorUtils = (error) => {
|
|
27
|
+
return error?.name === "TransformError" || error?.message?.includes("Transform failed") || error?.message?.includes("esbuild");
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// src/core/handlers/eventProcess.handler.ts
|
|
31
|
+
function eventProcessHandler(localeLanguage, expressApp) {
|
|
33
32
|
const errorEmitter = new EventEmitter();
|
|
34
|
-
const app = express();
|
|
35
33
|
const serverListenEvent = new ServerListenEventError(localeLanguage);
|
|
34
|
+
console.log("[Server] Setting up error event handlers...");
|
|
36
35
|
errorEmitter.on(eventName.error, (error) => {
|
|
36
|
+
console.error("[Server] EventEmitter error caught:", error.message);
|
|
37
|
+
if (isTransformErrorUtils(error)) {
|
|
38
|
+
handleTransformError(error);
|
|
39
|
+
}
|
|
37
40
|
serverListenEvent.listenerError(error);
|
|
38
41
|
});
|
|
42
|
+
function handleTransformError(error) {
|
|
43
|
+
console.error("[Server] ============================================");
|
|
44
|
+
console.error("[Server] TRANSFORM ERROR DETECTED");
|
|
45
|
+
console.error("[Server] ============================================");
|
|
46
|
+
console.error("[Server] Message:", error.message);
|
|
47
|
+
console.error("[Server] Stack:", error.stack);
|
|
48
|
+
if (error.errors && Array.isArray(error.errors)) {
|
|
49
|
+
error.errors.forEach((err, index) => {
|
|
50
|
+
console.error(`[Server] Error ${index + 1}:`, err.text);
|
|
51
|
+
if (err.location) {
|
|
52
|
+
console.error(`[Server] File: ${err.location.file}`);
|
|
53
|
+
console.error(`[Server] Line: ${err.location.line}, Column: ${err.location.column}`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const fileMatch = error.message.match(/([^:]+\.ts):(\d+):(\d+):/);
|
|
58
|
+
if (fileMatch) {
|
|
59
|
+
console.error("[Server] Problem file:", fileMatch[1]);
|
|
60
|
+
console.error("[Server] Line:", fileMatch[2], "Column:", fileMatch[3]);
|
|
61
|
+
}
|
|
62
|
+
const errorDetailMatch = error.message.match(/ERROR: (.+)$/m);
|
|
63
|
+
if (errorDetailMatch) {
|
|
64
|
+
console.error("[Server] Error detail:", errorDetailMatch[1]);
|
|
65
|
+
}
|
|
66
|
+
console.error("[Server] ============================================");
|
|
67
|
+
if (process.send) {
|
|
68
|
+
process.send({
|
|
69
|
+
type: "TRANSFORM_ERROR",
|
|
70
|
+
error: error.message,
|
|
71
|
+
stack: error.stack,
|
|
72
|
+
errorName: error.name,
|
|
73
|
+
details: error.errors,
|
|
74
|
+
timestamp: Date.now()
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
process.on(event.uncaughtException, (error) => {
|
|
79
|
+
console.error("[Server] UNCAUGHT EXCEPTION:", error.message);
|
|
80
|
+
console.error("[Server] Stack:", error.stack);
|
|
81
|
+
if (isTransformErrorUtils(error)) {
|
|
82
|
+
errorEmitter.emit("transformError", error);
|
|
83
|
+
}
|
|
84
|
+
serverListenEvent.uncaughtException(error);
|
|
85
|
+
if (process.send) {
|
|
86
|
+
const messageType = isTransformErrorUtils(error) ? "TRANSFORM_ERROR" : "HOT_RELOAD_ERROR";
|
|
87
|
+
process.send({
|
|
88
|
+
type: messageType,
|
|
89
|
+
error: error.message,
|
|
90
|
+
stack: error.stack,
|
|
91
|
+
errorName: error.name,
|
|
92
|
+
timestamp: Date.now()
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
process.on(event.unhandledRejection, (reason, promise) => {
|
|
97
|
+
console.error("[Server] UNHANDLED REJECTION:", reason);
|
|
98
|
+
if (isTransformErrorUtils(reason)) {
|
|
99
|
+
errorEmitter.emit("transformError", reason);
|
|
100
|
+
}
|
|
101
|
+
serverListenEvent.unhandledRejection(reason, promise);
|
|
102
|
+
if (process.send) {
|
|
103
|
+
const messageType = isTransformErrorUtils(reason) ? "TRANSFORM_ERROR" : "HOT_RELOAD_ERROR";
|
|
104
|
+
process.send({
|
|
105
|
+
type: messageType,
|
|
106
|
+
error: reason?.message || String(reason),
|
|
107
|
+
errorName: reason?.name,
|
|
108
|
+
timestamp: Date.now()
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
39
112
|
process.on(event.beforeExit, (code) => {
|
|
40
113
|
setTimeout(() => {
|
|
41
114
|
serverListenEvent.processBeforeExit(code);
|
|
@@ -50,20 +123,20 @@ function eventProcessHandler(localeLanguage) {
|
|
|
50
123
|
process.on(event.rejectionHandled, (promise) => {
|
|
51
124
|
serverListenEvent.promiseRejectionHandled(promise);
|
|
52
125
|
});
|
|
53
|
-
process.on(event.uncaughtException, (error) => {
|
|
54
|
-
serverListenEvent.uncaughtException(error);
|
|
55
|
-
});
|
|
56
126
|
process.on(event.uncaughtExceptionMonitor, (error) => {
|
|
127
|
+
console.error("[Server] UNCAUGHT EXCEPTION MONITOR:", error.message);
|
|
128
|
+
if (isTransformErrorUtils(error)) {
|
|
129
|
+
errorEmitter.emit("transformError", error);
|
|
130
|
+
}
|
|
57
131
|
serverListenEvent.uncaughtExceptionMonitor(error);
|
|
58
132
|
});
|
|
59
|
-
process.on(event.unhandledRejection, (reason, promise) => {
|
|
60
|
-
serverListenEvent.unhandledRejection(reason, promise);
|
|
61
|
-
});
|
|
62
133
|
process.on(event.warning, (warning) => {
|
|
63
134
|
serverListenEvent.warning(warning);
|
|
64
135
|
});
|
|
65
136
|
process.on(event.message, (message) => {
|
|
66
|
-
|
|
137
|
+
if (message.type !== "HOT_RELOAD_REQUEST" && message.type !== "SERVER_READY") {
|
|
138
|
+
serverListenEvent.message(message);
|
|
139
|
+
}
|
|
67
140
|
});
|
|
68
141
|
process.on(event.multipleResolves, (type, promise, reason) => {
|
|
69
142
|
serverListenEvent.multipleResolves(type, promise, reason);
|
|
@@ -74,67 +147,26 @@ function eventProcessHandler(localeLanguage) {
|
|
|
74
147
|
process.on(event.sigterm, (signal) => {
|
|
75
148
|
serverListenEvent.sigtermSignalReceived(signal);
|
|
76
149
|
});
|
|
77
|
-
|
|
150
|
+
expressApp.use((err, req, res, next) => {
|
|
151
|
+
console.error("[Server] Express error middleware triggered:", err.message);
|
|
152
|
+
console.error("[Server] Request URL:", req.url);
|
|
153
|
+
console.error("[Server] Request method:", req.method);
|
|
154
|
+
errorEmitter.emit(eventName.error, err);
|
|
78
155
|
serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
79
156
|
});
|
|
157
|
+
console.log("[Server] Error event handlers configured successfully");
|
|
158
|
+
return errorEmitter;
|
|
80
159
|
}
|
|
81
160
|
|
|
82
161
|
// src/application/service/core.service.ts
|
|
83
|
-
import process3 from "
|
|
162
|
+
import process3 from "process";
|
|
84
163
|
import chalk from "chalk";
|
|
85
|
-
import * as
|
|
164
|
+
import * as path from "path";
|
|
86
165
|
import * as fs from "fs";
|
|
87
|
-
import colors3 from "ansi-colors";
|
|
88
|
-
import { HttpStatusCode as status } from "opticore-http-response";
|
|
89
|
-
import { TranslationLoader as TranslationLoader2 } from "opticore-translator";
|
|
90
|
-
import { getEnvironnementValue } from "opticore-env-access";
|
|
91
|
-
|
|
92
|
-
// src/core/helpers/modulesLoaded.utils.ts
|
|
93
|
-
import colors2 from "ansi-colors";
|
|
94
|
-
|
|
95
|
-
// src/core/helpers/logMessage.utils.ts
|
|
96
166
|
import colors from "ansi-colors";
|
|
97
|
-
|
|
98
|
-
// src/core/helpers/dateTimeFormatted.utils.ts
|
|
99
|
-
var dateTimeFormattedUtils = `${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @__PURE__ */ new Date()).getDate()}-${(/* @__PURE__ */ new Date()).getFullYear()} ${(/* @__PURE__ */ new Date()).getHours()}:${(/* @__PURE__ */ new Date()).getMinutes()}:${(/* @__PURE__ */ new Date()).getSeconds()}`;
|
|
100
|
-
|
|
101
|
-
// src/core/helpers/logMessage.utils.ts
|
|
102
|
-
var LogMessageUtils = class {
|
|
103
|
-
static success(title, action, contentAction) {
|
|
104
|
-
console.log(`${colors.green(`\u2714`)} ${colors.bgGreen(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ ${action} ] ${contentAction} - [ Status ] ${colors.bgGreen(`${colors.white(` 200 `)}`)}`);
|
|
105
|
-
}
|
|
106
|
-
static warning(title, action, contentAction) {
|
|
107
|
-
console.warn(`${colors.yellow(`\u26A0\uFE0F`)} ${colors.bgYellow(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgYellow(`${colors.white(` Warning `)}`)} ${contentAction}`);
|
|
108
|
-
}
|
|
109
|
-
static info(title, action, contentAction) {
|
|
110
|
-
console.info(`${colors.cyan(`\u24D8`)} ${colors.bgCyan(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgCyan(`${colors.white(` Info `)}`)} ${contentAction}`);
|
|
111
|
-
}
|
|
112
|
-
static error(title, errorType, stackTrace, messageContent, httpCodeValue) {
|
|
113
|
-
console.error(`${colors.red(`\u2718`)} ${colors.bgRed(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors.red(`${colors.bold(` ${errorType} `)}`)} ] | [ ${colors.bold(`stack trace`)} ] ${colors.red(`${stackTrace}`)} - ${colors.red(`${messageContent}`)} - [ ${colors.red(`${colors.bold(` HttpCode `)}`)} ] ${colors.red(`${colors.bold(` ${httpCodeValue} `)}`)} `);
|
|
114
|
-
}
|
|
115
|
-
static requestError(title, errorName, errorMessage, errorCode) {
|
|
116
|
-
console.error(`[ ${colors.red(`${title}`)} ] ${dateTimeFormattedUtils} | ${colors.bgRed(`${colors.white(` ERROR `)}`)} ${colors.red(`[ ${errorName} ]`)} ${colors.red(`${errorMessage}`)} - [ Status ] ${colors.bgRed(`${colors.white(` ${errorCode} `)}`)}`);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
// src/core/helpers/modulesLoaded.utils.ts
|
|
167
|
+
import { HttpStatusCode, HttpStatusCode as status } from "opticore-http-response";
|
|
121
168
|
import { TranslationLoader } from "opticore-translator";
|
|
122
|
-
|
|
123
|
-
LogMessageUtils.success(
|
|
124
|
-
`${TranslationLoader.t("kernel", localeLanguage)}`,
|
|
125
|
-
`${TranslationLoader.t("loadKernel", localeLanguage)}`,
|
|
126
|
-
`${TranslationLoader.t("moduleAppLoaded", localeLanguage)}`
|
|
127
|
-
);
|
|
128
|
-
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`)}`);
|
|
129
|
-
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)} `);
|
|
130
|
-
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`)}`) : "";
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// src/application/service/traceError.service.ts
|
|
134
|
-
import { StackTraceError } from "opticore-catch-exception-error";
|
|
135
|
-
var STraceError = (props, name, httpCode, isOperational) => {
|
|
136
|
-
return new StackTraceError(props, name, httpCode, isOperational);
|
|
137
|
-
};
|
|
169
|
+
import { getEnvironnementValue } from "opticore-env-access";
|
|
138
170
|
|
|
139
171
|
// src/utils/envPath.utils.ts
|
|
140
172
|
import process2 from "process";
|
|
@@ -174,6 +206,21 @@ var dependenciesContainerProvider = (localLang) => {
|
|
|
174
206
|
return new SContainer(localLang, dependencies);
|
|
175
207
|
};
|
|
176
208
|
|
|
209
|
+
// src/application/service/core.service.ts
|
|
210
|
+
import { LoggerCore as LoggerCore2 } from "opticore-logger";
|
|
211
|
+
|
|
212
|
+
// src/application/service/logger.service.ts
|
|
213
|
+
var SLogger = (localLang) => {
|
|
214
|
+
return {
|
|
215
|
+
get serverLog() {
|
|
216
|
+
return dependenciesContainerProvider(localLang).resolve("OpticoreLogger");
|
|
217
|
+
},
|
|
218
|
+
get logger() {
|
|
219
|
+
return dependenciesContainerProvider(localLang).resolve("LoggerCore");
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
|
|
177
224
|
// src/application/service/core.service.ts
|
|
178
225
|
var CoreService = class {
|
|
179
226
|
localLanguage;
|
|
@@ -183,6 +230,7 @@ var CoreService = class {
|
|
|
183
230
|
constructor(localLang, environmentPath) {
|
|
184
231
|
this.environmentPath = environmentPath;
|
|
185
232
|
this.localLanguage = localLang;
|
|
233
|
+
loaderTranslationFile(this.localLanguage);
|
|
186
234
|
this.serverLog = dependenciesContainerProvider(localLang).resolve("OpticoreLogger");
|
|
187
235
|
this.logger = dependenciesContainerProvider(localLang).resolve("LoggerCore");
|
|
188
236
|
}
|
|
@@ -223,20 +271,20 @@ var CoreService = class {
|
|
|
223
271
|
loaderTranslationFile(this.localLanguage);
|
|
224
272
|
const memoryData = process3.memoryUsage();
|
|
225
273
|
const data = {
|
|
226
|
-
[
|
|
227
|
-
[
|
|
228
|
-
[
|
|
229
|
-
[
|
|
230
|
-
[
|
|
231
|
-
[
|
|
274
|
+
[TranslationLoader.t("totalMemoryAllocated", this.localLanguage)]: this.formatMemoryUsage(memoryData.rss),
|
|
275
|
+
[TranslationLoader.t("sizeAllocatedHeap", this.localLanguage)]: this.formatMemoryUsage(memoryData.heapTotal),
|
|
276
|
+
[TranslationLoader.t("memoryUsedExecution", this.localLanguage)]: this.formatMemoryUsage(memoryData.heapUsed),
|
|
277
|
+
[TranslationLoader.t("externalMemory", this.localLanguage)]: this.formatMemoryUsage(memoryData.external),
|
|
278
|
+
[TranslationLoader.t("memoryUsageUser", this.localLanguage)]: this.formatMemoryUsage(process3.cpuUsage().user),
|
|
279
|
+
[TranslationLoader.t("memoryUsageSystem", this.localLanguage)]: this.formatMemoryUsage(process3.cpuUsage().system)
|
|
232
280
|
};
|
|
233
281
|
return {
|
|
234
|
-
"rss": data[
|
|
235
|
-
"heapTotal": data[
|
|
236
|
-
"heapUsed": data[
|
|
237
|
-
"external": data[
|
|
238
|
-
"user": data[
|
|
239
|
-
"system": data[
|
|
282
|
+
"rss": data[TranslationLoader.t("totalMemoryAllocated", this.localLanguage)],
|
|
283
|
+
"heapTotal": data[TranslationLoader.t("sizeAllocatedHeap", this.localLanguage)],
|
|
284
|
+
"heapUsed": data[TranslationLoader.t("memoryUsedExecution", this.localLanguage)],
|
|
285
|
+
"external": data[TranslationLoader.t("externalMemory", this.localLanguage)],
|
|
286
|
+
"user": data[TranslationLoader.t("memoryUsageUser", this.localLanguage)],
|
|
287
|
+
"system": data[TranslationLoader.t("memoryUsageSystem", this.localLanguage)],
|
|
240
288
|
"pid": process3.pid
|
|
241
289
|
};
|
|
242
290
|
}
|
|
@@ -248,7 +296,7 @@ var CoreService = class {
|
|
|
248
296
|
const endTime = process3.hrtime(startTime);
|
|
249
297
|
const executionTime = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
250
298
|
return {
|
|
251
|
-
"projectPath":
|
|
299
|
+
"projectPath": path.join(process3.cwd()),
|
|
252
300
|
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
253
301
|
};
|
|
254
302
|
}
|
|
@@ -261,7 +309,7 @@ var CoreService = class {
|
|
|
261
309
|
*/
|
|
262
310
|
getEnvFileLoading(filePath) {
|
|
263
311
|
try {
|
|
264
|
-
const fullPath =
|
|
312
|
+
const fullPath = path.resolve(process3.cwd(), filePath);
|
|
265
313
|
if (fs.existsSync(fullPath)) {
|
|
266
314
|
const env = fs.readFileSync(fullPath, "utf-8");
|
|
267
315
|
const lines = env.split("\n");
|
|
@@ -276,7 +324,7 @@ var CoreService = class {
|
|
|
276
324
|
} catch (err) {
|
|
277
325
|
this.logger.error({
|
|
278
326
|
message: err.message,
|
|
279
|
-
title:
|
|
327
|
+
title: TranslationLoader.t("EnvFileLoading", this.localLanguage),
|
|
280
328
|
errorType: err.code,
|
|
281
329
|
stackTrace: err.stack,
|
|
282
330
|
httpCodeValue: status.INTERNAL_SERVER_ERROR
|
|
@@ -294,19 +342,19 @@ var CoreService = class {
|
|
|
294
342
|
try {
|
|
295
343
|
loaderTranslationFile(this.localLanguage);
|
|
296
344
|
this.getEnvFileLoading(".env");
|
|
297
|
-
const env = getEnvironnementValue(
|
|
345
|
+
const env = getEnvironnementValue(path.join(envPath));
|
|
298
346
|
const isDevelopment = env.devEnv === development && env.prodEnv === "";
|
|
299
347
|
if (isDevelopment) {
|
|
300
|
-
return `${
|
|
348
|
+
return `${TranslationLoader.t("serverRunning", this.localLanguage)} ${colors.bgBlue(`${colors.bold(`${development}`)}`)} mode`;
|
|
301
349
|
} else if (!isDevelopment) {
|
|
302
|
-
return `${
|
|
350
|
+
return `${TranslationLoader.t("serverRunning", this.localLanguage)} ${colors.bgBlue(`${colors.bold(`${production}`)}`)} mode`;
|
|
303
351
|
} else {
|
|
304
|
-
return `${
|
|
352
|
+
return `${TranslationLoader.t("serverRunning", this.localLanguage)} ${colors.bgBlue(`${colors.bold(`${development}`)}`)} mode`;
|
|
305
353
|
}
|
|
306
354
|
} catch (err) {
|
|
307
355
|
this.logger.error({
|
|
308
356
|
message: err.message,
|
|
309
|
-
title:
|
|
357
|
+
title: TranslationLoader.t("serverRunning mode", this.localLanguage),
|
|
310
358
|
errorType: err.code,
|
|
311
359
|
stackTrace: err.stack,
|
|
312
360
|
httpCodeValue: status.INTERNAL_SERVER_ERROR
|
|
@@ -317,20 +365,17 @@ var CoreService = class {
|
|
|
317
365
|
try {
|
|
318
366
|
loaderTranslationFile(this.localLanguage);
|
|
319
367
|
const getEnvironment = getEnvironnementValue(this.environmentPath);
|
|
320
|
-
const msg5 = getEnvironment.protocolTransfert === "" ?
|
|
368
|
+
const msg5 = getEnvironment.protocolTransfert === "" ? colors.underline(`http://${host}:${port}`) : colors.underline(`${getEnvironment.protocolTransfert}://${host}:${port}`);
|
|
321
369
|
const messages = [
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
this.getServerRunningMode(
|
|
326
|
-
TranslationLoader2.t("runningModeDev", this.localLanguage),
|
|
327
|
-
TranslationLoader2.t("runningModeProd", this.localLanguage)
|
|
328
|
-
)
|
|
370
|
+
TranslationLoader.t("webServerListening", this.localLanguage),
|
|
371
|
+
TranslationLoader.t("webServerUsingNodeVersion", this.localLanguage, { nodeVersion: this.getVersions().nodeVersion }),
|
|
372
|
+
TranslationLoader.t("startTime", this.localLanguage, { startTime: this.getProjectInfo().startingTime }),
|
|
373
|
+
this.getServerRunningMode(TranslationLoader.t("runningModeDev", this.localLanguage), TranslationLoader.t("runningModeProd", this.localLanguage))
|
|
329
374
|
];
|
|
330
375
|
const maxLength = Math.max(...messages.map((m) => {
|
|
331
376
|
return m.replace(/\u001b\[[0-9]{1,2}m/g, "").length;
|
|
332
377
|
})) + 4;
|
|
333
|
-
console.log(chalk.blackBright(`${
|
|
378
|
+
console.log(chalk.blackBright(`${TranslationLoader.t("tailingServerLog", this.localLanguage)} (${path.join(path.basename(process3.cwd()), "logs", "app.log")})`));
|
|
334
379
|
const border = chalk.bgGreen.white(" ".repeat(maxLength));
|
|
335
380
|
console.log(border);
|
|
336
381
|
messages.forEach((msg) => {
|
|
@@ -340,67 +385,39 @@ var CoreService = class {
|
|
|
340
385
|
});
|
|
341
386
|
console.log(border);
|
|
342
387
|
console.log("\n");
|
|
343
|
-
|
|
388
|
+
const logCore = new LoggerCore2();
|
|
389
|
+
logCore.success({
|
|
390
|
+
title: TranslationLoader.t("serverRunningTitle", this.localLanguage),
|
|
391
|
+
message: TranslationLoader.t("serverRunningAt", this.localLanguage, { server: msg5 })
|
|
392
|
+
});
|
|
393
|
+
SLogger(this.localLanguage).serverLog.serverLog({
|
|
344
394
|
timestamp: (/* @__PURE__ */ new Date()).toString(),
|
|
345
395
|
level: "SERVER",
|
|
346
|
-
title:
|
|
347
|
-
typeName:
|
|
348
|
-
message:
|
|
396
|
+
title: TranslationLoader.t("serverRunningTitle", this.localLanguage),
|
|
397
|
+
typeName: TranslationLoader.t("opticoreServerTypeName", this.localLanguage),
|
|
398
|
+
message: TranslationLoader.t("serverRunningAt", this.localLanguage, { server: msg5 })
|
|
349
399
|
});
|
|
350
400
|
} catch (err) {
|
|
351
|
-
this.logger.error({
|
|
401
|
+
SLogger(this.localLanguage).logger.error({
|
|
352
402
|
message: err.message,
|
|
353
|
-
title:
|
|
403
|
+
title: TranslationLoader.t("server", this.localLanguage),
|
|
354
404
|
errorType: err.code,
|
|
355
405
|
stackTrace: err.stack,
|
|
356
|
-
httpCodeValue:
|
|
406
|
+
httpCodeValue: HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
357
407
|
});
|
|
358
408
|
}
|
|
359
409
|
}
|
|
360
|
-
coreListenerEventLoaderModuleService(kernelModule) {
|
|
361
|
-
loaderTranslationFile(this.localLanguage);
|
|
362
|
-
let router = [];
|
|
363
|
-
let dbCon;
|
|
364
|
-
kernelModule.forEach((module) => {
|
|
365
|
-
if (Array.isArray(module)) {
|
|
366
|
-
router = module;
|
|
367
|
-
} else if (typeof module === "function") {
|
|
368
|
-
dbCon = module;
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
if (router && dbCon) {
|
|
372
|
-
modulesLoadedUtils(router, dbCon, this.localLanguage);
|
|
373
|
-
(() => {
|
|
374
|
-
dbCon();
|
|
375
|
-
})();
|
|
376
|
-
} else {
|
|
377
|
-
const stackTrace = STraceError(
|
|
378
|
-
TranslationLoader2.t("loadedModulesError", this.localLanguage),
|
|
379
|
-
TranslationLoader2.t("loadedModules", this.localLanguage),
|
|
380
|
-
status.NOT_ACCEPTABLE,
|
|
381
|
-
true
|
|
382
|
-
);
|
|
383
|
-
throw new Error(stackTrace.message);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
410
|
};
|
|
387
411
|
|
|
412
|
+
// src/core/helpers/dateTimeFormatted.utils.ts
|
|
413
|
+
var dateTimeFormattedUtils = `${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @__PURE__ */ new Date()).getDate()}-${(/* @__PURE__ */ new Date()).getFullYear()} ${(/* @__PURE__ */ new Date()).getHours()}:${(/* @__PURE__ */ new Date()).getMinutes()}:${(/* @__PURE__ */ new Date()).getSeconds()}`;
|
|
414
|
+
|
|
388
415
|
// src/application/service/serverStartError.service.ts
|
|
389
416
|
import {
|
|
390
417
|
CCodeError,
|
|
391
418
|
CErrorName
|
|
392
419
|
} from "opticore-catch-exception-error";
|
|
393
|
-
|
|
394
|
-
// src/application/service/logger.service.ts
|
|
395
|
-
var SLogger = (localLang) => {
|
|
396
|
-
return {
|
|
397
|
-
serverLog: dependenciesContainerProvider(localLang).resolve("OpticoreLogger"),
|
|
398
|
-
logger: dependenciesContainerProvider(localLang).resolve("LoggerCore")
|
|
399
|
-
};
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
// src/application/service/serverStartError.service.ts
|
|
403
|
-
import { HttpStatusCode } from "opticore-http-response";
|
|
420
|
+
import { HttpStatusCode as HttpStatusCode2 } from "opticore-http-response";
|
|
404
421
|
var SServerStartError = (err, environmentPath) => {
|
|
405
422
|
if (err.name) {
|
|
406
423
|
for (const [key, code] of Object.entries(CErrorName)) {
|
|
@@ -410,7 +427,7 @@ var SServerStartError = (err, environmentPath) => {
|
|
|
410
427
|
title: code,
|
|
411
428
|
errorType: code,
|
|
412
429
|
stackTrace: err.stack,
|
|
413
|
-
httpCodeValue:
|
|
430
|
+
httpCodeValue: HttpStatusCode2.INTERNAL_SERVER_ERROR
|
|
414
431
|
});
|
|
415
432
|
break;
|
|
416
433
|
}
|
|
@@ -423,7 +440,7 @@ var SServerStartError = (err, environmentPath) => {
|
|
|
423
440
|
title: code,
|
|
424
441
|
errorType: key,
|
|
425
442
|
stackTrace: err.stack,
|
|
426
|
-
httpCodeValue:
|
|
443
|
+
httpCodeValue: HttpStatusCode2.INTERNAL_SERVER_ERROR
|
|
427
444
|
});
|
|
428
445
|
break;
|
|
429
446
|
}
|
|
@@ -434,117 +451,147 @@ var SServerStartError = (err, environmentPath) => {
|
|
|
434
451
|
// src/core/webServer.core.ts
|
|
435
452
|
import { requestCallsEvent } from "opticore-request-call-event";
|
|
436
453
|
import { SContainer as SContainer2 } from "opticore-dependency-inject";
|
|
437
|
-
import { HttpStatusCode as
|
|
438
|
-
import { TranslationLoader as
|
|
454
|
+
import { HttpStatusCode as HttpStatusCode3 } from "opticore-http-response";
|
|
455
|
+
import { TranslationLoader as TranslationLoader2 } from "opticore-translator";
|
|
439
456
|
var WebServerCore = class {
|
|
440
457
|
serverUtility;
|
|
441
|
-
expressApp =
|
|
458
|
+
expressApp = express();
|
|
442
459
|
localLanguage;
|
|
443
460
|
loggerConfig;
|
|
444
461
|
routerExpressApp;
|
|
445
462
|
getEnvironment;
|
|
446
463
|
environmentPath;
|
|
447
464
|
serverListenEvent;
|
|
448
|
-
isHotReloading = false;
|
|
449
465
|
currentRoutes = [];
|
|
450
466
|
currentDependencies = [];
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
this.
|
|
462
|
-
this.
|
|
463
|
-
this.
|
|
464
|
-
this.
|
|
467
|
+
server = void 0;
|
|
468
|
+
errorEmitter;
|
|
469
|
+
// ✅✅✅ ÉTAT DU SERVEUR
|
|
470
|
+
serverState = "READY";
|
|
471
|
+
lastError = null;
|
|
472
|
+
// Statistiques
|
|
473
|
+
hotReloadAttempts = 0;
|
|
474
|
+
hotReloadSuccesses = 0;
|
|
475
|
+
hotReloadFailures = 0;
|
|
476
|
+
constructor(paramsConstructor) {
|
|
477
|
+
this.getEnvironment = getEnvironnementValue2(paramsConstructor.environmentPath);
|
|
478
|
+
this.routerExpressApp = paramsConstructor.app;
|
|
479
|
+
this.loggerConfig = paramsConstructor.loggerConfig;
|
|
480
|
+
this.localLanguage = paramsConstructor.localLanguage;
|
|
481
|
+
this.environmentPath = paramsConstructor.environmentPath;
|
|
482
|
+
this.expressApp.use(express.json());
|
|
483
|
+
this.expressApp.use(express.raw());
|
|
484
|
+
this.expressApp.use(express.text());
|
|
485
|
+
this.expressApp.use(express.urlencoded({ extended: true }));
|
|
486
|
+
this.expressApp.use(corsOrigin(paramsConstructor.corsOriginOptions));
|
|
487
|
+
this.serverListenEvent = new ServerListenEventError2(paramsConstructor.localLanguage);
|
|
488
|
+
this.serverUtility = new CoreService(paramsConstructor.localLanguage, paramsConstructor.environmentPath);
|
|
465
489
|
this.setupSignalHandlers();
|
|
490
|
+
this.setupIPCHandlers();
|
|
466
491
|
}
|
|
467
|
-
/**
|
|
468
|
-
*
|
|
469
|
-
* @param dependencies
|
|
470
|
-
*/
|
|
471
|
-
registerDependencies(dependencies2) {
|
|
472
|
-
try {
|
|
473
|
-
dependenciesContainerProvider(this.localLanguage).getServices();
|
|
474
|
-
} catch (err) {
|
|
475
|
-
SLogger(this.localLanguage).logger.error({
|
|
476
|
-
message: err.message,
|
|
477
|
-
title: TranslationLoader3.t("registerDependencies", this.localLanguage),
|
|
478
|
-
errorType: err.code,
|
|
479
|
-
stackTrace: err.stack,
|
|
480
|
-
httpCodeValue: HttpStatusCode2.INTERNAL_SERVER_ERROR
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
*
|
|
486
|
-
* @param routers
|
|
487
|
-
* @param databaseCallback
|
|
488
|
-
* @param dependenciesProvider
|
|
489
|
-
*/
|
|
490
492
|
onStartServer(routers, databaseCallback, dependenciesProvider) {
|
|
491
493
|
loaderTranslationFile(this.localLanguage);
|
|
492
494
|
this.currentRoutes = routers;
|
|
493
495
|
this.currentDependencies = dependenciesProvider || [];
|
|
494
496
|
if (this.getEnvironment.appPort === "" && Number(this.getEnvironment.appPort) === 0) {
|
|
495
497
|
this.serverListenEvent.hostPortUndefined(Number(this.getEnvironment.appPort));
|
|
496
|
-
|
|
498
|
+
return void 0;
|
|
499
|
+
}
|
|
500
|
+
if (this.getEnvironment.appHost === "") {
|
|
497
501
|
this.serverListenEvent.hostUndefined(this.getEnvironment.appHost);
|
|
498
|
-
|
|
502
|
+
return void 0;
|
|
503
|
+
}
|
|
504
|
+
if (Number(this.getEnvironment.appPort) === 0) {
|
|
499
505
|
this.serverListenEvent.portUndefined();
|
|
500
|
-
|
|
506
|
+
return void 0;
|
|
507
|
+
}
|
|
508
|
+
if (this.localLanguage === "") {
|
|
501
509
|
SLogger(this.localLanguage).logger.error({
|
|
502
|
-
message:
|
|
503
|
-
title:
|
|
504
|
-
errorType:
|
|
510
|
+
message: TranslationLoader2.t("noDefaultLocalLang", this.localLanguage),
|
|
511
|
+
title: TranslationLoader2.t("noLocalLang", this.localLanguage),
|
|
512
|
+
errorType: TranslationLoader2.t("localLangMissing", this.localLanguage),
|
|
505
513
|
stackTrace: void 0,
|
|
506
|
-
httpCodeValue:
|
|
514
|
+
httpCodeValue: HttpStatusCode3.NOT_FOUND
|
|
507
515
|
});
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
516
|
+
return void 0;
|
|
517
|
+
}
|
|
518
|
+
this.server = this.expressApp.listen(
|
|
519
|
+
Number(this.getEnvironment.appPort),
|
|
520
|
+
this.getEnvironment.appHost,
|
|
521
|
+
() => {
|
|
522
|
+
try {
|
|
523
|
+
SLogger(this.localLanguage).logger.info({
|
|
524
|
+
message: TranslationLoader2.t("HOT_RELOAD_READY", this.localLanguage),
|
|
525
|
+
title: TranslationLoader2.t("HOT_RELOAD", this.localLanguage)
|
|
526
|
+
});
|
|
527
|
+
if (databaseCallback) {
|
|
514
528
|
databaseCallback(this.getEnvironment);
|
|
515
|
-
new SContainer2(this.localLanguage, this.currentDependencies);
|
|
516
|
-
this.expressApp.use(express2.static(path3.join(process4.cwd(), "public/template")));
|
|
517
|
-
this.registerRoutes(this.currentRoutes);
|
|
518
|
-
} catch (err) {
|
|
519
|
-
SServerStartError(err, this.environmentPath);
|
|
520
529
|
}
|
|
530
|
+
new SContainer2(this.localLanguage, this.currentDependencies);
|
|
531
|
+
this.expressApp.use(express.static(path2.join(process4.cwd(), "public/template")));
|
|
532
|
+
this.registerRoutes(this.currentRoutes);
|
|
533
|
+
this.setupErrorHandling();
|
|
534
|
+
this.setupServerEvents();
|
|
535
|
+
this.serverState = "READY";
|
|
536
|
+
this.infoWebApp();
|
|
537
|
+
this.notifyServerReady();
|
|
538
|
+
} catch (err) {
|
|
539
|
+
SLogger(this.localLanguage).logger.error({
|
|
540
|
+
title: TranslationLoader2.t("STARTUP_ERROR", this.localLanguage),
|
|
541
|
+
message: err.message,
|
|
542
|
+
errorType: err.code,
|
|
543
|
+
stackTrace: err.stackTrace,
|
|
544
|
+
httpCodeValue: HttpStatusCode3.INTERNAL_SERVER_ERROR
|
|
545
|
+
});
|
|
546
|
+
SServerStartError(err, this.environmentPath);
|
|
521
547
|
}
|
|
522
|
-
|
|
523
|
-
|
|
548
|
+
}
|
|
549
|
+
);
|
|
550
|
+
return this.server;
|
|
524
551
|
}
|
|
525
552
|
/**
|
|
526
|
-
*
|
|
527
|
-
* @param serverWeb
|
|
553
|
+
* ✅✅✅ Configuration de la gestion d'erreurs
|
|
528
554
|
*/
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
555
|
+
setupErrorHandling() {
|
|
556
|
+
SLogger(this.localLanguage).logger.info({
|
|
557
|
+
title: TranslationLoader2.t("SETTING_UP", this.localLanguage),
|
|
558
|
+
message: TranslationLoader2.t("SETTING_UP_ERROR", this.localLanguage)
|
|
559
|
+
});
|
|
560
|
+
this.errorEmitter = eventProcessHandler(this.localLanguage, this.expressApp);
|
|
561
|
+
if (this.errorEmitter) {
|
|
562
|
+
this.errorEmitter.on("transformError", (error) => {
|
|
563
|
+
SLogger(this.localLanguage).logger.info({
|
|
564
|
+
title: TranslationLoader2.t("", this.localLanguage),
|
|
565
|
+
message: TranslationLoader2.t("", this.localLanguage)
|
|
566
|
+
});
|
|
567
|
+
this.lastError = error;
|
|
568
|
+
this.serverState = "BLOCKED";
|
|
569
|
+
this.notifyWatcherBlockedByError(error);
|
|
570
|
+
});
|
|
571
|
+
this.errorEmitter.on("error", (error) => {
|
|
572
|
+
SLogger(this.localLanguage).logger.info({
|
|
573
|
+
title: TranslationLoader2.t("ERROR_EMITTED", this.localLanguage),
|
|
574
|
+
message: `Error emitted: ${error.message}`
|
|
575
|
+
});
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
SLogger(this.localLanguage).logger.info({
|
|
579
|
+
title: TranslationLoader2.t("ERROR_HANDLING", this.localLanguage),
|
|
580
|
+
message: TranslationLoader2.t("ERROR_HANDLING_CONFIGURED", this.localLanguage)
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
setupServerEvents() {
|
|
584
|
+
if (!this.server) return;
|
|
585
|
+
this.server.on(eventName2.error, (err) => {
|
|
532
586
|
this.serverListenEvent.onEventError(err);
|
|
533
|
-
})
|
|
587
|
+
});
|
|
588
|
+
this.server.on(eventName2.close, () => {
|
|
534
589
|
this.serverListenEvent.serverClosing();
|
|
535
|
-
})
|
|
590
|
+
});
|
|
591
|
+
this.server.on(eventName2.drop, () => {
|
|
536
592
|
this.serverListenEvent.dropNewConnection();
|
|
537
|
-
}).on(eventName2.listening, () => {
|
|
538
|
-
this.infoWebApp();
|
|
539
593
|
});
|
|
540
|
-
|
|
541
|
-
/**
|
|
542
|
-
*
|
|
543
|
-
* @param serverWeb
|
|
544
|
-
*/
|
|
545
|
-
onRequestOnServerEvent(serverWeb) {
|
|
546
|
-
loaderTranslationFile(this.localLanguage);
|
|
547
|
-
serverWeb.on(eventName2.request, (req, res) => {
|
|
594
|
+
this.server.on(eventName2.request, (req, res) => {
|
|
548
595
|
requestCallsEvent(
|
|
549
596
|
req,
|
|
550
597
|
res,
|
|
@@ -556,145 +603,269 @@ var WebServerCore = class {
|
|
|
556
603
|
);
|
|
557
604
|
});
|
|
558
605
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
*
|
|
573
|
-
* @param localLanguage
|
|
574
|
-
* @private
|
|
575
|
-
*/
|
|
576
|
-
stackTraceErrorHandling(localLanguage) {
|
|
577
|
-
eventProcessHandler(localLanguage);
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
*
|
|
581
|
-
* @private
|
|
582
|
-
*/
|
|
583
|
-
infoWebApp() {
|
|
584
|
-
this.serverUtility.infoServer(
|
|
585
|
-
this.getEnvironment.appHost,
|
|
586
|
-
Number(this.getEnvironment.appPort)
|
|
587
|
-
);
|
|
606
|
+
notifyServerReady() {
|
|
607
|
+
setTimeout(() => {
|
|
608
|
+
if (process4.send) {
|
|
609
|
+
process4.send({
|
|
610
|
+
type: "SERVER_READY",
|
|
611
|
+
timestamp: Date.now(),
|
|
612
|
+
port: Number(this.getEnvironment.appPort),
|
|
613
|
+
host: this.getEnvironment.appHost,
|
|
614
|
+
message: "Server ready for hot reload"
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
}, 100);
|
|
588
618
|
}
|
|
589
619
|
setupSignalHandlers() {
|
|
590
620
|
process4.on("SIGHUP", async () => {
|
|
591
|
-
if (
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
this.
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
621
|
+
if (this.serverState === "READY") {
|
|
622
|
+
SLogger(this.localLanguage).logger.info({
|
|
623
|
+
title: TranslationLoader2.t("SIGHUP", this.localLanguage),
|
|
624
|
+
message: TranslationLoader2.t("RECEIVED_SIGHUP", this.localLanguage)
|
|
625
|
+
});
|
|
626
|
+
await this.performTrueHotReload();
|
|
627
|
+
}
|
|
628
|
+
});
|
|
629
|
+
process4.on("SIGTERM", () => {
|
|
630
|
+
SLogger(this.localLanguage).logger.info({
|
|
631
|
+
title: TranslationLoader2.t("SIGHUP", this.localLanguage),
|
|
632
|
+
message: TranslationLoader2.t("RECEIVED_SIGHUP", this.localLanguage)
|
|
633
|
+
});
|
|
634
|
+
this.shutdown();
|
|
635
|
+
});
|
|
636
|
+
process4.on("SIGINT", () => {
|
|
637
|
+
SLogger(this.localLanguage).logger.info({
|
|
638
|
+
title: TranslationLoader2.t("SIGINT", this.localLanguage),
|
|
639
|
+
message: TranslationLoader2.t("RECEIVED_SIGINT", this.localLanguage)
|
|
640
|
+
});
|
|
641
|
+
this.shutdown();
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
setupIPCHandlers() {
|
|
645
|
+
if (!process4.send) {
|
|
646
|
+
SLogger(this.localLanguage).logger.info({
|
|
647
|
+
title: TranslationLoader2.t("IPC", this.localLanguage),
|
|
648
|
+
message: TranslationLoader2.t("IPC_NOT_AVAILABLE", this.localLanguage)
|
|
649
|
+
});
|
|
650
|
+
return;
|
|
651
|
+
}
|
|
652
|
+
SLogger(this.localLanguage).logger.info({
|
|
653
|
+
title: TranslationLoader2.t("IPC_READY", this.localLanguage),
|
|
654
|
+
message: TranslationLoader2.t("IPC_READY_HOT_RELOAD", this.localLanguage)
|
|
655
|
+
});
|
|
656
|
+
process4.on("message", async (message) => {
|
|
657
|
+
if (message.type === "HOT_RELOAD_REQUEST") {
|
|
658
|
+
if (this.serverState === "BLOCKED") {
|
|
659
|
+
SLogger(this.localLanguage).logger.info({
|
|
660
|
+
title: TranslationLoader2.t("BLOCKED", this.localLanguage),
|
|
661
|
+
message: TranslationLoader2.t("BLOCKED_STATE", this.localLanguage)
|
|
662
|
+
});
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (this.serverState === "READY") {
|
|
666
|
+
await this.performTrueHotReload();
|
|
602
667
|
}
|
|
603
668
|
}
|
|
604
669
|
});
|
|
605
670
|
}
|
|
606
671
|
/**
|
|
607
|
-
*
|
|
672
|
+
* ✅✅✅ HOT RELOAD avec gestion d'état stricte
|
|
608
673
|
*/
|
|
609
|
-
async
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
674
|
+
async performTrueHotReload() {
|
|
675
|
+
this.serverState = "RELOADING";
|
|
676
|
+
this.hotReloadAttempts++;
|
|
677
|
+
const startTime = Date.now();
|
|
678
|
+
SLogger(this.localLanguage).logger.info({
|
|
679
|
+
title: TranslationLoader2.t("RELOAD_STARTING", this.localLanguage),
|
|
680
|
+
message: TranslationLoader2.t("HOT_RELOAD_ATTEMPTED", this.localLanguage, { hotReloadAttempts: this.hotReloadAttempts })
|
|
681
|
+
});
|
|
615
682
|
try {
|
|
616
|
-
this.
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
683
|
+
const clearedModules = this.clearApplicationModulesCache();
|
|
684
|
+
SLogger(this.localLanguage).logger.info({
|
|
685
|
+
title: TranslationLoader2.t("APP_MODULES_CLEARED", this.localLanguage),
|
|
686
|
+
message: TranslationLoader2.t("CLEARED_MODULES", this.localLanguage, { clearedModules })
|
|
687
|
+
});
|
|
688
|
+
this.reloadConfigurations();
|
|
689
|
+
SLogger(this.localLanguage).logger.info({
|
|
690
|
+
title: TranslationLoader2.t("APP_MODULES_CLEARED", this.localLanguage),
|
|
691
|
+
message: TranslationLoader2.t("CLEARED_MODULES", this.localLanguage, { hotReloadAttempts: this.hotReloadAttempts })
|
|
692
|
+
});
|
|
693
|
+
this.reloadDependencies();
|
|
694
|
+
SLogger(this.localLanguage).logger.info({
|
|
695
|
+
title: TranslationLoader2.t("DEPENDENCIES", this.localLanguage),
|
|
696
|
+
message: TranslationLoader2.t("RELOAD_DEPENDENCIES", this.localLanguage)
|
|
697
|
+
});
|
|
698
|
+
const duration = Date.now() - startTime;
|
|
699
|
+
this.hotReloadSuccesses++;
|
|
700
|
+
this.serverState = "READY";
|
|
701
|
+
this.lastError = null;
|
|
702
|
+
SLogger(this.localLanguage).logger.info({
|
|
703
|
+
title: TranslationLoader2.t("RELOAD_SUCCESS", this.localLanguage),
|
|
704
|
+
message: TranslationLoader2.t("HOT_RELOAD_SUCCESS", this.localLanguage, { duration })
|
|
705
|
+
});
|
|
706
|
+
this.notifyWatcherReloadSuccess(duration);
|
|
621
707
|
} catch (error) {
|
|
622
|
-
|
|
623
|
-
|
|
708
|
+
this.hotReloadFailures++;
|
|
709
|
+
const duration = Date.now() - startTime;
|
|
710
|
+
SLogger(this.localLanguage).logger.info({
|
|
711
|
+
title: TranslationLoader2.t("RELOAD_FAILED", this.localLanguage),
|
|
712
|
+
message: TranslationLoader2.t("HOT_RELOAD_FAILED", this.localLanguage, { duration, errorMessage: error.message })
|
|
713
|
+
});
|
|
714
|
+
const isTransformError = error?.name === "TransformError" || error?.message?.includes("Transform failed") || error?.message?.includes("esbuild");
|
|
715
|
+
if (isTransformError) {
|
|
716
|
+
this.lastError = error;
|
|
717
|
+
this.serverState = "BLOCKED";
|
|
718
|
+
this.notifyWatcherBlockedByError(error);
|
|
719
|
+
} else {
|
|
720
|
+
this.serverState = "BLOCKED";
|
|
721
|
+
this.notifyWatcherReloadError(error);
|
|
722
|
+
}
|
|
624
723
|
}
|
|
625
724
|
}
|
|
626
725
|
/**
|
|
627
|
-
*
|
|
726
|
+
* Nettoie le cache des modules applicatifs
|
|
628
727
|
*/
|
|
629
|
-
|
|
728
|
+
clearApplicationModulesCache() {
|
|
630
729
|
const baseDirs = [
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
path3.join(__dirname, "..")
|
|
730
|
+
path2.join(process4.cwd(), "src"),
|
|
731
|
+
path2.join(process4.cwd(), "dist")
|
|
634
732
|
];
|
|
733
|
+
let clearedCount = 0;
|
|
635
734
|
for (const key in __require.cache) {
|
|
636
|
-
|
|
735
|
+
const isApplicationModule = baseDirs.some((dir) => key.startsWith(dir));
|
|
736
|
+
const isNodeModule = key.includes("node_modules");
|
|
737
|
+
const isJsonFile = key.endsWith(".json");
|
|
738
|
+
if (isApplicationModule && !isNodeModule && !isJsonFile) {
|
|
637
739
|
delete __require.cache[key];
|
|
638
|
-
|
|
740
|
+
clearedCount++;
|
|
639
741
|
}
|
|
640
742
|
}
|
|
641
|
-
|
|
743
|
+
return clearedCount;
|
|
642
744
|
}
|
|
643
|
-
|
|
644
|
-
* Recharger les configurations
|
|
645
|
-
*/
|
|
646
|
-
async reloadConfigurations(context) {
|
|
745
|
+
reloadConfigurations() {
|
|
647
746
|
try {
|
|
648
747
|
const newEnv = getEnvironnementValue2(this.environmentPath);
|
|
649
|
-
Object.
|
|
748
|
+
Object.keys(newEnv).forEach((key) => {
|
|
749
|
+
this.getEnvironment[key] = newEnv[key];
|
|
750
|
+
});
|
|
650
751
|
loaderTranslationFile(this.localLanguage);
|
|
651
|
-
console.log(`${dateTimeFormattedUtils} | [Server] Configurations reloaded`);
|
|
652
752
|
} catch (error) {
|
|
653
|
-
|
|
753
|
+
throw new Error(`Configuration reload failed: ${error.message}`);
|
|
654
754
|
}
|
|
655
755
|
}
|
|
656
|
-
|
|
657
|
-
* Recharger les dépendances
|
|
658
|
-
*/
|
|
659
|
-
async reloadDependencies(context) {
|
|
756
|
+
reloadDependencies() {
|
|
660
757
|
try {
|
|
661
758
|
new SContainer2(this.localLanguage, this.currentDependencies);
|
|
662
|
-
|
|
759
|
+
const container = dependenciesContainerProvider(this.localLanguage);
|
|
760
|
+
if (!container) {
|
|
761
|
+
throw new Error("Dependency container is not available");
|
|
762
|
+
}
|
|
663
763
|
} catch (error) {
|
|
664
|
-
|
|
764
|
+
throw new Error(`Dependency reload failed: ${error.message}`);
|
|
665
765
|
}
|
|
666
766
|
}
|
|
667
767
|
/**
|
|
668
|
-
*
|
|
768
|
+
* ✅✅✅ Notifier le watcher : SUCCÈS
|
|
669
769
|
*/
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
770
|
+
notifyWatcherReloadSuccess(duration) {
|
|
771
|
+
if (process4.send && process4.env.WATCHER_MODE === "true") {
|
|
772
|
+
process4.send({
|
|
773
|
+
type: "HOT_RELOAD_SUCCESS",
|
|
774
|
+
timestamp: Date.now(),
|
|
775
|
+
duration,
|
|
776
|
+
serverState: this.serverState,
|
|
777
|
+
message: "Code reloaded successfully"
|
|
674
778
|
});
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* ✅✅✅ Notifier le watcher : BLOQUÉ PAR ERREUR TRANSFORM
|
|
783
|
+
*/
|
|
784
|
+
notifyWatcherBlockedByError(error) {
|
|
785
|
+
if (process4.send && process4.env.WATCHER_MODE === "true") {
|
|
786
|
+
const errorDetails = this.parseTransformError(error);
|
|
787
|
+
process4.send({
|
|
788
|
+
type: "HOT_RELOAD_BLOCKED_BY_ERROR",
|
|
789
|
+
timestamp: Date.now(),
|
|
790
|
+
serverState: this.serverState,
|
|
791
|
+
error: {
|
|
792
|
+
message: error.message,
|
|
793
|
+
errorType: error.name || "TransformError",
|
|
794
|
+
file: errorDetails.file,
|
|
795
|
+
line: errorDetails.line,
|
|
796
|
+
column: errorDetails.column,
|
|
797
|
+
detail: errorDetails.errorDetail,
|
|
798
|
+
tool: errorDetails.tool
|
|
679
799
|
}
|
|
680
|
-
|
|
681
|
-
}).filter((name) => !!name);
|
|
682
|
-
console.log(`${dateTimeFormattedUtils} | [Server] Routes reloaded: ${context.reloadedRoutes.join(", ")}`);
|
|
683
|
-
} catch (error) {
|
|
684
|
-
console.error(`${dateTimeFormattedUtils} | [Server] Routes reload error:`, error.message);
|
|
685
|
-
throw error;
|
|
800
|
+
});
|
|
686
801
|
}
|
|
687
802
|
}
|
|
688
803
|
/**
|
|
689
|
-
*
|
|
804
|
+
* ✅✅✅ Notifier le watcher : ERREUR GÉNÉRIQUE
|
|
690
805
|
*/
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
806
|
+
notifyWatcherReloadError(error) {
|
|
807
|
+
if (process4.send && process4.env.WATCHER_MODE === "true") {
|
|
808
|
+
process4.send({
|
|
809
|
+
type: "HOT_RELOAD_ERROR",
|
|
810
|
+
timestamp: Date.now(),
|
|
811
|
+
serverState: this.serverState,
|
|
812
|
+
error: error.message,
|
|
813
|
+
errorType: error.name || "UNKNOWN_ERROR"
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* ✅✅✅ Parser les détails d'une TransformError
|
|
819
|
+
*/
|
|
820
|
+
parseTransformError(error) {
|
|
821
|
+
const errorMessage = error.message || String(error);
|
|
822
|
+
let tool = "Unknown";
|
|
823
|
+
if (errorMessage.includes("esbuild")) tool = "esbuild";
|
|
824
|
+
if (errorMessage.includes("webpack")) tool = "webpack";
|
|
825
|
+
const fileMatch = errorMessage.match(/([^:\s]+\.(?:ts|js|tsx|jsx)):(\d+):(\d+):/);
|
|
826
|
+
const file = fileMatch ? fileMatch[1] : null;
|
|
827
|
+
const line = fileMatch ? parseInt(fileMatch[2], 10) : null;
|
|
828
|
+
const column = fileMatch ? parseInt(fileMatch[3], 10) : null;
|
|
829
|
+
const errorDetailMatch = errorMessage.match(/ERROR:\s*(.+?)(?:\n|$)/);
|
|
830
|
+
const errorDetail = errorDetailMatch ? errorDetailMatch[1].trim() : null;
|
|
831
|
+
return {
|
|
832
|
+
message: errorMessage,
|
|
833
|
+
file,
|
|
834
|
+
line,
|
|
835
|
+
column,
|
|
836
|
+
errorDetail,
|
|
837
|
+
tool
|
|
838
|
+
};
|
|
839
|
+
}
|
|
840
|
+
registerRoutes(allFeatureRoutes) {
|
|
841
|
+
allFeatureRoutes.forEach((router) => {
|
|
842
|
+
if (router.routes) {
|
|
843
|
+
router.routes.forEach((route) => {
|
|
844
|
+
this.expressApp.use(route.path, route.handler);
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
infoWebApp() {
|
|
850
|
+
this.serverUtility.infoServer(
|
|
851
|
+
this.getEnvironment.appHost,
|
|
852
|
+
Number(this.getEnvironment.appPort)
|
|
853
|
+
);
|
|
854
|
+
}
|
|
855
|
+
shutdown() {
|
|
856
|
+
if (this.server) {
|
|
857
|
+
this.server.close(() => {
|
|
858
|
+
SLogger(this.localLanguage).logger.info({
|
|
859
|
+
title: TranslationLoader2.t("CLOSED", this.localLanguage),
|
|
860
|
+
message: TranslationLoader2.t("SERVER_CLOSED", this.localLanguage)
|
|
861
|
+
});
|
|
862
|
+
process4.exit(0);
|
|
863
|
+
});
|
|
864
|
+
setTimeout(() => {
|
|
865
|
+
process4.exit(1);
|
|
866
|
+
}, 5e3);
|
|
867
|
+
} else {
|
|
868
|
+
process4.exit(0);
|
|
698
869
|
}
|
|
699
870
|
}
|
|
700
871
|
};
|