opticore-webapp 1.0.8 → 1.0.10
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 +116 -632
- package/dist/index.d.cts +6 -66
- package/dist/index.d.ts +6 -66
- package/dist/index.js +109 -613
- package/package.json +9 -6
- package/src/application/service/core.service.ts +13 -10
- package/src/core/handlers/eventProcess.handler.ts +8 -5
- package/src/core/{utils → helpers}/logMessage.utils.ts +2 -2
- package/src/core/helpers/modulesLoaded.utils.ts +22 -0
- package/src/core/webServer.core.ts +28 -23
- package/src/domains/interfaces/routeDefinition.interface.ts +2 -2
- package/src/domains/types/kernelModule.type.ts +1 -1
- package/src/index.ts +1 -8
- package/src/utils/translations/messages.exception.en.json +78 -0
- package/src/utils/translations/messages.exception.fr.json +78 -0
- package/tsup.config.ts +1 -1
- package/src/application/exceptions/messages.exception.ts +0 -67
- package/src/core/events/errors/serverListen.event.error.ts +0 -335
- package/src/core/events/requestCalls.event.ts +0 -83
- package/src/core/handlers/errors/base/stackTraceError.ts +0 -23
- package/src/core/handlers/errors/stackTraceAssertionError.ts +0 -13
- package/src/core/handlers/errors/stackTraceEvalError.ts +0 -12
- package/src/core/handlers/errors/stackTraceGeneralError.ts +0 -13
- package/src/core/handlers/errors/stackTraceOpenSSLError.ts +0 -12
- package/src/core/handlers/errors/stackTraceRangeError.ts +0 -12
- package/src/core/handlers/errors/stackTraceReferenceError.ts +0 -13
- package/src/core/handlers/errors/stackTraceSyntaxError.ts +0 -12
- package/src/core/handlers/errors/stackTraceSystemError.ts +0 -14
- package/src/core/handlers/errors/stackTraceTypeError.ts +0 -13
- package/src/core/handlers/errors/stackTraceURIError.ts +0 -13
- package/src/core/utils/modulesLoaded.utils.ts +0 -16
- package/src/domains/constants/errorName.constant.ts +0 -12
- package/src/domains/constants/event.constant.ts +0 -15
- package/src/domains/constants/eventNameError.constant.ts +0 -8
- package/src/domains/constants/httpStatusCodes.constant.ts +0 -375
- package/src/domains/constants/logLevel.constant.ts +0 -6
- package/src/domains/env/access.env.ts +0 -23
- package/src/domains/interfaces/envVariables.interface.ts +0 -16
- package/src/domains/interfaces/kernelModule.interface.ts +0 -6
- package/src/infrastructure/events/.gitkeep +0 -0
- package/src/infrastructure/handlers/.gitkeep +0 -0
- package/src/presentation/middleware/.gitkeep +0 -0
- /package/src/core/{errors → events}/.gitkeep +0 -0
- /package/src/core/{utils → helpers}/dateTimeFormatted.utils.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,472 +1,66 @@
|
|
|
1
1
|
// src/core/webServer.core.ts
|
|
2
|
-
import express2 from "express";
|
|
3
2
|
import corsOrigin from "cors";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
dataBaseHost: String((_j = (_i = dotenv.config()) == null ? void 0 : _i.parsed) == null ? void 0 : _j.DATA_BASE_HOST),
|
|
14
|
-
dataBasePort: String((_l = (_k = dotenv.config()) == null ? void 0 : _k.parsed) == null ? void 0 : _l.DATA_BASE_PORT),
|
|
15
|
-
dataBaseUser: String((_n = (_m = dotenv.config()) == null ? void 0 : _m.parsed) == null ? void 0 : _n.DATA_BASE_USER),
|
|
16
|
-
dataBasePassword: String((_p = (_o = dotenv.config()) == null ? void 0 : _o.parsed) == null ? void 0 : _p.DATA_BASE_PASSWORD),
|
|
17
|
-
dataBaseName: String((_r = (_q = dotenv.config()) == null ? void 0 : _q.parsed) == null ? void 0 : _r.DATA_BASE_NAME),
|
|
18
|
-
apiVersion: String((_t = (_s = dotenv.config()) == null ? void 0 : _s.parsed) == null ? void 0 : _t.API_VERSION),
|
|
19
|
-
usernameField: String((_v = (_u = dotenv.config()) == null ? void 0 : _u.parsed) == null ? void 0 : _v.USERNAME_FIELD),
|
|
20
|
-
passwordField: String((_x = (_w = dotenv.config()) == null ? void 0 : _w.parsed) == null ? void 0 : _x.PASSWORD_FIELD),
|
|
21
|
-
argumentsDatabaseConnection: String((_z = (_y = dotenv.config()) == null ? void 0 : _y.parsed) == null ? void 0 : _z.ARGUMENTS_DATABASE_CONNECTION),
|
|
22
|
-
logEnv: String((_B = (_A = dotenv.config()) == null ? void 0 : _A.parsed) == null ? void 0 : _B.LOG_ENVIRONMENT)
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// src/core/handlers/errors/base/stackTraceError.ts
|
|
26
|
-
var StackTraceError = class extends Error {
|
|
27
|
-
// Centralized error objet that derives from Node's Error.
|
|
28
|
-
constructor(props, name, httpCode, isOperational) {
|
|
29
|
-
super(props);
|
|
30
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
31
|
-
this.name = name;
|
|
32
|
-
this.httpCode = httpCode;
|
|
33
|
-
this.isOperational = isOperational;
|
|
34
|
-
Error.captureStackTrace(this);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
3
|
+
import {
|
|
4
|
+
CEventNameError as eventName2,
|
|
5
|
+
StackTraceError as StackTraceError2,
|
|
6
|
+
ServerListenEventError as eventErrorOnListeningServer
|
|
7
|
+
} from "opticore-catch-exception-error";
|
|
8
|
+
import { express as express2 } from "opticore-express";
|
|
9
|
+
import { getEnvVariable } from "opticore-env-access";
|
|
10
|
+
import { requestCallsEvent } from "opticore-requests-called-events";
|
|
11
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
37
12
|
|
|
38
13
|
// src/core/handlers/eventProcess.handler.ts
|
|
39
|
-
import
|
|
40
|
-
import process2 from "node:process";
|
|
14
|
+
import process from "node:process";
|
|
41
15
|
import EventEmitter from "node:events";
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// src/core/utils/dateTimeFormatted.utils.ts
|
|
49
|
-
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()}`;
|
|
50
|
-
|
|
51
|
-
// src/application/exceptions/messages.exception.ts
|
|
52
|
-
import colors from "ansi-colors";
|
|
53
|
-
var messageException = {
|
|
54
|
-
dbConnection: "DataBase connection",
|
|
55
|
-
dbConnectionClosed: "MySQL connection is closed",
|
|
56
|
-
mysqlErrorCon: "MysqlError connection",
|
|
57
|
-
mySQLError: "MysqlError",
|
|
58
|
-
mySqlCloseConnection: "MySql close connection",
|
|
59
|
-
verifyExistingKey: "Verify Existing Key",
|
|
60
|
-
invalidRequest: "Invalid request",
|
|
61
|
-
tokenNotProvided: "No token provided.",
|
|
62
|
-
ExpiresToken: "Expires Token. You're not authorize",
|
|
63
|
-
privateKeyNotExist: "A private key doesn't exist.",
|
|
64
|
-
publicKeyNotExist: "A public key doesn't exist.",
|
|
65
|
-
errorNamePublicKeyNotExist: "No public key",
|
|
66
|
-
errorAuthorPublicKeyNotExist: "PublicKey not existing",
|
|
67
|
-
errorDecryption: "Error decryption with private key",
|
|
68
|
-
rsaKeyNotFound: "RSA key provided is not found.",
|
|
69
|
-
notVerifyingRSAKey: "Not verify RSA Key",
|
|
70
|
-
errorNameNotVerifyingRSAKey: "Error Verify RSA Key",
|
|
71
|
-
errorEncryptionPublicKey: "Error encryption with public key",
|
|
72
|
-
errorEncryptionPrivateKey: "Error encryption with private key",
|
|
73
|
-
errorNameRsaVerifyExistingKey: "Verify existing key",
|
|
74
|
-
signatureRSAKeyFailed: "Signature verification failed.",
|
|
75
|
-
encryptionWithPrivateKeyFailed: "Encryption With PrivateKey",
|
|
76
|
-
encryptionFailed: "Encryption failed",
|
|
77
|
-
decryptionWithPublicKeyFailed: "Decryption With PublicKey",
|
|
78
|
-
decryptionFailed: "Decryption failed",
|
|
79
|
-
verifyRSAKey: "Verify RSA Keys",
|
|
80
|
-
verifyRSAKeyFailed: "Verify RSA Keys Failed",
|
|
81
|
-
notVerifying: "Verification failed",
|
|
82
|
-
signatureRSAKeysError: "Signature RSA Keys Error",
|
|
83
|
-
encryptionWithPublicKey: "Encryption error",
|
|
84
|
-
errorDecryptionWithPrivateKey: "Error Decryption With PrivateKey",
|
|
85
|
-
verifyPublicRSAKey: "Verify Public RSA Key",
|
|
86
|
-
PostgresDBConnectionChecker: "PostgresDB Connection Checker",
|
|
87
|
-
PostgresConnection: "connection",
|
|
88
|
-
MongoDBConnectionChecker: "MongoDB Connection Checker",
|
|
89
|
-
MongoConnection: "connection",
|
|
90
|
-
mongoDBAuthentication: "authentication",
|
|
91
|
-
mongoDBConnection: "MongoDB connection",
|
|
92
|
-
mongoDBAuthenticationFailed: "failed",
|
|
93
|
-
mongoDBUnableParsingUrl: "unable to parse",
|
|
94
|
-
mongoDBConnectionUrl: "url",
|
|
95
|
-
mongoDBServerSelection: "MongoServer selection error",
|
|
96
|
-
mongoDBServer: "MongoServer",
|
|
97
|
-
mongoDBConnectionError: "connection error",
|
|
98
|
-
mongoDBError: "error",
|
|
99
|
-
loadedModules: "Loading core modules",
|
|
100
|
-
loadedModulesError: "Required core modules are not loaded properly",
|
|
101
|
-
dbConnexionSuccess: "The database connection was successful \u{1F680}",
|
|
102
|
-
mongoConnectionSuccess: "Connection to database is successfully.",
|
|
103
|
-
PostgresConnectionSuccess: "Connection to database is successfully.",
|
|
104
|
-
verifyExistingKeyError: "The provided key is not found",
|
|
105
|
-
webServer: "Web server",
|
|
106
|
-
listening: "listening",
|
|
107
|
-
webHost: "host",
|
|
108
|
-
badHost: "bad host",
|
|
109
|
-
hostNotFound: "not found",
|
|
110
|
-
errorHostUrl: "The host and port are not define, please define them in .env",
|
|
111
|
-
badPort: "bad port",
|
|
112
|
-
errorPort: "The port is not correct. Please define a right port with number port.",
|
|
113
|
-
errorHost: "The host can't be empty or blank. Please define a string host in .env",
|
|
114
|
-
accessDeniedToDBCon: (user, password) => `Access denied for user ${user}. Database credentials in .env file are User: ${user} and Password: ${password}. '${user}''${password}'@'localhost'. Try to set user and password in .env file`,
|
|
115
|
-
unknownDB: (database) => `Database ${database} is unknown. Please try to use Database CLI to create your database, or do it manually in your Database Management System`,
|
|
116
|
-
errorDBHost: (host) => `A database host ${host} does not allow connection. Please either set the host like this: ${colors.bgRed(`${colors.white(`localhost`)}`)} in your .env file`
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
// src/domains/constants/eventNameError.constant.ts
|
|
120
|
-
var CEventNameError = {
|
|
121
|
-
error: "error",
|
|
122
|
-
listening: "listening",
|
|
123
|
-
close: "close",
|
|
124
|
-
connection: "connection",
|
|
125
|
-
drop: "drop",
|
|
126
|
-
request: "request"
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
// src/core/events/errors/serverListen.event.error.ts
|
|
130
|
-
import { LoggerCore } from "opticore-logger";
|
|
131
|
-
var ServerListenEventError = class {
|
|
132
|
-
/**
|
|
133
|
-
*
|
|
134
|
-
*/
|
|
135
|
-
static hostPortUndefined() {
|
|
136
|
-
this.stackTrace = this.traceError(messageException.errorHostUrl, messageException.listening, 400 /* BAD_REQUEST */);
|
|
137
|
-
this.logger.error(this.stackTrace.message, messageException.webServer, messageException.badHost, this.stackTrace.stack, 400 /* BAD_REQUEST */);
|
|
138
|
-
process.exit();
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
*
|
|
142
|
-
*/
|
|
143
|
-
static hostUndefined() {
|
|
144
|
-
this.stackTrace = this.traceError(messageException.badHost, messageException.listening, 400 /* BAD_REQUEST */);
|
|
145
|
-
this.logger.error(this.stackTrace.message, messageException.webServer, messageException.badHost, this.stackTrace.stack, 400 /* BAD_REQUEST */);
|
|
146
|
-
process.exit();
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
*
|
|
150
|
-
*/
|
|
151
|
-
static portUndefined() {
|
|
152
|
-
this.stackTrace = this.traceError(messageException.badPort, messageException.listening, 400 /* BAD_REQUEST */);
|
|
153
|
-
this.logger.error(this.stackTrace.message, messageException.webServer, messageException.badHost, this.stackTrace.stack, 400 /* BAD_REQUEST */);
|
|
154
|
-
process.exit();
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
*
|
|
158
|
-
* @param err
|
|
159
|
-
*/
|
|
160
|
-
static onEventError(err) {
|
|
161
|
-
this.logger.error(err.message, "Server start error", "Error", err.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
*
|
|
165
|
-
* @param error
|
|
166
|
-
*/
|
|
167
|
-
static listenerError(error) {
|
|
168
|
-
this.stackTrace = this.traceError(error.message, error.name, 400 /* BAD_REQUEST */);
|
|
169
|
-
this.logger.error(this.stackTrace.message, "Event error", "Error", error.stack, 400 /* BAD_REQUEST */);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
*
|
|
173
|
-
* @param code
|
|
174
|
-
*/
|
|
175
|
-
static processBeforeExit(code) {
|
|
176
|
-
this.stackTrace = this.traceError(`Process will exit with code: ${code}`, "BeforeExit", 503 /* SERVICE_UNAVAILABLE */);
|
|
177
|
-
this.logger.error(this.stackTrace.message, "BeforeExit", "process before exit", this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
178
|
-
process.exit(code);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
*
|
|
182
|
-
*/
|
|
183
|
-
static processDisconnected() {
|
|
184
|
-
this.stackTrace = this.traceError("Child process disconnected", "process disconnected", 503 /* SERVICE_UNAVAILABLE */);
|
|
185
|
-
this.logger.error(this.stackTrace.message, "Disconnected", "process disconnected", this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
186
|
-
process.exit();
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
*
|
|
190
|
-
* @param code
|
|
191
|
-
*/
|
|
192
|
-
static exited(code) {
|
|
193
|
-
switch (code) {
|
|
194
|
-
case 0:
|
|
195
|
-
this.logger.success("completed", "The process finished as expected and everything is ok");
|
|
196
|
-
console.log("");
|
|
197
|
-
const paddingLength = 35;
|
|
198
|
-
const msg0 = " ".padEnd(paddingLength, " ");
|
|
199
|
-
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
200
|
-
console.log(`${colors2.bgGreen(` [OK] The server shutting down `)}`);
|
|
201
|
-
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
202
|
-
break;
|
|
203
|
-
case 1:
|
|
204
|
-
this.stackTrace = this.traceError("Something went wrong", "General Errors", 503 /* SERVICE_UNAVAILABLE */);
|
|
205
|
-
this.logger.error(this.stackTrace.message, "Exited", "General Errors", this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
206
|
-
break;
|
|
207
|
-
case 2:
|
|
208
|
-
this.stackTrace = this.traceError("Incorrect using of shell commands", "Misuse of shell builtins", 503 /* SERVICE_UNAVAILABLE */);
|
|
209
|
-
this.logger.error(this.stackTrace.message, "Exited", "Incorrect using of shell commands", this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
210
|
-
break;
|
|
211
|
-
case 126:
|
|
212
|
-
this.stackTrace = this.traceError(
|
|
213
|
-
"Incorrect using of shell commands",
|
|
214
|
-
"The command is found but is not executable (e.g., trying to execute a directory)",
|
|
215
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
216
|
-
);
|
|
217
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
218
|
-
break;
|
|
219
|
-
case 127:
|
|
220
|
-
this.stackTrace = this.traceError(
|
|
221
|
-
"Command not found",
|
|
222
|
-
"The command was not found in the system's PATH or is misspelled",
|
|
223
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
224
|
-
);
|
|
225
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
226
|
-
break;
|
|
227
|
-
case 128:
|
|
228
|
-
this.stackTrace = this.traceError(
|
|
229
|
-
"The command was not found in the system's PATH or is misspelled",
|
|
230
|
-
"Invalid argument",
|
|
231
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
232
|
-
);
|
|
233
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
234
|
-
break;
|
|
235
|
-
case 130:
|
|
236
|
-
this.stackTrace = this.traceError(
|
|
237
|
-
"Indicates that the script was manually terminated by the user using the Control-C (SIGINT) signal",
|
|
238
|
-
"Script terminated",
|
|
239
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
240
|
-
);
|
|
241
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
242
|
-
break;
|
|
243
|
-
case 137:
|
|
244
|
-
this.stackTrace = this.traceError(
|
|
245
|
-
"Indicates that the process was terminated by a SIGKILL signal, possibly due to an out-of-memory situation",
|
|
246
|
-
"SIGKILL",
|
|
247
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
248
|
-
);
|
|
249
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
250
|
-
break;
|
|
251
|
-
case 139:
|
|
252
|
-
this.stackTrace = this.traceError(
|
|
253
|
-
"Indicates that the process accessed an illegal memory address (segfault)",
|
|
254
|
-
"Segmentation fault",
|
|
255
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
256
|
-
);
|
|
257
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
258
|
-
break;
|
|
259
|
-
case 143:
|
|
260
|
-
this.stackTrace = this.traceError(
|
|
261
|
-
"Indicates that the process received a SIGTERM signal to terminate",
|
|
262
|
-
"process received a SIGTERM",
|
|
263
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
264
|
-
);
|
|
265
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
266
|
-
break;
|
|
267
|
-
case 255:
|
|
268
|
-
this.stackTrace = this.traceError(
|
|
269
|
-
"An exit code that is outside the allowable range (0-255 for Unix-like systems)",
|
|
270
|
-
"out of range",
|
|
271
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
272
|
-
);
|
|
273
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
274
|
-
break;
|
|
275
|
-
default:
|
|
276
|
-
this.stackTrace = this.traceError(
|
|
277
|
-
"Error is occurring",
|
|
278
|
-
"errors",
|
|
279
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
280
|
-
);
|
|
281
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
*
|
|
287
|
-
* @param promise
|
|
288
|
-
*/
|
|
289
|
-
static promiseRejectionHandled(promise) {
|
|
290
|
-
this.stackTrace = this.traceError(
|
|
291
|
-
`Promise rejection is handled at : ${promise}`,
|
|
292
|
-
"rejection promise",
|
|
293
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
294
|
-
);
|
|
295
|
-
this.logger.error(this.stackTrace.message, "PromiseRejectionHandled", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
296
|
-
}
|
|
297
|
-
/**
|
|
298
|
-
*
|
|
299
|
-
* @param error
|
|
300
|
-
*/
|
|
301
|
-
static uncaughtException(error) {
|
|
302
|
-
if (error.message === "'app.router' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.") {
|
|
303
|
-
console.log("");
|
|
304
|
-
} else {
|
|
305
|
-
this.stackTrace = this.traceError(error.message, "uncaught exception handled", 503 /* SERVICE_UNAVAILABLE */);
|
|
306
|
-
this.logger.error(this.stackTrace.message, "UncaughtException", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
*
|
|
311
|
-
* @param error
|
|
312
|
-
*/
|
|
313
|
-
static uncaughtExceptionMonitor(error) {
|
|
314
|
-
if (error.message === "'app.router' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.") {
|
|
315
|
-
console.log("");
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
/**
|
|
319
|
-
*
|
|
320
|
-
* @param reason
|
|
321
|
-
* @param promise
|
|
322
|
-
*/
|
|
323
|
-
static unhandledRejection(reason, promise) {
|
|
324
|
-
this.stackTrace = this.traceError(
|
|
325
|
-
`Unhandled Rejection at: Promise ${promise} -- reason ${reason}`,
|
|
326
|
-
"Unhandled rejection",
|
|
327
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
328
|
-
);
|
|
329
|
-
this.logger.error(this.stackTrace.message, "UnhandledRejection", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
*
|
|
333
|
-
* @param warning
|
|
334
|
-
*/
|
|
335
|
-
static warning(warning) {
|
|
336
|
-
this.stackTrace = this.traceError(warning.message, "warning", 503 /* SERVICE_UNAVAILABLE */);
|
|
337
|
-
this.logger.error(this.stackTrace.message, "Warning", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
338
|
-
}
|
|
339
|
-
/**
|
|
340
|
-
*
|
|
341
|
-
* @param message
|
|
342
|
-
*/
|
|
343
|
-
static message(message) {
|
|
344
|
-
this.stackTrace = this.traceError(
|
|
345
|
-
`process got message ${message}`,
|
|
346
|
-
"message exception",
|
|
347
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
348
|
-
);
|
|
349
|
-
this.logger.error(this.stackTrace.message, "Message", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
*
|
|
353
|
-
* @param type
|
|
354
|
-
* @param promise
|
|
355
|
-
* @param reason
|
|
356
|
-
*/
|
|
357
|
-
static multipleResolves(type, promise, reason) {
|
|
358
|
-
this.stackTrace = this.traceError(
|
|
359
|
-
`${promise} -- ${reason}`,
|
|
360
|
-
`Multiple resolves detected : ${type}`,
|
|
361
|
-
503 /* SERVICE_UNAVAILABLE */
|
|
362
|
-
);
|
|
363
|
-
this.logger.error(this.stackTrace.message, "multipleResolves", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
364
|
-
}
|
|
365
|
-
/**
|
|
366
|
-
*
|
|
367
|
-
*/
|
|
368
|
-
static processInterrupted() {
|
|
369
|
-
this.logger.success("[ OK ] Success", "The Web server has been stopped !");
|
|
370
|
-
process.exit(0);
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
*
|
|
374
|
-
* @param signal
|
|
375
|
-
*/
|
|
376
|
-
static sigtermSignalReceived(signal) {
|
|
377
|
-
this.stackTrace = this.traceError(
|
|
378
|
-
`Process ${process.pid} received a SIGTERM signal : ${signal.toString()}`,
|
|
379
|
-
"SIGTERM",
|
|
380
|
-
406 /* NOT_ACCEPTABLE */
|
|
381
|
-
);
|
|
382
|
-
this.logger.error(this.stackTrace.message, "SIGTERM", this.stackTrace.name, this.stackTrace.stack, 406 /* NOT_ACCEPTABLE */);
|
|
383
|
-
process.exit(0);
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
*
|
|
387
|
-
*/
|
|
388
|
-
static serverClosing() {
|
|
389
|
-
console.log(`${colors2.bgCyanBright(` ${colors2.bold(`${colors2.white(` INFO `)}`)}`)} All processes are stopped`);
|
|
390
|
-
console.log(" Server is closed");
|
|
391
|
-
process.exit();
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
*
|
|
395
|
-
*/
|
|
396
|
-
static dropNewConnection() {
|
|
397
|
-
console.log(`${colors2.cyan(`\u24D8`)} ${colors2.bgCyan(` ${colors2.bold(`${colors2.white(` Server maxConnection `)}`)} `)} ${dateTimeFormattedUtils} | ${colors2.bgCyan(`${colors2.white(` Info `)}`)} The server dropped new connections`);
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
*
|
|
401
|
-
* @param errorEmitter
|
|
402
|
-
* @param err
|
|
403
|
-
* @param req
|
|
404
|
-
* @param res
|
|
405
|
-
* @param next
|
|
406
|
-
*/
|
|
407
|
-
static expressErrorHandlingMiddleware(errorEmitter, err, req, res, next) {
|
|
408
|
-
if (err) {
|
|
409
|
-
errorEmitter.emit(CEventNameError.error, err);
|
|
410
|
-
if (typeof res.status === "function") {
|
|
411
|
-
res.status(500).send("Internal Server Error");
|
|
412
|
-
} else {
|
|
413
|
-
console.error("res.status is not a function");
|
|
414
|
-
}
|
|
415
|
-
this.stackTrace = this.traceError(err.message, "Express error", 406 /* NOT_ACCEPTABLE */);
|
|
416
|
-
this.logger.error(this.stackTrace.message, "Express error-handling middleware", this.stackTrace.name, this.stackTrace.stack, 503 /* SERVICE_UNAVAILABLE */);
|
|
417
|
-
} else {
|
|
418
|
-
next();
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
static traceError(props, name, status) {
|
|
422
|
-
return new StackTraceError(props, name, status, true);
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
ServerListenEventError.logger = new LoggerCore();
|
|
426
|
-
|
|
427
|
-
// src/core/handlers/eventProcess.handler.ts
|
|
16
|
+
import { express } from "opticore-express";
|
|
17
|
+
import {
|
|
18
|
+
ServerListenEventError,
|
|
19
|
+
CEventNameError as eventName,
|
|
20
|
+
CEvent as event
|
|
21
|
+
} from "opticore-catch-exception-error";
|
|
428
22
|
function eventProcessHandler() {
|
|
429
23
|
const errorEmitter = new EventEmitter();
|
|
430
24
|
const app = express();
|
|
431
|
-
errorEmitter.on(
|
|
25
|
+
errorEmitter.on(eventName.error, (error) => {
|
|
432
26
|
ServerListenEventError.listenerError(error);
|
|
433
27
|
});
|
|
434
|
-
|
|
28
|
+
process.on(event.beforeExit, (code) => {
|
|
435
29
|
setTimeout(() => {
|
|
436
30
|
ServerListenEventError.processBeforeExit(code);
|
|
437
31
|
}, 100);
|
|
438
32
|
});
|
|
439
|
-
|
|
33
|
+
process.on(event.disconnect, () => {
|
|
440
34
|
ServerListenEventError.processDisconnected();
|
|
441
35
|
});
|
|
442
|
-
|
|
36
|
+
process.on(event.exit, (code) => {
|
|
443
37
|
ServerListenEventError.exited(code);
|
|
444
38
|
});
|
|
445
|
-
|
|
39
|
+
process.on(event.rejectionHandled, (promise) => {
|
|
446
40
|
ServerListenEventError.promiseRejectionHandled(promise);
|
|
447
41
|
});
|
|
448
|
-
|
|
42
|
+
process.on(event.uncaughtException, (error) => {
|
|
449
43
|
ServerListenEventError.uncaughtException(error);
|
|
450
44
|
});
|
|
451
|
-
|
|
45
|
+
process.on(event.uncaughtExceptionMonitor, (error) => {
|
|
452
46
|
ServerListenEventError.uncaughtExceptionMonitor(error);
|
|
453
47
|
});
|
|
454
|
-
|
|
48
|
+
process.on(event.unhandledRejection, (reason, promise) => {
|
|
455
49
|
ServerListenEventError.unhandledRejection(reason, promise);
|
|
456
50
|
});
|
|
457
|
-
|
|
51
|
+
process.on(event.warning, (warning) => {
|
|
458
52
|
ServerListenEventError.warning(warning);
|
|
459
53
|
});
|
|
460
|
-
|
|
54
|
+
process.on(event.message, (message) => {
|
|
461
55
|
ServerListenEventError.message(message);
|
|
462
56
|
});
|
|
463
|
-
|
|
57
|
+
process.on(event.multipleResolves, (type, promise, reason) => {
|
|
464
58
|
ServerListenEventError.multipleResolves(type, promise, reason);
|
|
465
59
|
});
|
|
466
|
-
|
|
60
|
+
process.on(event.sigint, () => {
|
|
467
61
|
ServerListenEventError.processInterrupted();
|
|
468
62
|
});
|
|
469
|
-
|
|
63
|
+
process.on(event.sigterm, (signal) => {
|
|
470
64
|
ServerListenEventError.sigtermSignalReceived(signal);
|
|
471
65
|
});
|
|
472
66
|
app.use((err, req, res, next) => {
|
|
@@ -474,125 +68,58 @@ function eventProcessHandler() {
|
|
|
474
68
|
});
|
|
475
69
|
}
|
|
476
70
|
|
|
477
|
-
// src/core/events/requestCalls.event.ts
|
|
478
|
-
import colors3 from "ansi-colors";
|
|
479
|
-
import { LoggerCore as LoggerCore2 } from "opticore-logger";
|
|
480
|
-
function requestCallsEvent(req, res, host, port, loadingTime) {
|
|
481
|
-
const logger = new LoggerCore2();
|
|
482
|
-
const currentDatePath = `Request called`;
|
|
483
|
-
if (req.originalUrl === "undefined") {
|
|
484
|
-
console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] The route do not exist. - [ Status ] ${colors3.red(`${colors3.white(` 404 `)}`)}`);
|
|
485
|
-
logger.error("The route do not exist.");
|
|
486
|
-
} else {
|
|
487
|
-
switch (res.statusCode) {
|
|
488
|
-
case 200:
|
|
489
|
-
switch (req.method) {
|
|
490
|
-
case "POST":
|
|
491
|
-
logger.info(`[ ${colors3.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgGreen(`${colors3.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgCyan(`${colors3.white(` 200 `)}`)}`);
|
|
492
|
-
break;
|
|
493
|
-
case "GET":
|
|
494
|
-
case "PUT":
|
|
495
|
-
logger.info(`[ ${colors3.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgGreen(`${colors3.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.bgCyan(`${colors3.white(` 200 `)}`)}`);
|
|
496
|
-
break;
|
|
497
|
-
case "DELETE":
|
|
498
|
-
logger.info(`[ ${colors3.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgGreen(`${colors3.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.bgCyan(`${colors3.white(` 200 `)}`)}`);
|
|
499
|
-
break;
|
|
500
|
-
}
|
|
501
|
-
break;
|
|
502
|
-
case 404:
|
|
503
|
-
switch (req.method) {
|
|
504
|
-
case "POST":
|
|
505
|
-
console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.red(`${colors3.white(` 404 `)}`)}`);
|
|
506
|
-
break;
|
|
507
|
-
case "GET":
|
|
508
|
-
console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 404 `)}`)}`);
|
|
509
|
-
break;
|
|
510
|
-
case "PUT":
|
|
511
|
-
console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 404 `)}`)}`);
|
|
512
|
-
break;
|
|
513
|
-
case "DELETE":
|
|
514
|
-
console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 404 `)}`)}`);
|
|
515
|
-
break;
|
|
516
|
-
}
|
|
517
|
-
break;
|
|
518
|
-
case 401:
|
|
519
|
-
switch (req.method) {
|
|
520
|
-
case "POST":
|
|
521
|
-
console.log(`[ ${colors3.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgYellowBright(`${colors3.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgYellow(`${colors3.bold(` 401 `)}`)}`);
|
|
522
|
-
break;
|
|
523
|
-
case "GET":
|
|
524
|
-
console.log(`[ ${colors3.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgYellowBright(`${colors3.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgYellow(`${colors3.bold(` 401 `)}`)}`);
|
|
525
|
-
break;
|
|
526
|
-
case "PUT":
|
|
527
|
-
console.log(`[ ${colors3.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgYellowBright(`${colors3.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgYellow(`${colors3.bold(` 401 `)}`)}`);
|
|
528
|
-
break;
|
|
529
|
-
case "DELETE":
|
|
530
|
-
console.log(`[ ${colors3.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgYellowBright(`${colors3.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.bgYellow(`${colors3.bold(` 401 `)}`)}`);
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
break;
|
|
534
|
-
case 500:
|
|
535
|
-
switch (req.method) {
|
|
536
|
-
case "POST":
|
|
537
|
-
console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.red(`${colors3.bold(` 500 `)}`)}`);
|
|
538
|
-
break;
|
|
539
|
-
case "GET":
|
|
540
|
-
console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 500 `)}`)}`);
|
|
541
|
-
break;
|
|
542
|
-
case "PUT":
|
|
543
|
-
console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 500 `)}`)}`);
|
|
544
|
-
break;
|
|
545
|
-
case "DELETE":
|
|
546
|
-
console.log(`[ ${colors3.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.bgRed(`${colors3.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors3.red(`${colors3.bold(` 500 `)}`)}`);
|
|
547
|
-
break;
|
|
548
|
-
}
|
|
549
|
-
break;
|
|
550
|
-
default:
|
|
551
|
-
console.log(`[ ${colors3.blueBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors3.blueBright(` ${res.statusMessage} `)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors3.blueBright(` ${res.req.socket._httpMessage.statusCode} `)}`);
|
|
552
|
-
break;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
|
|
557
71
|
// src/application/service/core.service.ts
|
|
558
|
-
import
|
|
559
|
-
import
|
|
72
|
+
import process2 from "node:process";
|
|
73
|
+
import chalk from "chalk";
|
|
560
74
|
import * as path from "path";
|
|
561
75
|
import * as fs from "fs";
|
|
562
|
-
import
|
|
76
|
+
import colors3 from "ansi-colors";
|
|
77
|
+
import { HttpStatusCode as status } from "opticore-http-response";
|
|
78
|
+
import { StackTraceError } from "opticore-catch-exception-error";
|
|
79
|
+
|
|
80
|
+
// src/core/helpers/modulesLoaded.utils.ts
|
|
81
|
+
import colors2 from "ansi-colors";
|
|
563
82
|
|
|
564
|
-
// src/core/
|
|
565
|
-
import
|
|
83
|
+
// src/core/helpers/logMessage.utils.ts
|
|
84
|
+
import colors from "ansi-colors";
|
|
566
85
|
|
|
567
|
-
// src/core/
|
|
568
|
-
|
|
86
|
+
// src/core/helpers/dateTimeFormatted.utils.ts
|
|
87
|
+
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()}`;
|
|
88
|
+
|
|
89
|
+
// src/core/helpers/logMessage.utils.ts
|
|
569
90
|
var LogMessageUtils = class {
|
|
570
91
|
static success(title, action, contentAction) {
|
|
571
|
-
console.log(`${
|
|
92
|
+
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 `)}`)}`);
|
|
572
93
|
}
|
|
573
94
|
static warning(title, action, contentAction) {
|
|
574
|
-
console.warn(`${
|
|
95
|
+
console.warn(`${colors.yellow(`\u26A0\uFE0F`)} ${colors.bgYellow(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgYellow(`${colors.white(` Warning `)}`)} ${contentAction}`);
|
|
575
96
|
}
|
|
576
97
|
static info(title, action, contentAction) {
|
|
577
|
-
console.info(`${
|
|
98
|
+
console.info(`${colors.cyan(`\u24D8`)} ${colors.bgCyan(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgCyan(`${colors.white(` Info `)}`)} ${contentAction}`);
|
|
578
99
|
}
|
|
579
100
|
static error(title, errorType, stackTrace, messageContent, httpCodeValue) {
|
|
580
|
-
console.error(`${
|
|
101
|
+
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} `)}`)} `);
|
|
581
102
|
}
|
|
582
103
|
static requestError(title, errorName, errorMessage, errorCode) {
|
|
583
|
-
console.error(`[ ${
|
|
104
|
+
console.error(`[ ${colors.red(`${title}`)} ] ${dateTimeFormattedUtils} | ${colors.bgRed(`${colors.white(` ERROR `)}`)} ${colors.red(`[ ${errorName} ]`)} ${colors.red(`${errorMessage}`)} - [ Status ] ${colors.bgRed(`${colors.white(` ${errorCode} `)}`)}`);
|
|
584
105
|
}
|
|
585
106
|
};
|
|
586
107
|
|
|
587
|
-
// src/core/
|
|
108
|
+
// src/core/helpers/modulesLoaded.utils.ts
|
|
109
|
+
import { CLocal, TranslationLoader } from "opticore-translator";
|
|
588
110
|
function modulesLoadedUtils(allAppRoutes, dbConChecker) {
|
|
589
|
-
LogMessageUtils.success(
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
111
|
+
LogMessageUtils.success(
|
|
112
|
+
`${TranslationLoader.t("kernel", CLocal)}`,
|
|
113
|
+
`${TranslationLoader.t("loadKernel", CLocal)}`,
|
|
114
|
+
`${TranslationLoader.t("moduleAppLoaded", CLocal)}`
|
|
115
|
+
);
|
|
116
|
+
console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", CLocal)}`)} ${colors2.green(`${TranslationLoader.t("kernel", CLocal)} :`)} ${colors2.cyan(`${colors2.bold(`${TranslationLoader.t("serverSide", CLocal)}`)}`)} ${TranslationLoader.t("hasBeenLoadedSuccessfully", CLocal)} ${colors2.green(`\u2714`)}`);
|
|
117
|
+
allAppRoutes ? console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", CLocal)}`)} ${colors2.green(`${TranslationLoader.t("kernel", CLocal)} :`)} ${colors2.cyan(`${colors2.bold(`${TranslationLoader.t("routerService", CLocal)}`)} `)} ${colors2.green(`\u2714`)}`) : console.log(`${colors2.red(`\u2718`)} ${colors2.bgRed(` ${colors2.bold(`${colors2.white(` ${TranslationLoader.t("registerRoutes", CLocal)} `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors2.red(`${colors2.bold(` ${TranslationLoader.t("fail", CLocal)} `)}`)} ] | [ ${colors2.bold(` ${TranslationLoader.t("loading", CLocal)} `)} ] - ${colors2.red(` ${TranslationLoader.t("routers", CLocal)} `)} - ${TranslationLoader.t("registerLoadingFailed", CLocal)} `);
|
|
118
|
+
typeof dbConChecker == "function" ? console.log(`${colors2.whiteBright(` ${TranslationLoader.t("content", CLocal)}`)} ${colors2.green(`${TranslationLoader.t("kernel", CLocal)} :`)} ${colors2.cyan(`${colors2.bold(`${TranslationLoader.t("dbConnChecker", CLocal)}`)}`)} ${TranslationLoader.t("hasBeenLoadedSuccessfully", CLocal)} ${colors2.green(`\u2714`)}`) : "";
|
|
593
119
|
}
|
|
594
120
|
|
|
595
121
|
// src/application/service/core.service.ts
|
|
122
|
+
import { CLocal as CLocal2, TranslationLoader as TranslationLoader2 } from "opticore-translator";
|
|
596
123
|
var CoreService = class {
|
|
597
124
|
/**
|
|
598
125
|
*
|
|
@@ -607,7 +134,7 @@ var CoreService = class {
|
|
|
607
134
|
* Returns an Object containing a node version, openssl, and v0
|
|
608
135
|
*/
|
|
609
136
|
getVersions() {
|
|
610
|
-
const { node, openssl, v8 } =
|
|
137
|
+
const { node, openssl, v8 } = process2.versions;
|
|
611
138
|
const data = {
|
|
612
139
|
"node version": node,
|
|
613
140
|
"openssl": openssl,
|
|
@@ -627,14 +154,14 @@ var CoreService = class {
|
|
|
627
154
|
* and Memory usage system
|
|
628
155
|
*/
|
|
629
156
|
getUsageMemory() {
|
|
630
|
-
const memoryData =
|
|
157
|
+
const memoryData = process2.memoryUsage();
|
|
631
158
|
const data = {
|
|
632
159
|
"Resident Set Size - total memory allocated for the process execution": this.formatMemoryUsage(memoryData.rss),
|
|
633
160
|
"Total size of the allocated heap": this.formatMemoryUsage(memoryData.heapTotal),
|
|
634
161
|
"Actual memory used during the execution": this.formatMemoryUsage(memoryData.heapUsed),
|
|
635
162
|
"V8 external memory": this.formatMemoryUsage(memoryData.external),
|
|
636
|
-
"Memory usage user": this.formatMemoryUsage(
|
|
637
|
-
"Memory usage system": this.formatMemoryUsage(
|
|
163
|
+
"Memory usage user": this.formatMemoryUsage(process2.cpuUsage().user),
|
|
164
|
+
"Memory usage system": this.formatMemoryUsage(process2.cpuUsage().system)
|
|
638
165
|
};
|
|
639
166
|
return {
|
|
640
167
|
"rss": data["Resident Set Size - total memory allocated for the process execution"],
|
|
@@ -649,11 +176,11 @@ var CoreService = class {
|
|
|
649
176
|
* Return an Object containing a project path and running server time
|
|
650
177
|
*/
|
|
651
178
|
getProjectInfo() {
|
|
652
|
-
const startTime =
|
|
653
|
-
const endTime =
|
|
179
|
+
const startTime = process2.hrtime();
|
|
180
|
+
const endTime = process2.hrtime(startTime);
|
|
654
181
|
const executionTime = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
655
182
|
return {
|
|
656
|
-
"projectPath": path.join(
|
|
183
|
+
"projectPath": path.join(process2.cwd()),
|
|
657
184
|
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
658
185
|
};
|
|
659
186
|
}
|
|
@@ -663,7 +190,7 @@ var CoreService = class {
|
|
|
663
190
|
* @private
|
|
664
191
|
*/
|
|
665
192
|
getEnvFileLoading(filePath) {
|
|
666
|
-
const fullPath = path.resolve(
|
|
193
|
+
const fullPath = path.resolve(process2.cwd(), filePath);
|
|
667
194
|
if (fs.existsSync(fullPath)) {
|
|
668
195
|
const env = fs.readFileSync(fullPath, "utf-8");
|
|
669
196
|
const lines = env.split("\n");
|
|
@@ -671,7 +198,7 @@ var CoreService = class {
|
|
|
671
198
|
const match = line.match(/^([^#=]+)=([^#]+)$/);
|
|
672
199
|
if (match) {
|
|
673
200
|
const key = match[1].trim();
|
|
674
|
-
|
|
201
|
+
process2.env[key] = match[2].trim();
|
|
675
202
|
}
|
|
676
203
|
});
|
|
677
204
|
}
|
|
@@ -683,35 +210,35 @@ var CoreService = class {
|
|
|
683
210
|
*/
|
|
684
211
|
getServerRunningMode(development, production) {
|
|
685
212
|
this.getEnvFileLoading(".env");
|
|
686
|
-
const isDevelopment =
|
|
213
|
+
const isDevelopment = process2.env.NODE_ENV === "development";
|
|
687
214
|
if (isDevelopment) {
|
|
688
|
-
return `The server is running in ${
|
|
215
|
+
return `The server is running in ${colors3.bgBlue(`${colors3.bold(`${development}`)}`)} mode`;
|
|
689
216
|
} else {
|
|
690
|
-
return `The server is running in ${
|
|
217
|
+
return `The server is running in ${colors3.bgBlue(`${colors3.bold(`${production}`)}`)} mode`;
|
|
691
218
|
}
|
|
692
219
|
}
|
|
693
220
|
infoServer(nodeVersion, startingTime, host, port, rss, heapUsed, user, system) {
|
|
694
221
|
const paddingLength = 52;
|
|
695
222
|
const msg0 = " ".padEnd(paddingLength, " ");
|
|
696
223
|
const msg1 = " [OK] Web server listening";
|
|
697
|
-
const msg2Value = `${
|
|
224
|
+
const msg2Value = `${colors3.bgBlue(`${colors3.bold(`${nodeVersion}`)}`)}`;
|
|
698
225
|
const msg2 = ` The Web server is using Node.js version`;
|
|
699
|
-
const msg3Value = `${
|
|
226
|
+
const msg3Value = `${colors3.bgBlue(`${colors3.bold(`${startingTime}`)}`)}`;
|
|
700
227
|
const msg3 = ` Startup time:`;
|
|
701
228
|
const msg4 = ` ${this.getServerRunningMode("development", "production")}`;
|
|
702
|
-
const msg5 = ` ${
|
|
703
|
-
console.log(
|
|
704
|
-
console.log(
|
|
705
|
-
console.log(
|
|
706
|
-
console.log(
|
|
707
|
-
console.log(
|
|
708
|
-
console.log(
|
|
709
|
-
console.log(
|
|
229
|
+
const msg5 = ` ${colors3.underline(`http://${host}:${port}`)}`;
|
|
230
|
+
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
231
|
+
console.log(chalk.bgGreen.white(msg1.padEnd(paddingLength, " ")));
|
|
232
|
+
console.log(chalk.bgGreen.white(msg2, msg2Value.padEnd(30.5, " ")));
|
|
233
|
+
console.log(chalk.bgGreen.white(msg3, msg3Value.padEnd(56, " ")));
|
|
234
|
+
console.log(chalk.bgGreen.white(msg4.padEnd(71, " ")));
|
|
235
|
+
console.log(chalk.bgGreen.white(msg5.padEnd(61, " ")));
|
|
236
|
+
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
710
237
|
console.log(``);
|
|
711
|
-
console.log(`${`Resident Set Size - total memory allocated for the process execution :`} ${
|
|
712
|
-
console.log(`${`Actual memory used during the execution :`} ${
|
|
713
|
-
console.log(`${`Memory usage by user :`} ${
|
|
714
|
-
console.log(`${`Memory usage by system :`} ${
|
|
238
|
+
console.log(`${`Resident Set Size - total memory allocated for the process execution :`} ${colors3.cyan(`${colors3.bold(`${rss}`)}`)}`);
|
|
239
|
+
console.log(`${`Actual memory used during the execution :`} ${colors3.cyan(`${colors3.bold(`${heapUsed}`)}`)}`);
|
|
240
|
+
console.log(`${`Memory usage by user :`} ${colors3.cyan(`${colors3.bold(`${user}`)}`)}`);
|
|
241
|
+
console.log(`${`Memory usage by system :`} ${colors3.cyan(`${colors3.bold(`${system}`)}`)}`);
|
|
715
242
|
console.log(``);
|
|
716
243
|
}
|
|
717
244
|
coreListenerEventLoaderModuleService(kernelModule) {
|
|
@@ -731,9 +258,9 @@ var CoreService = class {
|
|
|
731
258
|
})();
|
|
732
259
|
} else {
|
|
733
260
|
const stackTrace = new StackTraceError(
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
261
|
+
TranslationLoader2.t("loadedModulesError", CLocal2),
|
|
262
|
+
TranslationLoader2.t("loadedModules", CLocal2),
|
|
263
|
+
status.NOT_ACCEPTABLE,
|
|
737
264
|
true
|
|
738
265
|
);
|
|
739
266
|
throw new Error(stackTrace.message);
|
|
@@ -742,6 +269,9 @@ var CoreService = class {
|
|
|
742
269
|
};
|
|
743
270
|
|
|
744
271
|
// src/core/webServer.core.ts
|
|
272
|
+
import { TranslationLoader as TranslationLoader3 } from "opticore-translator";
|
|
273
|
+
import * as path2 from "path";
|
|
274
|
+
import process3 from "node:process";
|
|
745
275
|
var WebServerCore = class {
|
|
746
276
|
constructor(app, corsOriginOptions) {
|
|
747
277
|
this.serverUtility = new CoreService();
|
|
@@ -755,6 +285,7 @@ var WebServerCore = class {
|
|
|
755
285
|
this.expressApp.use(express2.urlencoded({ extended: true }));
|
|
756
286
|
this.expressApp.use(corsOrigin(corsOriginOptions));
|
|
757
287
|
this.stackTraceErrorHandling();
|
|
288
|
+
this.translationWebAppLoader();
|
|
758
289
|
}
|
|
759
290
|
onStartServer(routers) {
|
|
760
291
|
return this.expressApp.listen(
|
|
@@ -763,39 +294,39 @@ var WebServerCore = class {
|
|
|
763
294
|
() => {
|
|
764
295
|
try {
|
|
765
296
|
if (this.host === "" && this.port === 0) {
|
|
766
|
-
|
|
297
|
+
eventErrorOnListeningServer.hostPortUndefined();
|
|
767
298
|
} else if (this.host === "") {
|
|
768
|
-
|
|
299
|
+
eventErrorOnListeningServer.hostUndefined();
|
|
769
300
|
} else if (this.port === 0) {
|
|
770
|
-
|
|
301
|
+
eventErrorOnListeningServer.portUndefined();
|
|
771
302
|
} else {
|
|
772
303
|
this.registerRoutes(routers);
|
|
773
304
|
}
|
|
774
305
|
} catch (err) {
|
|
775
|
-
this.traceError(err.message, "Error",
|
|
306
|
+
this.traceError(err.message, "Error", HttpStatusCode.NOT_ACCEPTABLE);
|
|
776
307
|
}
|
|
777
308
|
}
|
|
778
309
|
);
|
|
779
310
|
}
|
|
780
311
|
onListeningOnServerEvent(serverWeb, kernelModule) {
|
|
781
|
-
serverWeb.on(
|
|
782
|
-
|
|
783
|
-
}).on(
|
|
784
|
-
|
|
785
|
-
}).on(
|
|
786
|
-
|
|
787
|
-
}).on(
|
|
312
|
+
serverWeb.on(eventName2.error, (err) => {
|
|
313
|
+
eventErrorOnListeningServer.onEventError(err);
|
|
314
|
+
}).on(eventName2.close, () => {
|
|
315
|
+
eventErrorOnListeningServer.serverClosing();
|
|
316
|
+
}).on(eventName2.drop, () => {
|
|
317
|
+
eventErrorOnListeningServer.dropNewConnection();
|
|
318
|
+
}).on(eventName2.listening, () => {
|
|
788
319
|
this.infoWebApp();
|
|
789
320
|
this.serverUtility.coreListenerEventLoaderModuleService(kernelModule);
|
|
790
321
|
});
|
|
791
322
|
}
|
|
792
323
|
onRequestOnServerEvent(serverWeb) {
|
|
793
|
-
serverWeb.on(
|
|
324
|
+
serverWeb.on(eventName2.request, (req, res) => {
|
|
794
325
|
requestCallsEvent(req, res, this.host, this.port, dateTimeFormattedUtils);
|
|
795
326
|
});
|
|
796
327
|
}
|
|
797
|
-
|
|
798
|
-
|
|
328
|
+
translationWebAppLoader() {
|
|
329
|
+
TranslationLoader3.loadTranslations(path2.join(process3.cwd(), "src", "utils", "translations"), getEnvVariable.defaultLocal);
|
|
799
330
|
}
|
|
800
331
|
registerRoutes(allFeatureRoutes) {
|
|
801
332
|
allFeatureRoutes.map((router) => {
|
|
@@ -819,45 +350,10 @@ var WebServerCore = class {
|
|
|
819
350
|
this.serverUtility.getUsageMemory().system
|
|
820
351
|
);
|
|
821
352
|
}
|
|
822
|
-
traceError(props, name,
|
|
823
|
-
return new
|
|
353
|
+
traceError(props, name, status2) {
|
|
354
|
+
return new StackTraceError2(props, name, status2, true);
|
|
824
355
|
}
|
|
825
356
|
};
|
|
826
|
-
|
|
827
|
-
// src/domains/constants/errorName.constant.ts
|
|
828
|
-
var CErrorName = {
|
|
829
|
-
evalError: "EvalError",
|
|
830
|
-
syntaxError: "SyntaxError",
|
|
831
|
-
rangeError: "RangeError",
|
|
832
|
-
referenceError: "ReferenceError",
|
|
833
|
-
typeError: "TypeError",
|
|
834
|
-
uriError: "URIError",
|
|
835
|
-
systemError: "SystemError",
|
|
836
|
-
assertionError: "AssertionError",
|
|
837
|
-
openSSLError: "OpenSSLError",
|
|
838
|
-
generalError: "GeneralError"
|
|
839
|
-
};
|
|
840
|
-
|
|
841
|
-
// src/domains/constants/event.constant.ts
|
|
842
|
-
var CEvent = {
|
|
843
|
-
beforeExit: "beforeExit",
|
|
844
|
-
disconnect: "disconnect",
|
|
845
|
-
exit: "exit",
|
|
846
|
-
rejectionHandled: "rejectionHandled",
|
|
847
|
-
uncaughtException: "uncaughtException",
|
|
848
|
-
uncaughtExceptionMonitor: "uncaughtExceptionMonitor",
|
|
849
|
-
unhandledRejection: "unhandledRejection",
|
|
850
|
-
warning: "warning",
|
|
851
|
-
message: "message",
|
|
852
|
-
multipleResolves: "multipleResolves",
|
|
853
|
-
worker: "worker",
|
|
854
|
-
sigint: "SIGINT",
|
|
855
|
-
sigterm: "SIGTERM"
|
|
856
|
-
};
|
|
857
357
|
export {
|
|
858
|
-
WebServerCore as WebServer
|
|
859
|
-
CErrorName as errorName,
|
|
860
|
-
CEvent as event,
|
|
861
|
-
CEventNameError as eventName,
|
|
862
|
-
getEnvVariable
|
|
358
|
+
WebServerCore as WebServer
|
|
863
359
|
};
|