opticore-webapp 1.0.65 → 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 +529 -229
- package/dist/index.d.cts +52 -40
- package/dist/index.d.ts +52 -40
- package/dist/index.js +539 -232
- package/dist/utils/translations/message.translation.en.json +32 -1
- package/dist/utils/translations/message.translation.fr.json +26 -1
- package/package.json +8 -8
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,62 +189,25 @@ 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);
|
|
160
199
|
var envPath = import_process.default.cwd() + "/config/env/.env";
|
|
161
200
|
|
|
201
|
+
// src/application/service/loaderTranslationFile.service.ts
|
|
202
|
+
var import_opticore_loader_translation = require("opticore-loader-translation");
|
|
203
|
+
var loaderTranslationFile = (localLanguage) => {
|
|
204
|
+
return (0, import_opticore_loader_translation.translationLoaderConfig)({
|
|
205
|
+
packageName: "opticore-webapp",
|
|
206
|
+
locationTranslationFile: ["utils", "translations"],
|
|
207
|
+
localLang: localLanguage
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
|
|
162
211
|
// src/core/providers/dependencies.provider.ts
|
|
163
212
|
var import_opticore_dependency_inject = require("opticore-dependency-inject");
|
|
164
213
|
|
|
@@ -172,8 +221,8 @@ var dependencies = [
|
|
|
172
221
|
scope: "singleton"
|
|
173
222
|
},
|
|
174
223
|
{
|
|
175
|
-
key: "
|
|
176
|
-
factory: () => new import_opticore_server_logger.
|
|
224
|
+
key: "OpticoreLogger",
|
|
225
|
+
factory: () => new import_opticore_server_logger.OpticoreLogger(),
|
|
177
226
|
scope: "singleton"
|
|
178
227
|
}
|
|
179
228
|
];
|
|
@@ -183,33 +232,33 @@ var dependenciesContainerProvider = (localLang) => {
|
|
|
183
232
|
return new import_opticore_dependency_inject.SContainer(localLang, dependencies);
|
|
184
233
|
};
|
|
185
234
|
|
|
235
|
+
// src/application/service/core.service.ts
|
|
236
|
+
var import_opticore_logger2 = require("opticore-logger");
|
|
237
|
+
|
|
186
238
|
// src/application/service/logger.service.ts
|
|
187
239
|
var SLogger = (localLang) => {
|
|
188
|
-
const serverLog = dependenciesContainerProvider(localLang).resolve("serverLogger");
|
|
189
|
-
const logger = dependenciesContainerProvider(localLang).resolve("LoggerCore");
|
|
190
240
|
return {
|
|
191
|
-
serverLog
|
|
192
|
-
|
|
241
|
+
get serverLog() {
|
|
242
|
+
return dependenciesContainerProvider(localLang).resolve("OpticoreLogger");
|
|
243
|
+
},
|
|
244
|
+
get logger() {
|
|
245
|
+
return dependenciesContainerProvider(localLang).resolve("LoggerCore");
|
|
246
|
+
}
|
|
193
247
|
};
|
|
194
248
|
};
|
|
195
249
|
|
|
196
|
-
// src/application/service/loaderTranslationFile.service.ts
|
|
197
|
-
var import_opticore_loader_translation = require("opticore-loader-translation");
|
|
198
|
-
var loaderTranslationFile = (localLanguage) => {
|
|
199
|
-
return (0, import_opticore_loader_translation.translationLoaderConfig)({
|
|
200
|
-
packageName: "opticore-webapp",
|
|
201
|
-
locationTranslationFile: ["utils", "translations"],
|
|
202
|
-
localLang: localLanguage
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
|
|
206
250
|
// src/application/service/core.service.ts
|
|
207
251
|
var CoreService = class {
|
|
208
252
|
localLanguage;
|
|
209
253
|
environmentPath;
|
|
254
|
+
serverLog;
|
|
255
|
+
logger;
|
|
210
256
|
constructor(localLang, environmentPath) {
|
|
211
257
|
this.environmentPath = environmentPath;
|
|
212
258
|
this.localLanguage = localLang;
|
|
259
|
+
loaderTranslationFile(this.localLanguage);
|
|
260
|
+
this.serverLog = dependenciesContainerProvider(localLang).resolve("OpticoreLogger");
|
|
261
|
+
this.logger = dependenciesContainerProvider(localLang).resolve("LoggerCore");
|
|
213
262
|
}
|
|
214
263
|
/**
|
|
215
264
|
*
|
|
@@ -248,20 +297,20 @@ var CoreService = class {
|
|
|
248
297
|
loaderTranslationFile(this.localLanguage);
|
|
249
298
|
const memoryData = import_node_process2.default.memoryUsage();
|
|
250
299
|
const data = {
|
|
251
|
-
[
|
|
252
|
-
[
|
|
253
|
-
[
|
|
254
|
-
[
|
|
255
|
-
[
|
|
256
|
-
[
|
|
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)
|
|
257
306
|
};
|
|
258
307
|
return {
|
|
259
|
-
"rss": data[
|
|
260
|
-
"heapTotal": data[
|
|
261
|
-
"heapUsed": data[
|
|
262
|
-
"external": data[
|
|
263
|
-
"user": data[
|
|
264
|
-
"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)],
|
|
265
314
|
"pid": import_node_process2.default.pid
|
|
266
315
|
};
|
|
267
316
|
}
|
|
@@ -299,9 +348,9 @@ var CoreService = class {
|
|
|
299
348
|
});
|
|
300
349
|
}
|
|
301
350
|
} catch (err) {
|
|
302
|
-
|
|
351
|
+
this.logger.error({
|
|
303
352
|
message: err.message,
|
|
304
|
-
title:
|
|
353
|
+
title: import_opticore_translator.TranslationLoader.t("EnvFileLoading", this.localLanguage),
|
|
305
354
|
errorType: err.code,
|
|
306
355
|
stackTrace: err.stack,
|
|
307
356
|
httpCodeValue: import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
@@ -322,37 +371,37 @@ var CoreService = class {
|
|
|
322
371
|
const env = (0, import_opticore_env_access.getEnvironnementValue)(path.join(envPath));
|
|
323
372
|
const isDevelopment = env.devEnv === development && env.prodEnv === "";
|
|
324
373
|
if (isDevelopment) {
|
|
325
|
-
return `${
|
|
374
|
+
return `${import_opticore_translator.TranslationLoader.t("serverRunning", this.localLanguage)} ${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${development}`)}`)} mode`;
|
|
326
375
|
} else if (!isDevelopment) {
|
|
327
|
-
return `${
|
|
376
|
+
return `${import_opticore_translator.TranslationLoader.t("serverRunning", this.localLanguage)} ${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${production}`)}`)} mode`;
|
|
328
377
|
} else {
|
|
329
|
-
return `${
|
|
378
|
+
return `${import_opticore_translator.TranslationLoader.t("serverRunning", this.localLanguage)} ${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${development}`)}`)} mode`;
|
|
330
379
|
}
|
|
331
380
|
} catch (err) {
|
|
332
|
-
|
|
381
|
+
this.logger.error({
|
|
333
382
|
message: err.message,
|
|
334
|
-
title:
|
|
383
|
+
title: import_opticore_translator.TranslationLoader.t("serverRunning mode", this.localLanguage),
|
|
335
384
|
errorType: err.code,
|
|
336
385
|
stackTrace: err.stack,
|
|
337
386
|
httpCodeValue: import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
338
387
|
});
|
|
339
388
|
}
|
|
340
389
|
}
|
|
341
|
-
infoServer(
|
|
390
|
+
infoServer(host, port) {
|
|
342
391
|
try {
|
|
343
392
|
loaderTranslationFile(this.localLanguage);
|
|
344
393
|
const getEnvironment = (0, import_opticore_env_access.getEnvironnementValue)(this.environmentPath);
|
|
345
|
-
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}`);
|
|
346
395
|
const messages = [
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
this.getServerRunningMode(
|
|
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))
|
|
351
400
|
];
|
|
352
401
|
const maxLength = Math.max(...messages.map((m) => {
|
|
353
402
|
return m.replace(/\u001b\[[0-9]{1,2}m/g, "").length;
|
|
354
403
|
})) + 4;
|
|
355
|
-
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")})`));
|
|
356
405
|
const border = import_chalk.default.bgGreen.white(" ".repeat(maxLength));
|
|
357
406
|
console.log(border);
|
|
358
407
|
messages.forEach((msg) => {
|
|
@@ -362,57 +411,39 @@ var CoreService = class {
|
|
|
362
411
|
});
|
|
363
412
|
console.log(border);
|
|
364
413
|
console.log("\n");
|
|
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
|
+
});
|
|
365
419
|
SLogger(this.localLanguage).serverLog.serverLog({
|
|
366
420
|
timestamp: (/* @__PURE__ */ new Date()).toString(),
|
|
367
421
|
level: "SERVER",
|
|
368
|
-
title:
|
|
369
|
-
typeName:
|
|
370
|
-
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 })
|
|
371
425
|
});
|
|
372
426
|
} catch (err) {
|
|
373
427
|
SLogger(this.localLanguage).logger.error({
|
|
374
428
|
message: err.message,
|
|
375
|
-
title:
|
|
429
|
+
title: import_opticore_translator.TranslationLoader.t("server", this.localLanguage),
|
|
376
430
|
errorType: err.code,
|
|
377
431
|
stackTrace: err.stack,
|
|
378
432
|
httpCodeValue: import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
379
433
|
});
|
|
380
434
|
}
|
|
381
435
|
}
|
|
382
|
-
coreListenerEventLoaderModuleService(kernelModule) {
|
|
383
|
-
loaderTranslationFile(this.localLanguage);
|
|
384
|
-
let router = [];
|
|
385
|
-
let dbCon;
|
|
386
|
-
kernelModule.forEach((module2) => {
|
|
387
|
-
if (Array.isArray(module2)) {
|
|
388
|
-
router = module2;
|
|
389
|
-
} else if (typeof module2 === "function") {
|
|
390
|
-
dbCon = module2;
|
|
391
|
-
}
|
|
392
|
-
});
|
|
393
|
-
if (router && dbCon) {
|
|
394
|
-
modulesLoadedUtils(router, dbCon, this.localLanguage);
|
|
395
|
-
(() => {
|
|
396
|
-
dbCon();
|
|
397
|
-
})();
|
|
398
|
-
} else {
|
|
399
|
-
const stackTrace = STraceError(
|
|
400
|
-
import_opticore_translator2.TranslationLoader.t("loadedModulesError", this.localLanguage),
|
|
401
|
-
import_opticore_translator2.TranslationLoader.t("loadedModules", this.localLanguage),
|
|
402
|
-
import_opticore_http_response.HttpStatusCode.NOT_ACCEPTABLE,
|
|
403
|
-
true
|
|
404
|
-
);
|
|
405
|
-
throw new Error(stackTrace.message);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
436
|
};
|
|
409
437
|
|
|
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()}`;
|
|
440
|
+
|
|
410
441
|
// src/application/service/serverStartError.service.ts
|
|
411
|
-
var
|
|
442
|
+
var import_opticore_catch_exception_error2 = require("opticore-catch-exception-error");
|
|
412
443
|
var import_opticore_http_response2 = require("opticore-http-response");
|
|
413
444
|
var SServerStartError = (err, environmentPath) => {
|
|
414
445
|
if (err.name) {
|
|
415
|
-
for (const [key, code] of Object.entries(
|
|
446
|
+
for (const [key, code] of Object.entries(import_opticore_catch_exception_error2.CErrorName)) {
|
|
416
447
|
if (err.name === code) {
|
|
417
448
|
SLogger(environmentPath).logger.error({
|
|
418
449
|
message: err.message,
|
|
@@ -425,7 +456,7 @@ var SServerStartError = (err, environmentPath) => {
|
|
|
425
456
|
}
|
|
426
457
|
}
|
|
427
458
|
} else {
|
|
428
|
-
for (const [key, code] of Object.entries(
|
|
459
|
+
for (const [key, code] of Object.entries(import_opticore_catch_exception_error2.CCodeError)) {
|
|
429
460
|
if (err.code === code) {
|
|
430
461
|
SLogger(environmentPath).logger.error({
|
|
431
462
|
message: err.message,
|
|
@@ -444,110 +475,146 @@ var SServerStartError = (err, environmentPath) => {
|
|
|
444
475
|
var import_opticore_request_call_event = require("opticore-request-call-event");
|
|
445
476
|
var import_opticore_dependency_inject2 = require("opticore-dependency-inject");
|
|
446
477
|
var import_opticore_http_response3 = require("opticore-http-response");
|
|
447
|
-
var
|
|
478
|
+
var import_opticore_translator2 = require("opticore-translator");
|
|
448
479
|
var WebServerCore = class {
|
|
449
480
|
serverUtility;
|
|
450
|
-
expressApp = (0,
|
|
481
|
+
expressApp = (0, import_opticore_express.express)();
|
|
451
482
|
localLanguage;
|
|
452
483
|
loggerConfig;
|
|
453
484
|
routerExpressApp;
|
|
454
485
|
getEnvironment;
|
|
455
486
|
environmentPath;
|
|
456
487
|
serverListenEvent;
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
this.
|
|
470
|
-
this.
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
errorType: err.code,
|
|
484
|
-
stackTrace: err.stack,
|
|
485
|
-
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
+
currentRoutes = [];
|
|
489
|
+
currentDependencies = [];
|
|
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);
|
|
512
|
+
this.setupSignalHandlers();
|
|
513
|
+
this.setupIPCHandlers();
|
|
488
514
|
}
|
|
489
|
-
/**
|
|
490
|
-
*
|
|
491
|
-
* @param routers
|
|
492
|
-
* @param databaseCallback
|
|
493
|
-
* @param dependenciesProvider
|
|
494
|
-
*/
|
|
495
515
|
onStartServer(routers, databaseCallback, dependenciesProvider) {
|
|
496
516
|
loaderTranslationFile(this.localLanguage);
|
|
517
|
+
this.currentRoutes = routers;
|
|
518
|
+
this.currentDependencies = dependenciesProvider || [];
|
|
497
519
|
if (this.getEnvironment.appPort === "" && Number(this.getEnvironment.appPort) === 0) {
|
|
498
520
|
this.serverListenEvent.hostPortUndefined(Number(this.getEnvironment.appPort));
|
|
499
|
-
|
|
521
|
+
return void 0;
|
|
522
|
+
}
|
|
523
|
+
if (this.getEnvironment.appHost === "") {
|
|
500
524
|
this.serverListenEvent.hostUndefined(this.getEnvironment.appHost);
|
|
501
|
-
|
|
525
|
+
return void 0;
|
|
526
|
+
}
|
|
527
|
+
if (Number(this.getEnvironment.appPort) === 0) {
|
|
502
528
|
this.serverListenEvent.portUndefined();
|
|
503
|
-
|
|
529
|
+
return void 0;
|
|
530
|
+
}
|
|
531
|
+
if (this.localLanguage === "") {
|
|
504
532
|
SLogger(this.localLanguage).logger.error({
|
|
505
|
-
message:
|
|
506
|
-
title:
|
|
507
|
-
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),
|
|
508
536
|
stackTrace: void 0,
|
|
509
537
|
httpCodeValue: import_opticore_http_response3.HttpStatusCode.NOT_FOUND
|
|
510
538
|
});
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
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) {
|
|
517
551
|
databaseCallback(this.getEnvironment);
|
|
518
|
-
new import_opticore_dependency_inject2.SContainer(this.localLanguage, dependenciesProvider);
|
|
519
|
-
this.expressApp.use(import_opticore_express2.express.static(path2.join(import_node_process3.default.cwd(), "public/template")));
|
|
520
|
-
this.registerRoutes(routers);
|
|
521
|
-
} catch (err) {
|
|
522
|
-
SServerStartError(err, this.environmentPath);
|
|
523
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);
|
|
524
570
|
}
|
|
525
|
-
|
|
526
|
-
|
|
571
|
+
}
|
|
572
|
+
);
|
|
573
|
+
return this.server;
|
|
527
574
|
}
|
|
528
575
|
/**
|
|
529
|
-
*
|
|
530
|
-
* @param serverWeb
|
|
576
|
+
* ✅✅✅ Configuration de la gestion d'erreurs
|
|
531
577
|
*/
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
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) => {
|
|
535
609
|
this.serverListenEvent.onEventError(err);
|
|
536
|
-
})
|
|
610
|
+
});
|
|
611
|
+
this.server.on(import_opticore_catch_exception_error3.CEventNameError.close, () => {
|
|
537
612
|
this.serverListenEvent.serverClosing();
|
|
538
|
-
})
|
|
613
|
+
});
|
|
614
|
+
this.server.on(import_opticore_catch_exception_error3.CEventNameError.drop, () => {
|
|
539
615
|
this.serverListenEvent.dropNewConnection();
|
|
540
|
-
}).on(import_opticore_catch_exception_error4.CEventNameError.listening, () => {
|
|
541
|
-
this.infoWebApp();
|
|
542
616
|
});
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
*
|
|
546
|
-
* @param serverWeb
|
|
547
|
-
*/
|
|
548
|
-
onRequestOnServerEvent(serverWeb) {
|
|
549
|
-
loaderTranslationFile(this.localLanguage);
|
|
550
|
-
serverWeb.on(import_opticore_catch_exception_error4.CEventNameError.request, (req, res) => {
|
|
617
|
+
this.server.on(import_opticore_catch_exception_error3.CEventNameError.request, (req, res) => {
|
|
551
618
|
(0, import_opticore_request_call_event.requestCallsEvent)(
|
|
552
619
|
req,
|
|
553
620
|
res,
|
|
@@ -559,38 +626,271 @@ var WebServerCore = class {
|
|
|
559
626
|
);
|
|
560
627
|
});
|
|
561
628
|
}
|
|
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);
|
|
641
|
+
}
|
|
642
|
+
setupSignalHandlers() {
|
|
643
|
+
import_node_process3.default.on("SIGHUP", async () => {
|
|
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();
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
}
|
|
562
694
|
/**
|
|
563
|
-
*
|
|
564
|
-
* @param allFeatureRoutes
|
|
565
|
-
* @private
|
|
695
|
+
* ✅✅✅ HOT RELOAD avec gestion d'état stricte
|
|
566
696
|
*/
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
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 })
|
|
572
704
|
});
|
|
705
|
+
try {
|
|
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);
|
|
730
|
+
} catch (error) {
|
|
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
|
+
}
|
|
746
|
+
}
|
|
573
747
|
}
|
|
574
748
|
/**
|
|
575
|
-
*
|
|
576
|
-
* @param localLanguage
|
|
577
|
-
* @private
|
|
749
|
+
* Nettoie le cache des modules applicatifs
|
|
578
750
|
*/
|
|
579
|
-
|
|
580
|
-
|
|
751
|
+
clearApplicationModulesCache() {
|
|
752
|
+
const baseDirs = [
|
|
753
|
+
path2.join(import_node_process3.default.cwd(), "src"),
|
|
754
|
+
path2.join(import_node_process3.default.cwd(), "dist")
|
|
755
|
+
];
|
|
756
|
+
let clearedCount = 0;
|
|
757
|
+
for (const key in require.cache) {
|
|
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) {
|
|
762
|
+
delete require.cache[key];
|
|
763
|
+
clearedCount++;
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return clearedCount;
|
|
767
|
+
}
|
|
768
|
+
reloadConfigurations() {
|
|
769
|
+
try {
|
|
770
|
+
const newEnv = (0, import_opticore_env_access2.getEnvironnementValue)(this.environmentPath);
|
|
771
|
+
Object.keys(newEnv).forEach((key) => {
|
|
772
|
+
this.getEnvironment[key] = newEnv[key];
|
|
773
|
+
});
|
|
774
|
+
loaderTranslationFile(this.localLanguage);
|
|
775
|
+
} catch (error) {
|
|
776
|
+
throw new Error(`Configuration reload failed: ${error.message}`);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
reloadDependencies() {
|
|
780
|
+
try {
|
|
781
|
+
new import_opticore_dependency_inject2.SContainer(this.localLanguage, this.currentDependencies);
|
|
782
|
+
const container = dependenciesContainerProvider(this.localLanguage);
|
|
783
|
+
if (!container) {
|
|
784
|
+
throw new Error("Dependency container is not available");
|
|
785
|
+
}
|
|
786
|
+
} catch (error) {
|
|
787
|
+
throw new Error(`Dependency reload failed: ${error.message}`);
|
|
788
|
+
}
|
|
581
789
|
}
|
|
582
790
|
/**
|
|
583
|
-
*
|
|
584
|
-
* @private
|
|
791
|
+
* ✅✅✅ Notifier le watcher : SUCCÈS
|
|
585
792
|
*/
|
|
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"
|
|
801
|
+
});
|
|
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
|
|
822
|
+
}
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* ✅✅✅ Notifier le watcher : ERREUR GÉNÉRIQUE
|
|
828
|
+
*/
|
|
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
|
+
}
|
|
586
872
|
infoWebApp() {
|
|
587
873
|
this.serverUtility.infoServer(
|
|
588
|
-
this.serverUtility.getVersions().nodeVersion,
|
|
589
|
-
this.serverUtility.getProjectInfo().startingTime,
|
|
590
874
|
this.getEnvironment.appHost,
|
|
591
875
|
Number(this.getEnvironment.appPort)
|
|
592
876
|
);
|
|
593
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);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
594
894
|
};
|
|
595
895
|
// Annotate the CommonJS export names for ESM import in node:
|
|
596
896
|
0 && (module.exports = {
|