opticore-webapp 1.0.68 → 1.0.70
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 +161 -892
- package/dist/index.d.cts +20 -185
- package/dist/index.d.ts +20 -185
- package/dist/index.js +164 -899
- package/dist/utils/translations/message.translation.en.json +24 -3
- package/dist/utils/translations/message.translation.fr.json +3 -3
- package/package.json +8 -9
package/dist/index.js
CHANGED
|
@@ -3,109 +3,24 @@ import * as path2 from "path";
|
|
|
3
3
|
import process4 from "process";
|
|
4
4
|
import corsOrigin from "cors";
|
|
5
5
|
import { CEventNameError as eventName2, ServerListenEventError as ServerListenEventError2 } from "opticore-catch-exception-error";
|
|
6
|
-
import { express } from "opticore-express";
|
|
7
|
-
import {
|
|
8
|
-
import { requestCallsEvent } from "opticore-request-call-event";
|
|
9
|
-
import { SContainer as SContainer2 } from "opticore-dependency-inject";
|
|
6
|
+
import { express as express2 } from "opticore-express";
|
|
7
|
+
import { getEnvironmentValue as getEnvironmentValue2 } from "opticore-env-access";
|
|
10
8
|
import { HttpStatusCode as HttpStatusCode3 } from "opticore-http-response";
|
|
11
9
|
import { TranslationLoader as TranslationLoader2 } from "opticore-translator";
|
|
10
|
+
import { requestCallsEvent } from "opticore-request-call-event";
|
|
12
11
|
|
|
13
12
|
// src/core/handlers/eventProcess.handler.ts
|
|
14
13
|
import process from "process";
|
|
15
14
|
import EventEmitter from "events";
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
CEvent as event
|
|
20
|
-
} from "opticore-catch-exception-error";
|
|
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) {
|
|
15
|
+
import { express } from "opticore-express";
|
|
16
|
+
import { ServerListenEventError, CEventNameError as eventName, CEvent as event } from "opticore-catch-exception-error";
|
|
17
|
+
function eventProcessHandler(localeLanguage) {
|
|
29
18
|
const errorEmitter = new EventEmitter();
|
|
19
|
+
const app = express();
|
|
30
20
|
const serverListenEvent = new ServerListenEventError(localeLanguage);
|
|
31
|
-
console.log("[Server] Setting up error event handlers...");
|
|
32
21
|
errorEmitter.on(eventName.error, (error) => {
|
|
33
|
-
console.error("[Server] EventEmitter error caught:", error.message);
|
|
34
|
-
if (isTransformErrorUtils(error)) {
|
|
35
|
-
handleTransformError(error);
|
|
36
|
-
}
|
|
37
22
|
serverListenEvent.listenerError(error);
|
|
38
23
|
});
|
|
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
|
-
});
|
|
109
24
|
process.on(event.beforeExit, (code) => {
|
|
110
25
|
setTimeout(() => {
|
|
111
26
|
serverListenEvent.processBeforeExit(code);
|
|
@@ -120,20 +35,20 @@ function eventProcessHandler(localeLanguage, expressApp) {
|
|
|
120
35
|
process.on(event.rejectionHandled, (promise) => {
|
|
121
36
|
serverListenEvent.promiseRejectionHandled(promise);
|
|
122
37
|
});
|
|
38
|
+
process.on(event.uncaughtException, (error) => {
|
|
39
|
+
serverListenEvent.uncaughtException(error);
|
|
40
|
+
});
|
|
123
41
|
process.on(event.uncaughtExceptionMonitor, (error) => {
|
|
124
|
-
console.error("[Server] UNCAUGHT EXCEPTION MONITOR:", error.message);
|
|
125
|
-
if (isTransformErrorUtils(error)) {
|
|
126
|
-
errorEmitter.emit("transformError", error);
|
|
127
|
-
}
|
|
128
42
|
serverListenEvent.uncaughtExceptionMonitor(error);
|
|
129
43
|
});
|
|
44
|
+
process.on(event.unhandledRejection, (reason, promise) => {
|
|
45
|
+
serverListenEvent.unhandledRejection(reason, promise);
|
|
46
|
+
});
|
|
130
47
|
process.on(event.warning, (warning) => {
|
|
131
48
|
serverListenEvent.warning(warning);
|
|
132
49
|
});
|
|
133
50
|
process.on(event.message, (message) => {
|
|
134
|
-
|
|
135
|
-
serverListenEvent.message(message);
|
|
136
|
-
}
|
|
51
|
+
serverListenEvent.message(message);
|
|
137
52
|
});
|
|
138
53
|
process.on(event.multipleResolves, (type, promise, reason) => {
|
|
139
54
|
serverListenEvent.multipleResolves(type, promise, reason);
|
|
@@ -144,15 +59,9 @@ function eventProcessHandler(localeLanguage, expressApp) {
|
|
|
144
59
|
process.on(event.sigterm, (signal) => {
|
|
145
60
|
serverListenEvent.sigtermSignalReceived(signal);
|
|
146
61
|
});
|
|
147
|
-
|
|
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);
|
|
62
|
+
app.use((err, req, res, next) => {
|
|
152
63
|
serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
153
64
|
});
|
|
154
|
-
console.log("[Server] Error event handlers configured successfully");
|
|
155
|
-
return errorEmitter;
|
|
156
65
|
}
|
|
157
66
|
|
|
158
67
|
// src/application/service/core.service.ts
|
|
@@ -163,7 +72,7 @@ import * as fs from "fs";
|
|
|
163
72
|
import colors from "ansi-colors";
|
|
164
73
|
import { HttpStatusCode, HttpStatusCode as status } from "opticore-http-response";
|
|
165
74
|
import { TranslationLoader } from "opticore-translator";
|
|
166
|
-
import {
|
|
75
|
+
import { getEnvironmentValue } from "opticore-env-access";
|
|
167
76
|
|
|
168
77
|
// src/utils/envPath.utils.ts
|
|
169
78
|
import process2 from "process";
|
|
@@ -203,21 +112,6 @@ var dependenciesContainerProvider = (localLang) => {
|
|
|
203
112
|
return new SContainer(localLang, dependencies);
|
|
204
113
|
};
|
|
205
114
|
|
|
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
|
-
|
|
221
115
|
// src/application/service/core.service.ts
|
|
222
116
|
var CoreService = class {
|
|
223
117
|
localLanguage;
|
|
@@ -225,9 +119,9 @@ var CoreService = class {
|
|
|
225
119
|
serverLog;
|
|
226
120
|
logger;
|
|
227
121
|
constructor(localLang, environmentPath) {
|
|
122
|
+
this.loadTranslationFiles();
|
|
228
123
|
this.environmentPath = environmentPath;
|
|
229
124
|
this.localLanguage = localLang;
|
|
230
|
-
loaderTranslationFile(this.localLanguage);
|
|
231
125
|
this.serverLog = dependenciesContainerProvider(localLang).resolve("OpticoreLogger");
|
|
232
126
|
this.logger = dependenciesContainerProvider(localLang).resolve("LoggerCore");
|
|
233
127
|
}
|
|
@@ -241,6 +135,41 @@ var CoreService = class {
|
|
|
241
135
|
formatMemoryUsage(data) {
|
|
242
136
|
return `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
|
|
243
137
|
}
|
|
138
|
+
loadTranslationFiles() {
|
|
139
|
+
loaderTranslationFile(this.localLanguage);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
*
|
|
143
|
+
* @param filePath
|
|
144
|
+
* @private
|
|
145
|
+
*
|
|
146
|
+
* Return void
|
|
147
|
+
*/
|
|
148
|
+
getEnvFileLoading(filePath) {
|
|
149
|
+
this.loadTranslationFiles();
|
|
150
|
+
try {
|
|
151
|
+
const fullPath = path.resolve(process3.cwd(), filePath);
|
|
152
|
+
if (fs.existsSync(fullPath)) {
|
|
153
|
+
const env = fs.readFileSync(fullPath, "utf-8");
|
|
154
|
+
const lines = env.split("\n");
|
|
155
|
+
lines.forEach((line) => {
|
|
156
|
+
const match = line.match(/^([^#=]+)=([^#]+)$/);
|
|
157
|
+
if (match) {
|
|
158
|
+
const key = match[1].trim();
|
|
159
|
+
process3.env[key] = match[2].trim();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
} catch (err) {
|
|
164
|
+
this.logger.error({
|
|
165
|
+
message: err.message,
|
|
166
|
+
title: TranslationLoader.t("EnvFileLoading", this.localLanguage),
|
|
167
|
+
errorType: err.code,
|
|
168
|
+
stackTrace: err.stack,
|
|
169
|
+
httpCodeValue: status.INTERNAL_SERVER_ERROR
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
244
173
|
/**
|
|
245
174
|
* Returns an Object containing a node version, openssl, and v0
|
|
246
175
|
*/
|
|
@@ -265,7 +194,7 @@ var CoreService = class {
|
|
|
265
194
|
* and Memory usage system
|
|
266
195
|
*/
|
|
267
196
|
getUsageMemory() {
|
|
268
|
-
|
|
197
|
+
this.loadTranslationFiles();
|
|
269
198
|
const memoryData = process3.memoryUsage();
|
|
270
199
|
const data = {
|
|
271
200
|
[TranslationLoader.t("totalMemoryAllocated", this.localLanguage)]: this.formatMemoryUsage(memoryData.rss),
|
|
@@ -297,37 +226,6 @@ var CoreService = class {
|
|
|
297
226
|
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
298
227
|
};
|
|
299
228
|
}
|
|
300
|
-
/**
|
|
301
|
-
*
|
|
302
|
-
* @param filePath
|
|
303
|
-
* @private
|
|
304
|
-
*
|
|
305
|
-
* Return void
|
|
306
|
-
*/
|
|
307
|
-
getEnvFileLoading(filePath) {
|
|
308
|
-
try {
|
|
309
|
-
const fullPath = path.resolve(process3.cwd(), filePath);
|
|
310
|
-
if (fs.existsSync(fullPath)) {
|
|
311
|
-
const env = fs.readFileSync(fullPath, "utf-8");
|
|
312
|
-
const lines = env.split("\n");
|
|
313
|
-
lines.forEach((line) => {
|
|
314
|
-
const match = line.match(/^([^#=]+)=([^#]+)$/);
|
|
315
|
-
if (match) {
|
|
316
|
-
const key = match[1].trim();
|
|
317
|
-
process3.env[key] = match[2].trim();
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
} catch (err) {
|
|
322
|
-
this.logger.error({
|
|
323
|
-
message: err.message,
|
|
324
|
-
title: TranslationLoader.t("EnvFileLoading", this.localLanguage),
|
|
325
|
-
errorType: err.code,
|
|
326
|
-
stackTrace: err.stack,
|
|
327
|
-
httpCodeValue: status.INTERNAL_SERVER_ERROR
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
229
|
/**
|
|
332
230
|
*
|
|
333
231
|
* @param development
|
|
@@ -336,14 +234,15 @@ var CoreService = class {
|
|
|
336
234
|
* Return string
|
|
337
235
|
*/
|
|
338
236
|
getServerRunningMode(development, production) {
|
|
237
|
+
this.loadTranslationFiles();
|
|
339
238
|
try {
|
|
340
|
-
loaderTranslationFile(this.localLanguage);
|
|
341
239
|
this.getEnvFileLoading(".env");
|
|
342
|
-
const env =
|
|
343
|
-
const isDevelopment = env.devEnv === development
|
|
240
|
+
const env = getEnvironmentValue(path.join(envPath));
|
|
241
|
+
const isDevelopment = env.devEnv === development;
|
|
242
|
+
const isProd = env.prodEnv === production;
|
|
344
243
|
if (isDevelopment) {
|
|
345
244
|
return `${TranslationLoader.t("serverRunning", this.localLanguage)} ${colors.bgBlue(`${colors.bold(`${development}`)}`)} mode`;
|
|
346
|
-
} else if (
|
|
245
|
+
} else if (isProd) {
|
|
347
246
|
return `${TranslationLoader.t("serverRunning", this.localLanguage)} ${colors.bgBlue(`${colors.bold(`${production}`)}`)} mode`;
|
|
348
247
|
} else {
|
|
349
248
|
return `${TranslationLoader.t("serverRunning", this.localLanguage)} ${colors.bgBlue(`${colors.bold(`${development}`)}`)} mode`;
|
|
@@ -359,9 +258,9 @@ var CoreService = class {
|
|
|
359
258
|
}
|
|
360
259
|
}
|
|
361
260
|
infoServer(host, port) {
|
|
261
|
+
this.loadTranslationFiles();
|
|
362
262
|
try {
|
|
363
|
-
|
|
364
|
-
const getEnvironment = getEnvironnementValue(this.environmentPath);
|
|
263
|
+
const getEnvironment = getEnvironmentValue(this.environmentPath);
|
|
365
264
|
const msg5 = getEnvironment.protocolTransfert === "" ? colors.underline(`http://${host}:${port}`) : colors.underline(`${getEnvironment.protocolTransfert}://${host}:${port}`);
|
|
366
265
|
const messages = [
|
|
367
266
|
TranslationLoader.t("webServerListening", this.localLanguage),
|
|
@@ -382,12 +281,11 @@ var CoreService = class {
|
|
|
382
281
|
});
|
|
383
282
|
console.log(border);
|
|
384
283
|
console.log("\n");
|
|
385
|
-
|
|
386
|
-
logCore.success({
|
|
284
|
+
this.logger.success({
|
|
387
285
|
title: TranslationLoader.t("serverRunningTitle", this.localLanguage),
|
|
388
286
|
message: TranslationLoader.t("serverRunningAt", this.localLanguage, { server: msg5 })
|
|
389
287
|
});
|
|
390
|
-
|
|
288
|
+
this.serverLog.serverLog({
|
|
391
289
|
timestamp: (/* @__PURE__ */ new Date()).toString(),
|
|
392
290
|
level: "SERVER",
|
|
393
291
|
title: TranslationLoader.t("serverRunningTitle", this.localLanguage),
|
|
@@ -395,7 +293,7 @@ var CoreService = class {
|
|
|
395
293
|
message: TranslationLoader.t("serverRunningAt", this.localLanguage, { server: msg5 })
|
|
396
294
|
});
|
|
397
295
|
} catch (err) {
|
|
398
|
-
|
|
296
|
+
this.logger.error({
|
|
399
297
|
message: err.message,
|
|
400
298
|
title: TranslationLoader.t("server", this.localLanguage),
|
|
401
299
|
errorType: err.code,
|
|
@@ -414,6 +312,20 @@ import {
|
|
|
414
312
|
CCodeError,
|
|
415
313
|
CErrorName
|
|
416
314
|
} from "opticore-catch-exception-error";
|
|
315
|
+
|
|
316
|
+
// src/application/service/logger.service.ts
|
|
317
|
+
var SLogger = (localLang) => {
|
|
318
|
+
return {
|
|
319
|
+
get serverLog() {
|
|
320
|
+
return dependenciesContainerProvider(localLang).resolve("OpticoreLogger");
|
|
321
|
+
},
|
|
322
|
+
get logger() {
|
|
323
|
+
return dependenciesContainerProvider(localLang).resolve("LoggerCore");
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/application/service/serverStartError.service.ts
|
|
417
329
|
import { HttpStatusCode as HttpStatusCode2 } from "opticore-http-response";
|
|
418
330
|
var SServerStartError = (err, environmentPath) => {
|
|
419
331
|
if (err.name) {
|
|
@@ -446,152 +358,108 @@ var SServerStartError = (err, environmentPath) => {
|
|
|
446
358
|
};
|
|
447
359
|
|
|
448
360
|
// src/core/webServer.core.ts
|
|
449
|
-
import {
|
|
361
|
+
import { SContainer as SContainer2 } from "opticore-dependency-inject";
|
|
450
362
|
var WebServerCore = class {
|
|
451
363
|
serverUtility;
|
|
452
|
-
expressApp =
|
|
453
|
-
fileWatcher;
|
|
364
|
+
expressApp = express2();
|
|
454
365
|
localLanguage;
|
|
455
366
|
loggerConfig;
|
|
456
367
|
routerExpressApp;
|
|
457
|
-
|
|
368
|
+
getEnvironmentValue;
|
|
458
369
|
environmentPath;
|
|
459
370
|
serverListenEvent;
|
|
460
|
-
|
|
461
|
-
currentDependencies = [];
|
|
462
|
-
server = void 0;
|
|
463
|
-
errorEmitter;
|
|
464
|
-
isWatcherEnabled = true;
|
|
465
|
-
serverStatus = "STARTING";
|
|
466
|
-
serverStartTime = /* @__PURE__ */ new Date();
|
|
371
|
+
dependenciesRegistered = false;
|
|
467
372
|
constructor(paramsConstructor) {
|
|
468
|
-
this.
|
|
373
|
+
this.loadTranslationFiles();
|
|
374
|
+
this.stackTraceErrorHandling();
|
|
375
|
+
this.getEnvironmentValue = getEnvironmentValue2(paramsConstructor.environmentPath);
|
|
469
376
|
this.routerExpressApp = paramsConstructor.app;
|
|
470
377
|
this.loggerConfig = paramsConstructor.loggerConfig;
|
|
471
378
|
this.localLanguage = paramsConstructor.localLanguage;
|
|
472
379
|
this.environmentPath = paramsConstructor.environmentPath;
|
|
473
|
-
this.expressApp.use(
|
|
474
|
-
this.expressApp.use(
|
|
475
|
-
this.expressApp.use(
|
|
476
|
-
this.expressApp.use(
|
|
380
|
+
this.expressApp.use(express2.json());
|
|
381
|
+
this.expressApp.use(express2.raw());
|
|
382
|
+
this.expressApp.use(express2.text());
|
|
383
|
+
this.expressApp.use(express2.urlencoded({ extended: true }));
|
|
477
384
|
this.expressApp.use(corsOrigin(paramsConstructor.corsOriginOptions));
|
|
478
385
|
this.serverListenEvent = new ServerListenEventError2(paramsConstructor.localLanguage);
|
|
479
386
|
this.serverUtility = new CoreService(paramsConstructor.localLanguage, paramsConstructor.environmentPath);
|
|
480
387
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
388
|
+
registerDependencies(dependencies2) {
|
|
389
|
+
try {
|
|
390
|
+
if (dependencies2 && dependencies2.length > 0) {
|
|
391
|
+
dependencies2.forEach((dependency) => {
|
|
392
|
+
return new SContainer2(this.localLanguage).register(dependency.key, dependency.factory, dependency.scope);
|
|
393
|
+
});
|
|
394
|
+
} else {
|
|
395
|
+
SLogger(this.environmentPath).logger.info({
|
|
396
|
+
message: TranslationLoader2.t("NO_REGISTER_DEPENDENCIES", this.localLanguage),
|
|
397
|
+
title: TranslationLoader2.t("REGISTER_DEPENDENCIES", this.localLanguage)
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
} catch (err) {
|
|
401
|
+
SLogger(this.environmentPath).logger.error({
|
|
402
|
+
message: err.message,
|
|
403
|
+
title: "Register Dependencies",
|
|
404
|
+
errorType: err.code,
|
|
405
|
+
stackTrace: err.stack,
|
|
406
|
+
httpCodeValue: HttpStatusCode3.INTERNAL_SERVER_ERROR
|
|
407
|
+
});
|
|
492
408
|
}
|
|
493
|
-
|
|
409
|
+
}
|
|
410
|
+
onStartServer(routers, databaseCallback, dependenciesProvider) {
|
|
411
|
+
this.loadTranslationFiles();
|
|
412
|
+
if (this.getEnvironmentValue.appPort === "" && Number(this.getEnvironmentValue.appPort) === 0) {
|
|
413
|
+
this.serverListenEvent.hostPortUndefined(Number(this.getEnvironmentValue.appPort));
|
|
414
|
+
} else if (this.getEnvironmentValue.appHost === "") {
|
|
415
|
+
this.serverListenEvent.hostUndefined(this.getEnvironmentValue.appHost);
|
|
416
|
+
} else if (Number(this.getEnvironmentValue.appPort) === 0) {
|
|
494
417
|
this.serverListenEvent.portUndefined();
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
if (this.localLanguage === "") {
|
|
498
|
-
SLogger(this.localLanguage).logger.error({
|
|
418
|
+
} else if (this.localLanguage === "") {
|
|
419
|
+
SLogger(this.environmentPath).logger.error({
|
|
499
420
|
message: TranslationLoader2.t("noDefaultLocalLang", this.localLanguage),
|
|
500
421
|
title: TranslationLoader2.t("noLocalLang", this.localLanguage),
|
|
501
422
|
errorType: TranslationLoader2.t("localLangMissing", this.localLanguage),
|
|
502
423
|
stackTrace: void 0,
|
|
503
424
|
httpCodeValue: HttpStatusCode3.NOT_FOUND
|
|
504
425
|
});
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
this.registerRoutes(this.currentRoutes);
|
|
518
|
-
this.setupErrorHandling();
|
|
519
|
-
this.setupServerEvents();
|
|
520
|
-
if (this.isWatcherEnabled) {
|
|
521
|
-
this.initializeFileWatcher();
|
|
426
|
+
} else {
|
|
427
|
+
return this.expressApp.listen(
|
|
428
|
+
Number(this.getEnvironmentValue.appPort),
|
|
429
|
+
() => {
|
|
430
|
+
this.loadTranslationFiles();
|
|
431
|
+
try {
|
|
432
|
+
databaseCallback(this.getEnvironmentValue);
|
|
433
|
+
new SContainer2(this.localLanguage, dependenciesProvider);
|
|
434
|
+
this.expressApp.use(express2.static(path2.join(process4.cwd(), "public/template")));
|
|
435
|
+
this.registerRoutes(routers);
|
|
436
|
+
} catch (err) {
|
|
437
|
+
SServerStartError(err, this.environmentPath);
|
|
522
438
|
}
|
|
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);
|
|
533
439
|
}
|
|
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
|
-
});
|
|
440
|
+
);
|
|
569
441
|
}
|
|
570
|
-
SLogger(this.localLanguage).logger.info({
|
|
571
|
-
title: TranslationLoader2.t("ERROR_HANDLING", this.localLanguage),
|
|
572
|
-
message: TranslationLoader2.t("ERROR_HANDLING_CONFIGURED", this.localLanguage)
|
|
573
|
-
});
|
|
574
442
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
setupServerEvents() {
|
|
579
|
-
if (!this.server) return;
|
|
580
|
-
this.server.on(eventName2.error, (err) => {
|
|
443
|
+
onListeningOnServerEvent(serverWeb) {
|
|
444
|
+
this.loadTranslationFiles();
|
|
445
|
+
serverWeb.on(eventName2.error, (err) => {
|
|
581
446
|
this.serverListenEvent.onEventError(err);
|
|
582
|
-
})
|
|
583
|
-
this.server.on(eventName2.close, () => {
|
|
447
|
+
}).on(eventName2.close, () => {
|
|
584
448
|
this.serverListenEvent.serverClosing();
|
|
585
|
-
})
|
|
586
|
-
this.server.on(eventName2.drop, () => {
|
|
449
|
+
}).on(eventName2.drop, () => {
|
|
587
450
|
this.serverListenEvent.dropNewConnection();
|
|
451
|
+
}).on(eventName2.listening, () => {
|
|
452
|
+
this.infoWebApp();
|
|
588
453
|
});
|
|
589
|
-
|
|
454
|
+
}
|
|
455
|
+
onRequestOnServerEvent(serverWeb) {
|
|
456
|
+
this.loadTranslationFiles();
|
|
457
|
+
serverWeb.on(eventName2.request, (req, res) => {
|
|
590
458
|
requestCallsEvent(
|
|
591
459
|
req,
|
|
592
460
|
res,
|
|
593
|
-
this.
|
|
594
|
-
Number(this.
|
|
461
|
+
this.getEnvironmentValue.appHost,
|
|
462
|
+
Number(this.getEnvironmentValue.appPort),
|
|
595
463
|
dateTimeFormattedUtils,
|
|
596
464
|
this.environmentPath,
|
|
597
465
|
this.localLanguage
|
|
@@ -599,645 +467,42 @@ var WebServerCore = class {
|
|
|
599
467
|
});
|
|
600
468
|
}
|
|
601
469
|
/**
|
|
602
|
-
*
|
|
603
|
-
|
|
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);
|
|
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
|
-
)
|
|
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
|
-
}
|
|
702
|
-
}
|
|
703
|
-
/**
|
|
704
|
-
* Handle hot reload requested by watcher
|
|
705
|
-
*/
|
|
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
|
-
}
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
* Handle watcher errors
|
|
737
|
-
*/
|
|
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
|
-
});
|
|
746
|
-
}
|
|
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))
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
/**
|
|
757
|
-
* Reload environment configuration
|
|
758
|
-
*/
|
|
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) {
|
|
780
|
-
try {
|
|
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
|
-
});
|
|
790
|
-
} catch (error) {
|
|
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
|
-
});
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
/**
|
|
800
|
-
* Reload configuration files
|
|
801
|
-
*/
|
|
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
|
-
});
|
|
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
|
-
});
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
/**
|
|
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
|
|
947
|
-
*/
|
|
948
|
-
reloadConfigurations() {
|
|
949
|
-
try {
|
|
950
|
-
const newEnv = getEnvironnementValue2(this.environmentPath);
|
|
951
|
-
Object.keys(newEnv).forEach((key) => {
|
|
952
|
-
this.getEnvironment[key] = newEnv[key];
|
|
953
|
-
});
|
|
954
|
-
loaderTranslationFile(this.localLanguage);
|
|
955
|
-
} catch (error) {
|
|
956
|
-
throw new Error(`Configuration reload failed: ${error.message}`);
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Reload dependencies
|
|
470
|
+
*
|
|
471
|
+
* @private
|
|
961
472
|
*/
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
new SContainer2(this.localLanguage, this.currentDependencies);
|
|
965
|
-
const container = dependenciesContainerProvider(this.localLanguage);
|
|
966
|
-
if (!container) {
|
|
967
|
-
throw new Error("Dependency container is not available");
|
|
968
|
-
}
|
|
969
|
-
} catch (error) {
|
|
970
|
-
throw new Error(`Dependency reload failed: ${error.message}`);
|
|
971
|
-
}
|
|
473
|
+
loadTranslationFiles() {
|
|
474
|
+
loaderTranslationFile(this.localLanguage);
|
|
972
475
|
}
|
|
973
476
|
/**
|
|
974
|
-
*
|
|
477
|
+
*
|
|
478
|
+
* @param allFeatureRoutes
|
|
479
|
+
* @private
|
|
975
480
|
*/
|
|
976
481
|
registerRoutes(allFeatureRoutes) {
|
|
977
|
-
allFeatureRoutes.
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
});
|
|
982
|
-
}
|
|
482
|
+
allFeatureRoutes.map((router) => {
|
|
483
|
+
router.routes.map((route) => {
|
|
484
|
+
this.expressApp.use(route.path, route.handler);
|
|
485
|
+
});
|
|
983
486
|
});
|
|
984
487
|
}
|
|
985
488
|
/**
|
|
986
|
-
*
|
|
489
|
+
*
|
|
490
|
+
* @private
|
|
987
491
|
*/
|
|
988
|
-
|
|
989
|
-
|
|
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
|
-
};
|
|
492
|
+
stackTraceErrorHandling() {
|
|
493
|
+
return eventProcessHandler(this.localLanguage);
|
|
1007
494
|
}
|
|
1008
495
|
/**
|
|
1009
|
-
*
|
|
496
|
+
*
|
|
497
|
+
* @private
|
|
1010
498
|
*/
|
|
1011
499
|
infoWebApp() {
|
|
500
|
+
this.loadTranslationFiles();
|
|
1012
501
|
this.serverUtility.infoServer(
|
|
1013
|
-
this.
|
|
1014
|
-
Number(this.
|
|
502
|
+
this.getEnvironmentValue.appHost,
|
|
503
|
+
Number(this.getEnvironmentValue.appPort)
|
|
1015
504
|
);
|
|
1016
505
|
}
|
|
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);
|
|
1052
|
-
});
|
|
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);
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
/**
|
|
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
|
|
1081
|
-
*/
|
|
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() {
|
|
1210
|
-
try {
|
|
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
|
-
});
|
|
1217
|
-
} catch (error) {
|
|
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);
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
506
|
};
|
|
1242
507
|
export {
|
|
1243
508
|
WebServerCore as WebServer,
|