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