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