opticore-webapp 1.0.66 → 1.0.68
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 +857 -302
- package/dist/index.d.cts +173 -53
- package/dist/index.d.ts +173 -53
- package/dist/index.js +868 -327
- package/dist/utils/translations/message.translation.en.json +79 -4
- package/dist/utils/translations/message.translation.fr.json +74 -3
- package/package.json +10 -9
package/dist/index.cjs
CHANGED
|
@@ -39,22 +39,106 @@ 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
|
+
var import_opticore_request_call_event = require("opticore-request-call-event");
|
|
46
|
+
var import_opticore_dependency_inject2 = require("opticore-dependency-inject");
|
|
47
|
+
var import_opticore_http_response3 = require("opticore-http-response");
|
|
48
|
+
var import_opticore_translator2 = require("opticore-translator");
|
|
45
49
|
|
|
46
50
|
// src/core/handlers/eventProcess.handler.ts
|
|
47
51
|
var import_node_process = __toESM(require("process"), 1);
|
|
48
52
|
var import_node_events = __toESM(require("events"), 1);
|
|
49
|
-
var import_opticore_express = require("opticore-express");
|
|
50
53
|
var import_opticore_catch_exception_error = require("opticore-catch-exception-error");
|
|
51
|
-
|
|
54
|
+
|
|
55
|
+
// src/utils/isTransformError.utils.ts
|
|
56
|
+
var isTransformErrorUtils = (error) => {
|
|
57
|
+
return error?.name === "TransformError" || error?.message?.includes("Transform failed") || error?.message?.includes("esbuild");
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/core/handlers/eventProcess.handler.ts
|
|
61
|
+
function eventProcessHandler(localeLanguage, expressApp) {
|
|
52
62
|
const errorEmitter = new import_node_events.default();
|
|
53
|
-
const app = (0, import_opticore_express.express)();
|
|
54
63
|
const serverListenEvent = new import_opticore_catch_exception_error.ServerListenEventError(localeLanguage);
|
|
64
|
+
console.log("[Server] Setting up error event handlers...");
|
|
55
65
|
errorEmitter.on(import_opticore_catch_exception_error.CEventNameError.error, (error) => {
|
|
66
|
+
console.error("[Server] EventEmitter error caught:", error.message);
|
|
67
|
+
if (isTransformErrorUtils(error)) {
|
|
68
|
+
handleTransformError(error);
|
|
69
|
+
}
|
|
56
70
|
serverListenEvent.listenerError(error);
|
|
57
71
|
});
|
|
72
|
+
function handleTransformError(error) {
|
|
73
|
+
console.error("[Server] ============================================");
|
|
74
|
+
console.error("[Server] TRANSFORM ERROR DETECTED");
|
|
75
|
+
console.error("[Server] ============================================");
|
|
76
|
+
console.error("[Server] Message:", error.message);
|
|
77
|
+
console.error("[Server] Stack:", error.stack);
|
|
78
|
+
if (error.errors && Array.isArray(error.errors)) {
|
|
79
|
+
error.errors.forEach((err, index) => {
|
|
80
|
+
console.error(`[Server] Error ${index + 1}:`, err.text);
|
|
81
|
+
if (err.location) {
|
|
82
|
+
console.error(`[Server] File: ${err.location.file}`);
|
|
83
|
+
console.error(`[Server] Line: ${err.location.line}, Column: ${err.location.column}`);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const fileMatch = error.message.match(/([^:]+\.ts):(\d+):(\d+):/);
|
|
88
|
+
if (fileMatch) {
|
|
89
|
+
console.error("[Server] Problem file:", fileMatch[1]);
|
|
90
|
+
console.error("[Server] Line:", fileMatch[2], "Column:", fileMatch[3]);
|
|
91
|
+
}
|
|
92
|
+
const errorDetailMatch = error.message.match(/ERROR: (.+)$/m);
|
|
93
|
+
if (errorDetailMatch) {
|
|
94
|
+
console.error("[Server] Error detail:", errorDetailMatch[1]);
|
|
95
|
+
}
|
|
96
|
+
console.error("[Server] ============================================");
|
|
97
|
+
if (import_node_process.default.send) {
|
|
98
|
+
import_node_process.default.send({
|
|
99
|
+
type: "TRANSFORM_ERROR",
|
|
100
|
+
error: error.message,
|
|
101
|
+
stack: error.stack,
|
|
102
|
+
errorName: error.name,
|
|
103
|
+
details: error.errors,
|
|
104
|
+
timestamp: Date.now()
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.uncaughtException, (error) => {
|
|
109
|
+
console.error("[Server] UNCAUGHT EXCEPTION:", error.message);
|
|
110
|
+
console.error("[Server] Stack:", error.stack);
|
|
111
|
+
if (isTransformErrorUtils(error)) {
|
|
112
|
+
errorEmitter.emit("transformError", error);
|
|
113
|
+
}
|
|
114
|
+
serverListenEvent.uncaughtException(error);
|
|
115
|
+
if (import_node_process.default.send) {
|
|
116
|
+
const messageType = isTransformErrorUtils(error) ? "TRANSFORM_ERROR" : "HOT_RELOAD_ERROR";
|
|
117
|
+
import_node_process.default.send({
|
|
118
|
+
type: messageType,
|
|
119
|
+
error: error.message,
|
|
120
|
+
stack: error.stack,
|
|
121
|
+
errorName: error.name,
|
|
122
|
+
timestamp: Date.now()
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.unhandledRejection, (reason, promise) => {
|
|
127
|
+
console.error("[Server] UNHANDLED REJECTION:", reason);
|
|
128
|
+
if (isTransformErrorUtils(reason)) {
|
|
129
|
+
errorEmitter.emit("transformError", reason);
|
|
130
|
+
}
|
|
131
|
+
serverListenEvent.unhandledRejection(reason, promise);
|
|
132
|
+
if (import_node_process.default.send) {
|
|
133
|
+
const messageType = isTransformErrorUtils(reason) ? "TRANSFORM_ERROR" : "HOT_RELOAD_ERROR";
|
|
134
|
+
import_node_process.default.send({
|
|
135
|
+
type: messageType,
|
|
136
|
+
error: reason?.message || String(reason),
|
|
137
|
+
errorName: reason?.name,
|
|
138
|
+
timestamp: Date.now()
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
});
|
|
58
142
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.beforeExit, (code) => {
|
|
59
143
|
setTimeout(() => {
|
|
60
144
|
serverListenEvent.processBeforeExit(code);
|
|
@@ -69,20 +153,20 @@ function eventProcessHandler(localeLanguage) {
|
|
|
69
153
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.rejectionHandled, (promise) => {
|
|
70
154
|
serverListenEvent.promiseRejectionHandled(promise);
|
|
71
155
|
});
|
|
72
|
-
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.uncaughtException, (error) => {
|
|
73
|
-
serverListenEvent.uncaughtException(error);
|
|
74
|
-
});
|
|
75
156
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.uncaughtExceptionMonitor, (error) => {
|
|
157
|
+
console.error("[Server] UNCAUGHT EXCEPTION MONITOR:", error.message);
|
|
158
|
+
if (isTransformErrorUtils(error)) {
|
|
159
|
+
errorEmitter.emit("transformError", error);
|
|
160
|
+
}
|
|
76
161
|
serverListenEvent.uncaughtExceptionMonitor(error);
|
|
77
162
|
});
|
|
78
|
-
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.unhandledRejection, (reason, promise) => {
|
|
79
|
-
serverListenEvent.unhandledRejection(reason, promise);
|
|
80
|
-
});
|
|
81
163
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.warning, (warning) => {
|
|
82
164
|
serverListenEvent.warning(warning);
|
|
83
165
|
});
|
|
84
166
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.message, (message) => {
|
|
85
|
-
|
|
167
|
+
if (message.type !== "HOT_RELOAD_REQUEST" && message.type !== "SERVER_READY") {
|
|
168
|
+
serverListenEvent.message(message);
|
|
169
|
+
}
|
|
86
170
|
});
|
|
87
171
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.multipleResolves, (type, promise, reason) => {
|
|
88
172
|
serverListenEvent.multipleResolves(type, promise, reason);
|
|
@@ -93,9 +177,15 @@ function eventProcessHandler(localeLanguage) {
|
|
|
93
177
|
import_node_process.default.on(import_opticore_catch_exception_error.CEvent.sigterm, (signal) => {
|
|
94
178
|
serverListenEvent.sigtermSignalReceived(signal);
|
|
95
179
|
});
|
|
96
|
-
|
|
180
|
+
expressApp.use((err, req, res, next) => {
|
|
181
|
+
console.error("[Server] Express error middleware triggered:", err.message);
|
|
182
|
+
console.error("[Server] Request URL:", req.url);
|
|
183
|
+
console.error("[Server] Request method:", req.method);
|
|
184
|
+
errorEmitter.emit(import_opticore_catch_exception_error.CEventNameError.error, err);
|
|
97
185
|
serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
98
186
|
});
|
|
187
|
+
console.log("[Server] Error event handlers configured successfully");
|
|
188
|
+
return errorEmitter;
|
|
99
189
|
}
|
|
100
190
|
|
|
101
191
|
// src/application/service/core.service.ts
|
|
@@ -103,57 +193,10 @@ var import_node_process2 = __toESM(require("process"), 1);
|
|
|
103
193
|
var import_chalk = __toESM(require("chalk"), 1);
|
|
104
194
|
var path = __toESM(require("path"), 1);
|
|
105
195
|
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
196
|
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
|
|
197
|
+
var import_opticore_http_response = require("opticore-http-response");
|
|
140
198
|
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
|
-
};
|
|
199
|
+
var import_opticore_env_access = require("opticore-env-access");
|
|
157
200
|
|
|
158
201
|
// src/utils/envPath.utils.ts
|
|
159
202
|
var import_process = __toESM(require("process"), 1);
|
|
@@ -193,6 +236,21 @@ var dependenciesContainerProvider = (localLang) => {
|
|
|
193
236
|
return new import_opticore_dependency_inject.SContainer(localLang, dependencies);
|
|
194
237
|
};
|
|
195
238
|
|
|
239
|
+
// src/application/service/core.service.ts
|
|
240
|
+
var import_opticore_logger2 = require("opticore-logger");
|
|
241
|
+
|
|
242
|
+
// src/application/service/logger.service.ts
|
|
243
|
+
var SLogger = (localLang) => {
|
|
244
|
+
return {
|
|
245
|
+
get serverLog() {
|
|
246
|
+
return dependenciesContainerProvider(localLang).resolve("OpticoreLogger");
|
|
247
|
+
},
|
|
248
|
+
get logger() {
|
|
249
|
+
return dependenciesContainerProvider(localLang).resolve("LoggerCore");
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
|
|
196
254
|
// src/application/service/core.service.ts
|
|
197
255
|
var CoreService = class {
|
|
198
256
|
localLanguage;
|
|
@@ -202,6 +260,7 @@ var CoreService = class {
|
|
|
202
260
|
constructor(localLang, environmentPath) {
|
|
203
261
|
this.environmentPath = environmentPath;
|
|
204
262
|
this.localLanguage = localLang;
|
|
263
|
+
loaderTranslationFile(this.localLanguage);
|
|
205
264
|
this.serverLog = dependenciesContainerProvider(localLang).resolve("OpticoreLogger");
|
|
206
265
|
this.logger = dependenciesContainerProvider(localLang).resolve("LoggerCore");
|
|
207
266
|
}
|
|
@@ -242,20 +301,20 @@ var CoreService = class {
|
|
|
242
301
|
loaderTranslationFile(this.localLanguage);
|
|
243
302
|
const memoryData = import_node_process2.default.memoryUsage();
|
|
244
303
|
const data = {
|
|
245
|
-
[
|
|
246
|
-
[
|
|
247
|
-
[
|
|
248
|
-
[
|
|
249
|
-
[
|
|
250
|
-
[
|
|
304
|
+
[import_opticore_translator.TranslationLoader.t("totalMemoryAllocated", this.localLanguage)]: this.formatMemoryUsage(memoryData.rss),
|
|
305
|
+
[import_opticore_translator.TranslationLoader.t("sizeAllocatedHeap", this.localLanguage)]: this.formatMemoryUsage(memoryData.heapTotal),
|
|
306
|
+
[import_opticore_translator.TranslationLoader.t("memoryUsedExecution", this.localLanguage)]: this.formatMemoryUsage(memoryData.heapUsed),
|
|
307
|
+
[import_opticore_translator.TranslationLoader.t("externalMemory", this.localLanguage)]: this.formatMemoryUsage(memoryData.external),
|
|
308
|
+
[import_opticore_translator.TranslationLoader.t("memoryUsageUser", this.localLanguage)]: this.formatMemoryUsage(import_node_process2.default.cpuUsage().user),
|
|
309
|
+
[import_opticore_translator.TranslationLoader.t("memoryUsageSystem", this.localLanguage)]: this.formatMemoryUsage(import_node_process2.default.cpuUsage().system)
|
|
251
310
|
};
|
|
252
311
|
return {
|
|
253
|
-
"rss": data[
|
|
254
|
-
"heapTotal": data[
|
|
255
|
-
"heapUsed": data[
|
|
256
|
-
"external": data[
|
|
257
|
-
"user": data[
|
|
258
|
-
"system": data[
|
|
312
|
+
"rss": data[import_opticore_translator.TranslationLoader.t("totalMemoryAllocated", this.localLanguage)],
|
|
313
|
+
"heapTotal": data[import_opticore_translator.TranslationLoader.t("sizeAllocatedHeap", this.localLanguage)],
|
|
314
|
+
"heapUsed": data[import_opticore_translator.TranslationLoader.t("memoryUsedExecution", this.localLanguage)],
|
|
315
|
+
"external": data[import_opticore_translator.TranslationLoader.t("externalMemory", this.localLanguage)],
|
|
316
|
+
"user": data[import_opticore_translator.TranslationLoader.t("memoryUsageUser", this.localLanguage)],
|
|
317
|
+
"system": data[import_opticore_translator.TranslationLoader.t("memoryUsageSystem", this.localLanguage)],
|
|
259
318
|
"pid": import_node_process2.default.pid
|
|
260
319
|
};
|
|
261
320
|
}
|
|
@@ -295,7 +354,7 @@ var CoreService = class {
|
|
|
295
354
|
} catch (err) {
|
|
296
355
|
this.logger.error({
|
|
297
356
|
message: err.message,
|
|
298
|
-
title:
|
|
357
|
+
title: import_opticore_translator.TranslationLoader.t("EnvFileLoading", this.localLanguage),
|
|
299
358
|
errorType: err.code,
|
|
300
359
|
stackTrace: err.stack,
|
|
301
360
|
httpCodeValue: import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
@@ -316,16 +375,16 @@ var CoreService = class {
|
|
|
316
375
|
const env = (0, import_opticore_env_access.getEnvironnementValue)(path.join(envPath));
|
|
317
376
|
const isDevelopment = env.devEnv === development && env.prodEnv === "";
|
|
318
377
|
if (isDevelopment) {
|
|
319
|
-
return `${
|
|
378
|
+
return `${import_opticore_translator.TranslationLoader.t("serverRunning", this.localLanguage)} ${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${development}`)}`)} mode`;
|
|
320
379
|
} else if (!isDevelopment) {
|
|
321
|
-
return `${
|
|
380
|
+
return `${import_opticore_translator.TranslationLoader.t("serverRunning", this.localLanguage)} ${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${production}`)}`)} mode`;
|
|
322
381
|
} else {
|
|
323
|
-
return `${
|
|
382
|
+
return `${import_opticore_translator.TranslationLoader.t("serverRunning", this.localLanguage)} ${import_ansi_colors.default.bgBlue(`${import_ansi_colors.default.bold(`${development}`)}`)} mode`;
|
|
324
383
|
}
|
|
325
384
|
} catch (err) {
|
|
326
385
|
this.logger.error({
|
|
327
386
|
message: err.message,
|
|
328
|
-
title:
|
|
387
|
+
title: import_opticore_translator.TranslationLoader.t("serverRunning mode", this.localLanguage),
|
|
329
388
|
errorType: err.code,
|
|
330
389
|
stackTrace: err.stack,
|
|
331
390
|
httpCodeValue: import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
@@ -336,20 +395,17 @@ var CoreService = class {
|
|
|
336
395
|
try {
|
|
337
396
|
loaderTranslationFile(this.localLanguage);
|
|
338
397
|
const getEnvironment = (0, import_opticore_env_access.getEnvironnementValue)(this.environmentPath);
|
|
339
|
-
const msg5 = getEnvironment.protocolTransfert === "" ?
|
|
398
|
+
const msg5 = getEnvironment.protocolTransfert === "" ? import_ansi_colors.default.underline(`http://${host}:${port}`) : import_ansi_colors.default.underline(`${getEnvironment.protocolTransfert}://${host}:${port}`);
|
|
340
399
|
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
|
-
)
|
|
400
|
+
import_opticore_translator.TranslationLoader.t("webServerListening", this.localLanguage),
|
|
401
|
+
import_opticore_translator.TranslationLoader.t("webServerUsingNodeVersion", this.localLanguage, { nodeVersion: this.getVersions().nodeVersion }),
|
|
402
|
+
import_opticore_translator.TranslationLoader.t("startTime", this.localLanguage, { startTime: this.getProjectInfo().startingTime }),
|
|
403
|
+
this.getServerRunningMode(import_opticore_translator.TranslationLoader.t("runningModeDev", this.localLanguage), import_opticore_translator.TranslationLoader.t("runningModeProd", this.localLanguage))
|
|
348
404
|
];
|
|
349
405
|
const maxLength = Math.max(...messages.map((m) => {
|
|
350
406
|
return m.replace(/\u001b\[[0-9]{1,2}m/g, "").length;
|
|
351
407
|
})) + 4;
|
|
352
|
-
console.log(import_chalk.default.blackBright(`${
|
|
408
|
+
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
409
|
const border = import_chalk.default.bgGreen.white(" ".repeat(maxLength));
|
|
354
410
|
console.log(border);
|
|
355
411
|
messages.forEach((msg) => {
|
|
@@ -359,67 +415,39 @@ var CoreService = class {
|
|
|
359
415
|
});
|
|
360
416
|
console.log(border);
|
|
361
417
|
console.log("\n");
|
|
362
|
-
|
|
418
|
+
const logCore = new import_opticore_logger2.LoggerCore();
|
|
419
|
+
logCore.success({
|
|
420
|
+
title: import_opticore_translator.TranslationLoader.t("serverRunningTitle", this.localLanguage),
|
|
421
|
+
message: import_opticore_translator.TranslationLoader.t("serverRunningAt", this.localLanguage, { server: msg5 })
|
|
422
|
+
});
|
|
423
|
+
SLogger(this.localLanguage).serverLog.serverLog({
|
|
363
424
|
timestamp: (/* @__PURE__ */ new Date()).toString(),
|
|
364
425
|
level: "SERVER",
|
|
365
|
-
title:
|
|
366
|
-
typeName:
|
|
367
|
-
message:
|
|
426
|
+
title: import_opticore_translator.TranslationLoader.t("serverRunningTitle", this.localLanguage),
|
|
427
|
+
typeName: import_opticore_translator.TranslationLoader.t("opticoreServerTypeName", this.localLanguage),
|
|
428
|
+
message: import_opticore_translator.TranslationLoader.t("serverRunningAt", this.localLanguage, { server: msg5 })
|
|
368
429
|
});
|
|
369
430
|
} catch (err) {
|
|
370
|
-
this.logger.error({
|
|
431
|
+
SLogger(this.localLanguage).logger.error({
|
|
371
432
|
message: err.message,
|
|
372
|
-
title:
|
|
433
|
+
title: import_opticore_translator.TranslationLoader.t("server", this.localLanguage),
|
|
373
434
|
errorType: err.code,
|
|
374
435
|
stackTrace: err.stack,
|
|
375
436
|
httpCodeValue: import_opticore_http_response.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
376
437
|
});
|
|
377
438
|
}
|
|
378
439
|
}
|
|
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
440
|
};
|
|
406
441
|
|
|
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
|
-
};
|
|
442
|
+
// src/core/helpers/dateTimeFormatted.utils.ts
|
|
443
|
+
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
444
|
|
|
418
445
|
// src/application/service/serverStartError.service.ts
|
|
446
|
+
var import_opticore_catch_exception_error2 = require("opticore-catch-exception-error");
|
|
419
447
|
var import_opticore_http_response2 = require("opticore-http-response");
|
|
420
448
|
var SServerStartError = (err, environmentPath) => {
|
|
421
449
|
if (err.name) {
|
|
422
|
-
for (const [key, code] of Object.entries(
|
|
450
|
+
for (const [key, code] of Object.entries(import_opticore_catch_exception_error2.CErrorName)) {
|
|
423
451
|
if (err.name === code) {
|
|
424
452
|
SLogger(environmentPath).logger.error({
|
|
425
453
|
message: err.message,
|
|
@@ -432,7 +460,7 @@ var SServerStartError = (err, environmentPath) => {
|
|
|
432
460
|
}
|
|
433
461
|
}
|
|
434
462
|
} else {
|
|
435
|
-
for (const [key, code] of Object.entries(
|
|
463
|
+
for (const [key, code] of Object.entries(import_opticore_catch_exception_error2.CCodeError)) {
|
|
436
464
|
if (err.code === code) {
|
|
437
465
|
SLogger(environmentPath).logger.error({
|
|
438
466
|
message: err.message,
|
|
@@ -448,119 +476,147 @@ var SServerStartError = (err, environmentPath) => {
|
|
|
448
476
|
};
|
|
449
477
|
|
|
450
478
|
// src/core/webServer.core.ts
|
|
451
|
-
var
|
|
452
|
-
var import_opticore_dependency_inject2 = require("opticore-dependency-inject");
|
|
453
|
-
var import_opticore_http_response3 = require("opticore-http-response");
|
|
454
|
-
var import_opticore_translator3 = require("opticore-translator");
|
|
479
|
+
var import_opticore_watcher = require("opticore-watcher");
|
|
455
480
|
var WebServerCore = class {
|
|
456
481
|
serverUtility;
|
|
457
|
-
expressApp = (0,
|
|
482
|
+
expressApp = (0, import_opticore_express.express)();
|
|
483
|
+
fileWatcher;
|
|
458
484
|
localLanguage;
|
|
459
485
|
loggerConfig;
|
|
460
486
|
routerExpressApp;
|
|
461
487
|
getEnvironment;
|
|
462
488
|
environmentPath;
|
|
463
489
|
serverListenEvent;
|
|
464
|
-
isHotReloading = false;
|
|
465
490
|
currentRoutes = [];
|
|
466
491
|
currentDependencies = [];
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
this.
|
|
474
|
-
this.
|
|
475
|
-
this.
|
|
476
|
-
this.
|
|
477
|
-
this.
|
|
478
|
-
this.expressApp.use(
|
|
479
|
-
this.
|
|
480
|
-
this.
|
|
481
|
-
this.
|
|
482
|
-
|
|
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
|
-
}
|
|
492
|
+
server = void 0;
|
|
493
|
+
errorEmitter;
|
|
494
|
+
isWatcherEnabled = true;
|
|
495
|
+
serverStatus = "STARTING";
|
|
496
|
+
serverStartTime = /* @__PURE__ */ new Date();
|
|
497
|
+
constructor(paramsConstructor) {
|
|
498
|
+
this.getEnvironment = (0, import_opticore_env_access2.getEnvironnementValue)(paramsConstructor.environmentPath);
|
|
499
|
+
this.routerExpressApp = paramsConstructor.app;
|
|
500
|
+
this.loggerConfig = paramsConstructor.loggerConfig;
|
|
501
|
+
this.localLanguage = paramsConstructor.localLanguage;
|
|
502
|
+
this.environmentPath = paramsConstructor.environmentPath;
|
|
503
|
+
this.expressApp.use(import_opticore_express.express.json());
|
|
504
|
+
this.expressApp.use(import_opticore_express.express.raw());
|
|
505
|
+
this.expressApp.use(import_opticore_express.express.text());
|
|
506
|
+
this.expressApp.use(import_opticore_express.express.urlencoded({ extended: true }));
|
|
507
|
+
this.expressApp.use((0, import_cors.default)(paramsConstructor.corsOriginOptions));
|
|
508
|
+
this.serverListenEvent = new import_opticore_catch_exception_error3.ServerListenEventError(paramsConstructor.localLanguage);
|
|
509
|
+
this.serverUtility = new CoreService(paramsConstructor.localLanguage, paramsConstructor.environmentPath);
|
|
499
510
|
}
|
|
500
|
-
/**
|
|
501
|
-
*
|
|
502
|
-
* @param routers
|
|
503
|
-
* @param databaseCallback
|
|
504
|
-
* @param dependenciesProvider
|
|
505
|
-
*/
|
|
506
511
|
onStartServer(routers, databaseCallback, dependenciesProvider) {
|
|
507
512
|
loaderTranslationFile(this.localLanguage);
|
|
508
513
|
this.currentRoutes = routers;
|
|
509
514
|
this.currentDependencies = dependenciesProvider || [];
|
|
510
515
|
if (this.getEnvironment.appPort === "" && Number(this.getEnvironment.appPort) === 0) {
|
|
511
516
|
this.serverListenEvent.hostPortUndefined(Number(this.getEnvironment.appPort));
|
|
512
|
-
|
|
517
|
+
return void 0;
|
|
518
|
+
}
|
|
519
|
+
if (this.getEnvironment.appHost === "") {
|
|
513
520
|
this.serverListenEvent.hostUndefined(this.getEnvironment.appHost);
|
|
514
|
-
|
|
521
|
+
return void 0;
|
|
522
|
+
}
|
|
523
|
+
if (Number(this.getEnvironment.appPort) === 0) {
|
|
515
524
|
this.serverListenEvent.portUndefined();
|
|
516
|
-
|
|
525
|
+
return void 0;
|
|
526
|
+
}
|
|
527
|
+
if (this.localLanguage === "") {
|
|
517
528
|
SLogger(this.localLanguage).logger.error({
|
|
518
|
-
message:
|
|
519
|
-
title:
|
|
520
|
-
errorType:
|
|
529
|
+
message: import_opticore_translator2.TranslationLoader.t("noDefaultLocalLang", this.localLanguage),
|
|
530
|
+
title: import_opticore_translator2.TranslationLoader.t("noLocalLang", this.localLanguage),
|
|
531
|
+
errorType: import_opticore_translator2.TranslationLoader.t("localLangMissing", this.localLanguage),
|
|
521
532
|
stackTrace: void 0,
|
|
522
533
|
httpCodeValue: import_opticore_http_response3.HttpStatusCode.NOT_FOUND
|
|
523
534
|
});
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
535
|
+
return void 0;
|
|
536
|
+
}
|
|
537
|
+
this.server = this.expressApp.listen(
|
|
538
|
+
Number(this.getEnvironment.appPort),
|
|
539
|
+
this.getEnvironment.appHost,
|
|
540
|
+
() => {
|
|
541
|
+
try {
|
|
542
|
+
if (databaseCallback && typeof databaseCallback === "function") {
|
|
530
543
|
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
544
|
}
|
|
545
|
+
new import_opticore_dependency_inject2.SContainer(this.localLanguage, this.currentDependencies);
|
|
546
|
+
this.expressApp.use(import_opticore_express.express.static(path2.join(import_node_process3.default.cwd(), "public/template")));
|
|
547
|
+
this.registerRoutes(this.currentRoutes);
|
|
548
|
+
this.setupErrorHandling();
|
|
549
|
+
this.setupServerEvents();
|
|
550
|
+
if (this.isWatcherEnabled) {
|
|
551
|
+
this.initializeFileWatcher();
|
|
552
|
+
}
|
|
553
|
+
this.infoWebApp();
|
|
554
|
+
} catch (err) {
|
|
555
|
+
SLogger(this.localLanguage).logger.error({
|
|
556
|
+
title: import_opticore_translator2.TranslationLoader.t("STARTUP_ERROR", this.localLanguage),
|
|
557
|
+
message: err.message,
|
|
558
|
+
errorType: err.code,
|
|
559
|
+
stackTrace: err.stackTrace,
|
|
560
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
561
|
+
});
|
|
562
|
+
SServerStartError(err, this.environmentPath);
|
|
537
563
|
}
|
|
538
|
-
|
|
564
|
+
}
|
|
565
|
+
);
|
|
566
|
+
return this.server;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Error handling configuration
|
|
570
|
+
*/
|
|
571
|
+
setupErrorHandling() {
|
|
572
|
+
SLogger(this.localLanguage).logger.info({
|
|
573
|
+
title: import_opticore_translator2.TranslationLoader.t("SETTING_UP", this.localLanguage),
|
|
574
|
+
message: import_opticore_translator2.TranslationLoader.t("SETTING_UP_ERROR", this.localLanguage)
|
|
575
|
+
});
|
|
576
|
+
this.errorEmitter = eventProcessHandler(this.localLanguage, this.expressApp);
|
|
577
|
+
if (this.errorEmitter) {
|
|
578
|
+
this.errorEmitter.on("transformError", (error) => {
|
|
579
|
+
SLogger(this.localLanguage).logger.error({
|
|
580
|
+
title: import_opticore_translator2.TranslationLoader.t("TRANSFORM_ERROR", this.localLanguage),
|
|
581
|
+
message: error.message,
|
|
582
|
+
errorType: error.name,
|
|
583
|
+
stackTrace: error.stackTrace,
|
|
584
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
this.errorEmitter.on("error", (error) => {
|
|
588
|
+
SLogger(this.localLanguage).logger.info({
|
|
589
|
+
title: import_opticore_translator2.TranslationLoader.t("ERROR_EMITTED", this.localLanguage),
|
|
590
|
+
message: error.message
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
this.errorEmitter.on("hotReload", (data) => {
|
|
594
|
+
SLogger(this.localLanguage).logger.info({
|
|
595
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_EVENT", this.localLanguage),
|
|
596
|
+
message: `Hot reload triggered for ${data.file}`
|
|
597
|
+
});
|
|
598
|
+
});
|
|
539
599
|
}
|
|
600
|
+
SLogger(this.localLanguage).logger.info({
|
|
601
|
+
title: import_opticore_translator2.TranslationLoader.t("ERROR_HANDLING", this.localLanguage),
|
|
602
|
+
message: import_opticore_translator2.TranslationLoader.t("ERROR_HANDLING_CONFIGURED", this.localLanguage)
|
|
603
|
+
});
|
|
540
604
|
}
|
|
541
605
|
/**
|
|
542
|
-
*
|
|
543
|
-
* @param serverWeb
|
|
606
|
+
* Setup server events
|
|
544
607
|
*/
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
608
|
+
setupServerEvents() {
|
|
609
|
+
if (!this.server) return;
|
|
610
|
+
this.server.on(import_opticore_catch_exception_error3.CEventNameError.error, (err) => {
|
|
548
611
|
this.serverListenEvent.onEventError(err);
|
|
549
|
-
})
|
|
612
|
+
});
|
|
613
|
+
this.server.on(import_opticore_catch_exception_error3.CEventNameError.close, () => {
|
|
550
614
|
this.serverListenEvent.serverClosing();
|
|
551
|
-
})
|
|
615
|
+
});
|
|
616
|
+
this.server.on(import_opticore_catch_exception_error3.CEventNameError.drop, () => {
|
|
552
617
|
this.serverListenEvent.dropNewConnection();
|
|
553
|
-
}).on(import_opticore_catch_exception_error4.CEventNameError.listening, () => {
|
|
554
|
-
this.infoWebApp();
|
|
555
618
|
});
|
|
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) => {
|
|
619
|
+
this.server.on(import_opticore_catch_exception_error3.CEventNameError.request, (req, res) => {
|
|
564
620
|
(0, import_opticore_request_call_event.requestCallsEvent)(
|
|
565
621
|
req,
|
|
566
622
|
res,
|
|
@@ -573,144 +629,643 @@ var WebServerCore = class {
|
|
|
573
629
|
});
|
|
574
630
|
}
|
|
575
631
|
/**
|
|
576
|
-
*
|
|
577
|
-
* @param allFeatureRoutes
|
|
578
|
-
* @private
|
|
632
|
+
* Initialize file watcher
|
|
579
633
|
*/
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
634
|
+
initializeFileWatcher() {
|
|
635
|
+
try {
|
|
636
|
+
this.fileWatcher = new import_opticore_watcher.WebServerWatcherService(this.localLanguage);
|
|
637
|
+
this.setupWatcherEvents();
|
|
638
|
+
this.fileWatcher.startWatching();
|
|
639
|
+
this.fileWatcher.setHotReload(true);
|
|
640
|
+
SLogger(this.localLanguage).logger.info({
|
|
641
|
+
title: import_opticore_translator2.TranslationLoader.t("WATCHER_INITIALIZED", this.localLanguage),
|
|
642
|
+
message: "File watcher has been initialized successfully"
|
|
643
|
+
});
|
|
644
|
+
} catch (error) {
|
|
645
|
+
SLogger(this.localLanguage).logger.error({
|
|
646
|
+
title: import_opticore_translator2.TranslationLoader.t("WATCHER_INIT_ERROR", this.localLanguage),
|
|
647
|
+
message: `Failed to initialize file watcher: ${error.message}`,
|
|
648
|
+
errorType: "WatcherInitializationError",
|
|
649
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Setup watcher events
|
|
655
|
+
*/
|
|
656
|
+
setupWatcherEvents() {
|
|
657
|
+
if (!this.fileWatcher) return;
|
|
658
|
+
try {
|
|
659
|
+
this.fileWatcher.on("fileChangeDetected", (data) => {
|
|
660
|
+
this.handleFileChange(data);
|
|
661
|
+
});
|
|
662
|
+
this.fileWatcher.on("hotReloadRequired", (data) => {
|
|
663
|
+
this.handleHotReload(data);
|
|
664
|
+
});
|
|
665
|
+
this.fileWatcher.on("watcherError", (error) => {
|
|
666
|
+
this.handleWatcherError(error);
|
|
667
|
+
});
|
|
668
|
+
this.fileWatcher.on("started", () => {
|
|
669
|
+
SLogger(this.localLanguage).logger.info({
|
|
670
|
+
title: import_opticore_translator2.TranslationLoader.t("WATCHER_STARTED", this.localLanguage),
|
|
671
|
+
message: import_opticore_translator2.TranslationLoader.t("FILE_WATCHER_ACTIVE", this.localLanguage)
|
|
672
|
+
});
|
|
673
|
+
});
|
|
674
|
+
this.fileWatcher.on("stopped", () => {
|
|
675
|
+
SLogger(this.localLanguage).logger.info({
|
|
676
|
+
title: import_opticore_translator2.TranslationLoader.t("WATCHER_STOPPED", this.localLanguage),
|
|
677
|
+
message: import_opticore_translator2.TranslationLoader.t("FILE_WATCHER_INACTIVE", this.localLanguage)
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
} catch (error) {
|
|
681
|
+
SLogger(this.localLanguage).logger.error({
|
|
682
|
+
title: import_opticore_translator2.TranslationLoader.t("WATCHER_EVENTS_ERROR", this.localLanguage),
|
|
683
|
+
message: `Failed to setup watcher events: ${error.message}`,
|
|
684
|
+
errorType: "WatcherEventsError",
|
|
685
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
584
686
|
});
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
/**
|
|
690
|
+
* Handle file changes detected by watcher
|
|
691
|
+
*/
|
|
692
|
+
handleFileChange(data) {
|
|
693
|
+
const { event: event2, action, requiresReload } = data;
|
|
694
|
+
SLogger(this.localLanguage).logger.info({
|
|
695
|
+
title: import_opticore_translator2.TranslationLoader.t("FILE_CHANGE_HANDLED", this.localLanguage),
|
|
696
|
+
message: import_opticore_translator2.TranslationLoader.t(
|
|
697
|
+
"PROCESSING_FILE_CHANGE",
|
|
698
|
+
this.localLanguage
|
|
699
|
+
).replace(
|
|
700
|
+
"{file}",
|
|
701
|
+
path2.basename(event2.filePath)
|
|
702
|
+
).replace(
|
|
703
|
+
"{action}",
|
|
704
|
+
action
|
|
705
|
+
)
|
|
585
706
|
});
|
|
707
|
+
if (this.errorEmitter) {
|
|
708
|
+
this.errorEmitter.emit("fileChanged", {
|
|
709
|
+
file: event2.filePath,
|
|
710
|
+
type: event2.extension,
|
|
711
|
+
action,
|
|
712
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
switch (action) {
|
|
716
|
+
case "reloadEnvironment":
|
|
717
|
+
this.reloadEnvironmentConfig();
|
|
718
|
+
break;
|
|
719
|
+
case "reloadConfig":
|
|
720
|
+
this.reloadConfigurationFiles();
|
|
721
|
+
break;
|
|
722
|
+
case "reloadRoutes":
|
|
723
|
+
this.reloadApplicationRoutes(event2.filePath);
|
|
724
|
+
break;
|
|
725
|
+
case "reloadDependencies":
|
|
726
|
+
this.reloadDependencies();
|
|
727
|
+
break;
|
|
728
|
+
case "notifyOnly":
|
|
729
|
+
this.notifyFileChange(event2);
|
|
730
|
+
break;
|
|
731
|
+
}
|
|
586
732
|
}
|
|
587
733
|
/**
|
|
588
|
-
*
|
|
589
|
-
* @param localLanguage
|
|
590
|
-
* @private
|
|
734
|
+
* Handle hot reload requested by watcher
|
|
591
735
|
*/
|
|
592
|
-
|
|
593
|
-
|
|
736
|
+
handleHotReload(data) {
|
|
737
|
+
const { file, type, action } = data;
|
|
738
|
+
SLogger(this.localLanguage).logger.info({
|
|
739
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_STARTING", this.localLanguage),
|
|
740
|
+
message: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_FOR_FILE", this.localLanguage).replace("{file}", path2.basename(file)).replace("{type}", type)
|
|
741
|
+
});
|
|
742
|
+
if (this.errorEmitter) {
|
|
743
|
+
this.errorEmitter.emit("hotReload", {
|
|
744
|
+
file,
|
|
745
|
+
type,
|
|
746
|
+
action,
|
|
747
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
switch (action) {
|
|
751
|
+
case "reloadEnvironment":
|
|
752
|
+
this.executeHotReloadEnvironment(file);
|
|
753
|
+
break;
|
|
754
|
+
case "reloadConfig":
|
|
755
|
+
this.executeHotReloadConfig(file);
|
|
756
|
+
break;
|
|
757
|
+
case "reloadRoutes":
|
|
758
|
+
this.executeHotReloadRoutes(file);
|
|
759
|
+
break;
|
|
760
|
+
case "reloadDependencies":
|
|
761
|
+
this.executeHotReloadDependencies(file);
|
|
762
|
+
break;
|
|
763
|
+
}
|
|
594
764
|
}
|
|
595
765
|
/**
|
|
596
|
-
*
|
|
597
|
-
* @private
|
|
766
|
+
* Handle watcher errors
|
|
598
767
|
*/
|
|
599
|
-
|
|
600
|
-
this.
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
768
|
+
handleWatcherError(error) {
|
|
769
|
+
SLogger(this.localLanguage).logger.error({
|
|
770
|
+
title: import_opticore_translator2.TranslationLoader.t("WATCHER_SYSTEM_ERROR", this.localLanguage),
|
|
771
|
+
message: error.message || "Unknown watcher system error",
|
|
772
|
+
errorType: "WatcherSystemError",
|
|
773
|
+
stackTrace: error.stack,
|
|
774
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
775
|
+
});
|
|
604
776
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
console.log(`${dateTimeFormattedUtils} | [Server] Hot reload completed successfully`);
|
|
613
|
-
} catch (error) {
|
|
614
|
-
console.error(`${dateTimeFormattedUtils} | [Server] Hot reload failed:`, error);
|
|
615
|
-
this.serverListenEvent.onEventError(error);
|
|
616
|
-
} finally {
|
|
617
|
-
this.isHotReloading = false;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
777
|
+
/**
|
|
778
|
+
* Notify file change without action
|
|
779
|
+
*/
|
|
780
|
+
notifyFileChange(event2) {
|
|
781
|
+
SLogger(this.localLanguage).logger.info({
|
|
782
|
+
title: import_opticore_translator2.TranslationLoader.t("FILE_CHANGE_NOTIFIED", this.localLanguage),
|
|
783
|
+
message: import_opticore_translator2.TranslationLoader.t("FILE_CHANGE_NO_ACTION", this.localLanguage).replace("{file}", path2.basename(event2.filePath))
|
|
620
784
|
});
|
|
621
785
|
}
|
|
622
786
|
/**
|
|
623
|
-
*
|
|
787
|
+
* Reload environment configuration
|
|
624
788
|
*/
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
789
|
+
reloadEnvironmentConfig() {
|
|
790
|
+
try {
|
|
791
|
+
this.reloadConfigurations();
|
|
792
|
+
SLogger(this.localLanguage).logger.info({
|
|
793
|
+
title: import_opticore_translator2.TranslationLoader.t("ENV_RELOADED", this.localLanguage),
|
|
794
|
+
message: import_opticore_translator2.TranslationLoader.t("ENVIRONMENT_RELOADED_SUCCESS", this.localLanguage)
|
|
795
|
+
});
|
|
796
|
+
this.notifyEnvironmentReload();
|
|
797
|
+
} catch (error) {
|
|
798
|
+
SLogger(this.localLanguage).logger.error({
|
|
799
|
+
title: import_opticore_translator2.TranslationLoader.t("ENV_RELOAD_FAILED", this.localLanguage),
|
|
800
|
+
message: error.message,
|
|
801
|
+
errorType: "EnvironmentReloadError",
|
|
802
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
/**
|
|
807
|
+
* Execute hot reload for environment files
|
|
808
|
+
*/
|
|
809
|
+
executeHotReloadEnvironment(filePath) {
|
|
810
|
+
try {
|
|
811
|
+
const newEnv = (0, import_opticore_env_access2.getEnvironnementValue)(this.environmentPath);
|
|
812
|
+
Object.keys(newEnv).forEach((key) => {
|
|
813
|
+
this.getEnvironment[key] = newEnv[key];
|
|
814
|
+
});
|
|
815
|
+
loaderTranslationFile(this.localLanguage);
|
|
816
|
+
SLogger(this.localLanguage).logger.info({
|
|
817
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_ENV_SUCCESS", this.localLanguage),
|
|
818
|
+
message: import_opticore_translator2.TranslationLoader.t("ENV_HOT_RELOAD_COMPLETE", this.localLanguage).replace("{file}", path2.basename(filePath))
|
|
819
|
+
});
|
|
820
|
+
} catch (error) {
|
|
821
|
+
SLogger(this.localLanguage).logger.error({
|
|
822
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_ENV_FAILED", this.localLanguage),
|
|
823
|
+
message: error.message,
|
|
824
|
+
errorType: "HotReloadEnvironmentError",
|
|
825
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Reload configuration files
|
|
831
|
+
*/
|
|
832
|
+
reloadConfigurationFiles() {
|
|
833
|
+
try {
|
|
834
|
+
loaderTranslationFile(this.localLanguage);
|
|
835
|
+
SLogger(this.localLanguage).logger.info({
|
|
836
|
+
title: import_opticore_translator2.TranslationLoader.t("CONFIG_RELOADED", this.localLanguage),
|
|
837
|
+
message: import_opticore_translator2.TranslationLoader.t("CONFIGURATION_RELOADED_SUCCESS", this.localLanguage)
|
|
838
|
+
});
|
|
839
|
+
} catch (error) {
|
|
840
|
+
SLogger(this.localLanguage).logger.error({
|
|
841
|
+
title: import_opticore_translator2.TranslationLoader.t("CONFIG_RELOAD_FAILED", this.localLanguage),
|
|
842
|
+
message: error.message,
|
|
843
|
+
errorType: "ConfigurationReloadError",
|
|
844
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
/**
|
|
849
|
+
* Execute hot reload for config files
|
|
850
|
+
*/
|
|
851
|
+
executeHotReloadConfig(filePath) {
|
|
631
852
|
try {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
853
|
+
if (filePath.includes("locales") || filePath.includes("translations")) {
|
|
854
|
+
loaderTranslationFile(this.localLanguage);
|
|
855
|
+
SLogger(this.localLanguage).logger.info({
|
|
856
|
+
title: import_opticore_translator2.TranslationLoader.t("TRANSLATIONS_RELOADED", this.localLanguage),
|
|
857
|
+
message: import_opticore_translator2.TranslationLoader.t("TRANSLATIONS_HOT_RELOAD_COMPLETE", this.localLanguage).replace("{file}", path2.basename(filePath))
|
|
858
|
+
});
|
|
859
|
+
}
|
|
637
860
|
} catch (error) {
|
|
638
|
-
|
|
639
|
-
|
|
861
|
+
SLogger(this.localLanguage).logger.error({
|
|
862
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_CONFIG_FAILED", this.localLanguage),
|
|
863
|
+
message: error.message,
|
|
864
|
+
errorType: "HotReloadConfigError",
|
|
865
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
866
|
+
});
|
|
640
867
|
}
|
|
641
868
|
}
|
|
642
869
|
/**
|
|
643
|
-
*
|
|
870
|
+
* Reload application routes
|
|
644
871
|
*/
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
872
|
+
reloadApplicationRoutes(filePath) {
|
|
873
|
+
try {
|
|
874
|
+
SLogger(this.localLanguage).logger.info({
|
|
875
|
+
title: import_opticore_translator2.TranslationLoader.t("ROUTES_RELOADING", this.localLanguage),
|
|
876
|
+
message: import_opticore_translator2.TranslationLoader.t("APPLICATION_ROUTES_RELOADING", this.localLanguage).replace("{file}", path2.basename(filePath))
|
|
877
|
+
});
|
|
878
|
+
if (filePath.includes("routes") || filePath.includes("controller")) {
|
|
879
|
+
this.reloadSpecificRoute(filePath);
|
|
880
|
+
}
|
|
881
|
+
if (this.errorEmitter) {
|
|
882
|
+
this.errorEmitter.emit("routesReloaded", {
|
|
883
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
884
|
+
file: filePath,
|
|
885
|
+
routesCount: this.currentRoutes.length
|
|
886
|
+
});
|
|
655
887
|
}
|
|
888
|
+
} catch (error) {
|
|
889
|
+
SLogger(this.localLanguage).logger.error({
|
|
890
|
+
title: import_opticore_translator2.TranslationLoader.t("ROUTES_RELOAD_FAILED", this.localLanguage),
|
|
891
|
+
message: error.message,
|
|
892
|
+
errorType: "RoutesReloadError",
|
|
893
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
894
|
+
});
|
|
656
895
|
}
|
|
657
|
-
console.log(`${dateTimeFormattedUtils} | [Server] Cleared ${context.clearedModules.length} modules from cache`);
|
|
658
896
|
}
|
|
659
897
|
/**
|
|
660
|
-
*
|
|
898
|
+
* Execute hot reload for routes
|
|
661
899
|
*/
|
|
662
|
-
|
|
900
|
+
executeHotReloadRoutes(filePath) {
|
|
901
|
+
try {
|
|
902
|
+
SLogger(this.localLanguage).logger.info({
|
|
903
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_ROUTES_START", this.localLanguage),
|
|
904
|
+
message: import_opticore_translator2.TranslationLoader.t("ROUTES_HOT_RELOADING", this.localLanguage).replace("{file}", path2.basename(filePath))
|
|
905
|
+
});
|
|
906
|
+
this.reloadRouterForFile(filePath);
|
|
907
|
+
SLogger(this.localLanguage).logger.info({
|
|
908
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_ROUTES_SUCCESS", this.localLanguage),
|
|
909
|
+
message: import_opticore_translator2.TranslationLoader.t("ROUTES_HOT_RELOAD_COMPLETE", this.localLanguage)
|
|
910
|
+
});
|
|
911
|
+
} catch (error) {
|
|
912
|
+
SLogger(this.localLanguage).logger.error({
|
|
913
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_ROUTES_FAILED", this.localLanguage),
|
|
914
|
+
message: error.message,
|
|
915
|
+
errorType: "HotReloadRoutesError",
|
|
916
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Execute hot reload for dependencies
|
|
922
|
+
*/
|
|
923
|
+
executeHotReloadDependencies(filePath) {
|
|
924
|
+
try {
|
|
925
|
+
SLogger(this.localLanguage).logger.info({
|
|
926
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_DEPS_START", this.localLanguage),
|
|
927
|
+
message: import_opticore_translator2.TranslationLoader.t(
|
|
928
|
+
"DEPENDENCIES_HOT_RELOADING",
|
|
929
|
+
this.localLanguage
|
|
930
|
+
).replace("{file}", path2.basename(filePath))
|
|
931
|
+
});
|
|
932
|
+
this.reloadDependencies();
|
|
933
|
+
SLogger(this.localLanguage).logger.info({
|
|
934
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_DEPS_SUCCESS", this.localLanguage),
|
|
935
|
+
message: import_opticore_translator2.TranslationLoader.t("DEPENDENCIES_HOT_RELOAD_COMPLETE", this.localLanguage)
|
|
936
|
+
});
|
|
937
|
+
} catch (error) {
|
|
938
|
+
SLogger(this.localLanguage).logger.error({
|
|
939
|
+
title: import_opticore_translator2.TranslationLoader.t("HOT_RELOAD_DEPS_FAILED", this.localLanguage),
|
|
940
|
+
message: error.message,
|
|
941
|
+
errorType: "HotReloadDependenciesError",
|
|
942
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Notify environment reload
|
|
948
|
+
*/
|
|
949
|
+
notifyEnvironmentReload() {
|
|
950
|
+
if (this.errorEmitter) {
|
|
951
|
+
this.errorEmitter.emit("environmentReloaded", {
|
|
952
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
953
|
+
environment: this.getEnvironment
|
|
954
|
+
});
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
/**
|
|
958
|
+
* Reload specific route
|
|
959
|
+
*/
|
|
960
|
+
reloadSpecificRoute(filePath) {
|
|
961
|
+
SLogger(this.localLanguage).logger.info({
|
|
962
|
+
title: "Route Reload",
|
|
963
|
+
message: `Reloading route from: ${filePath}`
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* Reload router for specific file
|
|
968
|
+
*/
|
|
969
|
+
reloadRouterForFile(filePath) {
|
|
970
|
+
SLogger(this.localLanguage).logger.info({
|
|
971
|
+
title: "Router Reload",
|
|
972
|
+
message: `Reloading router for file: ${filePath}`
|
|
973
|
+
});
|
|
974
|
+
}
|
|
975
|
+
/**
|
|
976
|
+
* Reload configurations
|
|
977
|
+
*/
|
|
978
|
+
reloadConfigurations() {
|
|
663
979
|
try {
|
|
664
980
|
const newEnv = (0, import_opticore_env_access2.getEnvironnementValue)(this.environmentPath);
|
|
665
|
-
Object.
|
|
981
|
+
Object.keys(newEnv).forEach((key) => {
|
|
982
|
+
this.getEnvironment[key] = newEnv[key];
|
|
983
|
+
});
|
|
666
984
|
loaderTranslationFile(this.localLanguage);
|
|
667
|
-
console.log(`${dateTimeFormattedUtils} | [Server] Configurations reloaded`);
|
|
668
985
|
} catch (error) {
|
|
669
|
-
|
|
986
|
+
throw new Error(`Configuration reload failed: ${error.message}`);
|
|
670
987
|
}
|
|
671
988
|
}
|
|
672
989
|
/**
|
|
673
|
-
*
|
|
990
|
+
* Reload dependencies
|
|
674
991
|
*/
|
|
675
|
-
|
|
992
|
+
reloadDependencies() {
|
|
676
993
|
try {
|
|
677
994
|
new import_opticore_dependency_inject2.SContainer(this.localLanguage, this.currentDependencies);
|
|
678
|
-
|
|
995
|
+
const container = dependenciesContainerProvider(this.localLanguage);
|
|
996
|
+
if (!container) {
|
|
997
|
+
throw new Error("Dependency container is not available");
|
|
998
|
+
}
|
|
679
999
|
} catch (error) {
|
|
680
|
-
|
|
1000
|
+
throw new Error(`Dependency reload failed: ${error.message}`);
|
|
681
1001
|
}
|
|
682
1002
|
}
|
|
683
1003
|
/**
|
|
684
|
-
*
|
|
1004
|
+
* Register routes
|
|
685
1005
|
*/
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
1006
|
+
registerRoutes(allFeatureRoutes) {
|
|
1007
|
+
allFeatureRoutes.forEach((router) => {
|
|
1008
|
+
if (router.routes) {
|
|
1009
|
+
router.routes.forEach((route) => {
|
|
1010
|
+
this.expressApp.use(route.path, route.handler);
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
/**
|
|
1016
|
+
* Parse transform error
|
|
1017
|
+
*/
|
|
1018
|
+
parseTransformError(error) {
|
|
1019
|
+
const errorMessage = error.message || String(error);
|
|
1020
|
+
let tool = "Unknown";
|
|
1021
|
+
if (errorMessage.includes("esbuild")) tool = "esbuild";
|
|
1022
|
+
if (errorMessage.includes("webpack")) tool = "webpack";
|
|
1023
|
+
const fileMatch = errorMessage.match(/([^:\s]+\.(?:ts|js|tsx|jsx)):(\d+):(\d+):/);
|
|
1024
|
+
const file = fileMatch ? fileMatch[1] : null;
|
|
1025
|
+
const line = fileMatch ? parseInt(fileMatch[2], 10) : null;
|
|
1026
|
+
const column = fileMatch ? parseInt(fileMatch[3], 10) : null;
|
|
1027
|
+
const errorDetailMatch = errorMessage.match(/ERROR:\s*(.+?)(?:\n|$)/);
|
|
1028
|
+
const errorDetail = errorDetailMatch ? errorDetailMatch[1].trim() : null;
|
|
1029
|
+
return {
|
|
1030
|
+
message: errorMessage,
|
|
1031
|
+
file,
|
|
1032
|
+
line,
|
|
1033
|
+
column,
|
|
1034
|
+
errorDetail,
|
|
1035
|
+
tool
|
|
1036
|
+
};
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Display server info
|
|
1040
|
+
*/
|
|
1041
|
+
infoWebApp() {
|
|
1042
|
+
this.serverUtility.infoServer(
|
|
1043
|
+
this.getEnvironment.appHost,
|
|
1044
|
+
Number(this.getEnvironment.appPort)
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Stop file watcher
|
|
1049
|
+
*/
|
|
1050
|
+
stopFileWatcher() {
|
|
1051
|
+
if (this.fileWatcher) {
|
|
1052
|
+
try {
|
|
1053
|
+
this.fileWatcher.stopWatching();
|
|
1054
|
+
SLogger(this.localLanguage).logger.info({
|
|
1055
|
+
title: import_opticore_translator2.TranslationLoader.t("WATCHER_STOPPED", this.localLanguage),
|
|
1056
|
+
message: import_opticore_translator2.TranslationLoader.t("FILE_WATCHER_STOPPED_GRACEFULLY", this.localLanguage)
|
|
1057
|
+
});
|
|
1058
|
+
} catch (error) {
|
|
1059
|
+
SLogger(this.localLanguage).logger.error({
|
|
1060
|
+
title: import_opticore_translator2.TranslationLoader.t("WATCHER_STOP_ERROR", this.localLanguage),
|
|
1061
|
+
message: `Error stopping watcher: ${error.message}`,
|
|
1062
|
+
errorType: "WatcherStopError",
|
|
1063
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
1064
|
+
});
|
|
1065
|
+
} finally {
|
|
1066
|
+
this.fileWatcher = void 0;
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
/**
|
|
1071
|
+
* Shutdown server
|
|
1072
|
+
*/
|
|
1073
|
+
shutdown() {
|
|
1074
|
+
this.stopFileWatcher();
|
|
1075
|
+
if (this.server) {
|
|
1076
|
+
this.server.close(() => {
|
|
1077
|
+
SLogger(this.localLanguage).logger.info({
|
|
1078
|
+
title: import_opticore_translator2.TranslationLoader.t("CLOSED", this.localLanguage),
|
|
1079
|
+
message: import_opticore_translator2.TranslationLoader.t("SERVER_CLOSED", this.localLanguage)
|
|
1080
|
+
});
|
|
1081
|
+
import_node_process3.default.exit(0);
|
|
690
1082
|
});
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
console.error(`${dateTimeFormattedUtils} | [Server] Routes reload error:`, error.message);
|
|
701
|
-
throw error;
|
|
1083
|
+
setTimeout(() => {
|
|
1084
|
+
SLogger(this.localLanguage).logger.error({
|
|
1085
|
+
title: import_opticore_translator2.TranslationLoader.t("FORCE_SHUTDOWN", this.localLanguage),
|
|
1086
|
+
message: import_opticore_translator2.TranslationLoader.t("SERVER_FORCE_SHUTDOWN", this.localLanguage)
|
|
1087
|
+
});
|
|
1088
|
+
import_node_process3.default.exit(1);
|
|
1089
|
+
}, 5e3);
|
|
1090
|
+
} else {
|
|
1091
|
+
import_node_process3.default.exit(0);
|
|
702
1092
|
}
|
|
703
1093
|
}
|
|
704
1094
|
/**
|
|
705
|
-
*
|
|
1095
|
+
* Enable/disable watcher
|
|
1096
|
+
*/
|
|
1097
|
+
setWatcherEnabled(enabled) {
|
|
1098
|
+
this.isWatcherEnabled = enabled;
|
|
1099
|
+
if (enabled && !this.fileWatcher) {
|
|
1100
|
+
this.initializeFileWatcher();
|
|
1101
|
+
} else if (!enabled && this.fileWatcher) {
|
|
1102
|
+
this.stopFileWatcher();
|
|
1103
|
+
}
|
|
1104
|
+
SLogger(this.localLanguage).logger.info({
|
|
1105
|
+
title: "Watcher Status",
|
|
1106
|
+
message: `File watcher ${enabled ? "enabled" : "disabled"}`
|
|
1107
|
+
});
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Get watcher status
|
|
706
1111
|
*/
|
|
707
|
-
|
|
1112
|
+
getWatcherStatus() {
|
|
1113
|
+
return {
|
|
1114
|
+
enabled: this.isWatcherEnabled,
|
|
1115
|
+
active: this.fileWatcher !== void 0
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
/**
|
|
1119
|
+
* Get server state information
|
|
1120
|
+
*/
|
|
1121
|
+
getServerState() {
|
|
1122
|
+
const now = /* @__PURE__ */ new Date();
|
|
1123
|
+
const uptime = this.serverStartTime ? now.getTime() - this.serverStartTime.getTime() : 0;
|
|
1124
|
+
const formatUptime = (ms) => {
|
|
1125
|
+
const seconds = Math.floor(ms / 1e3);
|
|
1126
|
+
const minutes = Math.floor(seconds / 60);
|
|
1127
|
+
const hours = Math.floor(minutes / 60);
|
|
1128
|
+
const days = Math.floor(hours / 24);
|
|
1129
|
+
if (days > 0) return `${days}j ${hours % 24}h ${minutes % 60}m`;
|
|
1130
|
+
if (hours > 0) return `${hours}h ${minutes % 60}m ${seconds % 60}s`;
|
|
1131
|
+
if (minutes > 0) return `${minutes}m ${seconds % 60}s`;
|
|
1132
|
+
return `${seconds}s`;
|
|
1133
|
+
};
|
|
1134
|
+
const memory = import_node_process3.default.memoryUsage();
|
|
1135
|
+
return {
|
|
1136
|
+
status: this.serverStatus,
|
|
1137
|
+
isRunning: this.server !== void 0,
|
|
1138
|
+
host: this.getEnvironment.appHost,
|
|
1139
|
+
port: Number(this.getEnvironment.appPort),
|
|
1140
|
+
language: this.localLanguage,
|
|
1141
|
+
watcherEnabled: this.isWatcherEnabled,
|
|
1142
|
+
watcherActive: this.fileWatcher !== void 0,
|
|
1143
|
+
routesCount: this.currentRoutes.length,
|
|
1144
|
+
dependenciesCount: this.currentDependencies.length,
|
|
1145
|
+
startTime: this.serverStartTime,
|
|
1146
|
+
currentTime: now,
|
|
1147
|
+
uptime,
|
|
1148
|
+
uptimeFormatted: formatUptime(uptime),
|
|
1149
|
+
memoryUsage: {
|
|
1150
|
+
rss: memory.rss,
|
|
1151
|
+
heapTotal: memory.heapTotal,
|
|
1152
|
+
heapUsed: memory.heapUsed,
|
|
1153
|
+
external: memory.external,
|
|
1154
|
+
arrayBuffers: memory.arrayBuffers
|
|
1155
|
+
},
|
|
1156
|
+
pid: import_node_process3.default.pid,
|
|
1157
|
+
platform: import_node_process3.default.platform,
|
|
1158
|
+
nodeVersion: import_node_process3.default.version,
|
|
1159
|
+
cwd: import_node_process3.default.cwd()
|
|
1160
|
+
};
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Simple method to get just the status
|
|
1164
|
+
*/
|
|
1165
|
+
getServerStatus() {
|
|
1166
|
+
return this.serverStatus;
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Get server statistics for monitoring
|
|
1170
|
+
*/
|
|
1171
|
+
getServerStats() {
|
|
1172
|
+
const uptime = this.serverStartTime ? Date.now() - this.serverStartTime.getTime() : 0;
|
|
1173
|
+
const memory = import_node_process3.default.memoryUsage();
|
|
1174
|
+
return {
|
|
1175
|
+
status: this.serverStatus,
|
|
1176
|
+
uptime: this.formatUptime(uptime),
|
|
1177
|
+
memory: {
|
|
1178
|
+
rss: this.formatBytes(memory.rss),
|
|
1179
|
+
heapTotal: this.formatBytes(memory.heapTotal),
|
|
1180
|
+
heapUsed: this.formatBytes(memory.heapUsed),
|
|
1181
|
+
external: this.formatBytes(memory.external)
|
|
1182
|
+
},
|
|
1183
|
+
performance: {
|
|
1184
|
+
cpuUsage: import_node_process3.default.cpuUsage(),
|
|
1185
|
+
resourceUsage: import_node_process3.default.resourceUsage?.()
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Format bytes to human readable string
|
|
1191
|
+
*/
|
|
1192
|
+
formatBytes(bytes) {
|
|
1193
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
1194
|
+
let value = bytes;
|
|
1195
|
+
let unitIndex = 0;
|
|
1196
|
+
while (value >= 1024 && unitIndex < units.length - 1) {
|
|
1197
|
+
value /= 1024;
|
|
1198
|
+
unitIndex++;
|
|
1199
|
+
}
|
|
1200
|
+
return `${value.toFixed(2)} ${units[unitIndex]}`;
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Format uptime to human readable string
|
|
1204
|
+
*/
|
|
1205
|
+
formatUptime(ms) {
|
|
1206
|
+
const seconds = Math.floor(ms / 1e3);
|
|
1207
|
+
const minutes = Math.floor(seconds / 60);
|
|
1208
|
+
const hours = Math.floor(minutes / 60);
|
|
1209
|
+
const days = Math.floor(hours / 24);
|
|
1210
|
+
if (days > 0) {
|
|
1211
|
+
return `${days}j ${hours % 24}h ${minutes % 60}m`;
|
|
1212
|
+
} else if (hours > 0) {
|
|
1213
|
+
return `${hours}h ${minutes % 60}m ${seconds % 60}s`;
|
|
1214
|
+
} else if (minutes > 0) {
|
|
1215
|
+
return `${minutes}m ${seconds % 60}s`;
|
|
1216
|
+
} else {
|
|
1217
|
+
return `${seconds}s`;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
/**
|
|
1221
|
+
* Add watch directories
|
|
1222
|
+
*/
|
|
1223
|
+
addWatchDirectories(directories) {
|
|
1224
|
+
if (this.fileWatcher) {
|
|
1225
|
+
this.fileWatcher.addWatchDirectories(directories);
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Clear file cache
|
|
1230
|
+
*/
|
|
1231
|
+
clearFileCache() {
|
|
1232
|
+
if (this.fileWatcher) {
|
|
1233
|
+
this.fileWatcher.clearFileCache();
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Force reload configurations
|
|
1238
|
+
*/
|
|
1239
|
+
forceReloadConfig() {
|
|
708
1240
|
try {
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
1241
|
+
this.reloadConfigurations();
|
|
1242
|
+
this.reloadDependencies();
|
|
1243
|
+
SLogger(this.localLanguage).logger.info({
|
|
1244
|
+
title: "Force Reload",
|
|
1245
|
+
message: "All configurations and dependencies have been reloaded"
|
|
1246
|
+
});
|
|
712
1247
|
} catch (error) {
|
|
713
|
-
|
|
1248
|
+
SLogger(this.localLanguage).logger.error({
|
|
1249
|
+
title: "Force Reload Failed",
|
|
1250
|
+
message: error.message,
|
|
1251
|
+
errorType: "ForceReloadError",
|
|
1252
|
+
httpCodeValue: import_opticore_http_response3.HttpStatusCode.INTERNAL_SERVER_ERROR
|
|
1253
|
+
});
|
|
1254
|
+
}
|
|
1255
|
+
}
|
|
1256
|
+
/**
|
|
1257
|
+
* Restart watcher
|
|
1258
|
+
*/
|
|
1259
|
+
restartWatcher() {
|
|
1260
|
+
this.stopFileWatcher();
|
|
1261
|
+
if (this.isWatcherEnabled) {
|
|
1262
|
+
setTimeout(() => {
|
|
1263
|
+
this.initializeFileWatcher();
|
|
1264
|
+
SLogger(this.localLanguage).logger.info({
|
|
1265
|
+
title: "Watcher Restarted",
|
|
1266
|
+
message: "File watcher has been restarted successfully"
|
|
1267
|
+
});
|
|
1268
|
+
}, 1e3);
|
|
714
1269
|
}
|
|
715
1270
|
}
|
|
716
1271
|
};
|