opticore-webapp 1.0.8 → 1.0.9
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 +139 -599
- package/dist/index.d.cts +5 -63
- package/dist/index.d.ts +5 -63
- package/dist/index.js +146 -594
- package/package.json +7 -6
- package/src/application/service/core.service.ts +11 -8
- package/src/core/handlers/eventProcess.handler.ts +8 -5
- package/src/core/utils/logMessage.utils.ts +2 -2
- package/src/core/utils/modulesLoaded.utils.ts +5 -4
- package/src/core/webServer.core.ts +25 -21
- 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/tsup.config.ts +1 -1
- 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/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/dist/index.js
CHANGED
|
@@ -1,55 +1,118 @@
|
|
|
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";
|
|
16
|
+
import { express } from "opticore-express";
|
|
17
|
+
import {
|
|
18
|
+
ServerListenEventError,
|
|
19
|
+
CEventNameError as eventName,
|
|
20
|
+
CEvent as event
|
|
21
|
+
} from "opticore-catch-exception-error";
|
|
22
|
+
function eventProcessHandler() {
|
|
23
|
+
const errorEmitter = new EventEmitter();
|
|
24
|
+
const app = express();
|
|
25
|
+
errorEmitter.on(eventName.error, (error) => {
|
|
26
|
+
ServerListenEventError.listenerError(error);
|
|
27
|
+
});
|
|
28
|
+
process.on(event.beforeExit, (code) => {
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
ServerListenEventError.processBeforeExit(code);
|
|
31
|
+
}, 100);
|
|
32
|
+
});
|
|
33
|
+
process.on(event.disconnect, () => {
|
|
34
|
+
ServerListenEventError.processDisconnected();
|
|
35
|
+
});
|
|
36
|
+
process.on(event.exit, (code) => {
|
|
37
|
+
ServerListenEventError.exited(code);
|
|
38
|
+
});
|
|
39
|
+
process.on(event.rejectionHandled, (promise) => {
|
|
40
|
+
ServerListenEventError.promiseRejectionHandled(promise);
|
|
41
|
+
});
|
|
42
|
+
process.on(event.uncaughtException, (error) => {
|
|
43
|
+
ServerListenEventError.uncaughtException(error);
|
|
44
|
+
});
|
|
45
|
+
process.on(event.uncaughtExceptionMonitor, (error) => {
|
|
46
|
+
ServerListenEventError.uncaughtExceptionMonitor(error);
|
|
47
|
+
});
|
|
48
|
+
process.on(event.unhandledRejection, (reason, promise) => {
|
|
49
|
+
ServerListenEventError.unhandledRejection(reason, promise);
|
|
50
|
+
});
|
|
51
|
+
process.on(event.warning, (warning) => {
|
|
52
|
+
ServerListenEventError.warning(warning);
|
|
53
|
+
});
|
|
54
|
+
process.on(event.message, (message) => {
|
|
55
|
+
ServerListenEventError.message(message);
|
|
56
|
+
});
|
|
57
|
+
process.on(event.multipleResolves, (type, promise, reason) => {
|
|
58
|
+
ServerListenEventError.multipleResolves(type, promise, reason);
|
|
59
|
+
});
|
|
60
|
+
process.on(event.sigint, () => {
|
|
61
|
+
ServerListenEventError.processInterrupted();
|
|
62
|
+
});
|
|
63
|
+
process.on(event.sigterm, (signal) => {
|
|
64
|
+
ServerListenEventError.sigtermSignalReceived(signal);
|
|
65
|
+
});
|
|
66
|
+
app.use((err, req, res, next) => {
|
|
67
|
+
ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
42
70
|
|
|
43
|
-
// src/
|
|
44
|
-
import
|
|
45
|
-
import colors2 from "ansi-colors";
|
|
71
|
+
// src/application/service/core.service.ts
|
|
72
|
+
import process2 from "node:process";
|
|
46
73
|
import chalk from "chalk";
|
|
74
|
+
import * as path from "path";
|
|
75
|
+
import * as fs from "fs";
|
|
76
|
+
import colors4 from "ansi-colors";
|
|
77
|
+
import { HttpStatusCode as status } from "opticore-http-response";
|
|
78
|
+
import { StackTraceError } from "opticore-catch-exception-error";
|
|
79
|
+
|
|
80
|
+
// src/core/utils/modulesLoaded.utils.ts
|
|
81
|
+
import colors2 from "ansi-colors";
|
|
47
82
|
|
|
48
83
|
// src/core/utils/dateTimeFormatted.utils.ts
|
|
49
84
|
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
85
|
|
|
51
|
-
// src/
|
|
86
|
+
// src/core/utils/logMessage.utils.ts
|
|
52
87
|
import colors from "ansi-colors";
|
|
88
|
+
var LogMessageUtils = class {
|
|
89
|
+
static success(title, action, contentAction) {
|
|
90
|
+
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 `)}`)}`);
|
|
91
|
+
}
|
|
92
|
+
static warning(title, action, contentAction) {
|
|
93
|
+
console.warn(`${colors.yellow(`\u26A0\uFE0F`)} ${colors.bgYellow(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgYellow(`${colors.white(` Warning `)}`)} ${contentAction}`);
|
|
94
|
+
}
|
|
95
|
+
static info(title, action, contentAction) {
|
|
96
|
+
console.info(`${colors.cyan(`\u24D8`)} ${colors.bgCyan(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgCyan(`${colors.white(` Info `)}`)} ${contentAction}`);
|
|
97
|
+
}
|
|
98
|
+
static error(title, errorType, stackTrace, messageContent, httpCodeValue) {
|
|
99
|
+
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} `)}`)} `);
|
|
100
|
+
}
|
|
101
|
+
static requestError(title, errorName, errorMessage, errorCode) {
|
|
102
|
+
console.error(`[ ${colors.red(`${title}`)} ] ${dateTimeFormattedUtils} | ${colors.bgRed(`${colors.white(` ERROR `)}`)} ${colors.red(`[ ${errorName} ]`)} ${colors.red(`${errorMessage}`)} - [ Status ] ${colors.bgRed(`${colors.white(` ${errorCode} `)}`)}`);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// src/core/utils/modulesLoaded.utils.ts
|
|
107
|
+
function modulesLoadedUtils(allAppRoutes, dbConChecker) {
|
|
108
|
+
LogMessageUtils.success("Kernel", "load kernel", "Modules app have been successfully loaded");
|
|
109
|
+
console.log(`${colors2.whiteBright(` content`)} ${colors2.green("Kernel :")} ${colors2.cyan(`${colors2.bold(`server side`)}`)} has been loaded successfully ${colors2.green(`\u2714`)}`);
|
|
110
|
+
allAppRoutes ? console.log(`${colors2.whiteBright(` content`)} ${colors2.green("Kernel :")} ${colors2.cyan(`${colors2.bold(`Routers service`)} `)} has been loaded successfully ${colors2.green(`\u2714`)}`) : console.log(`${colors2.red(`\u2718`)} ${colors2.bgRed(` ${colors2.bold(`${colors2.white(` Register routes `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors2.red(`${colors2.bold(` fail `)}`)} ] | [ ${colors2.bold(` loading `)} ] - ${colors2.red(` routers `)} - The route register failed to load `);
|
|
111
|
+
typeof dbConChecker == "function" ? console.log(`${colors2.whiteBright(` content`)} ${colors2.green("Kernel :")} ${colors2.cyan(`${colors2.bold(`database checker connection`)}`)} has been loaded successfully ${colors2.green(`\u2714`)}`) : "";
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/application/exceptions/messages.exception.ts
|
|
115
|
+
import colors3 from "ansi-colors";
|
|
53
116
|
var messageException = {
|
|
54
117
|
dbConnection: "DataBase connection",
|
|
55
118
|
dbConnectionClosed: "MySQL connection is closed",
|
|
@@ -113,485 +176,9 @@ var messageException = {
|
|
|
113
176
|
errorHost: "The host can't be empty or blank. Please define a string host in .env",
|
|
114
177
|
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
178
|
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: ${
|
|
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
|
|
428
|
-
function eventProcessHandler() {
|
|
429
|
-
const errorEmitter = new EventEmitter();
|
|
430
|
-
const app = express();
|
|
431
|
-
errorEmitter.on(CEventNameError.error, (error) => {
|
|
432
|
-
ServerListenEventError.listenerError(error);
|
|
433
|
-
});
|
|
434
|
-
process2.on(CEvent.beforeExit, (code) => {
|
|
435
|
-
setTimeout(() => {
|
|
436
|
-
ServerListenEventError.processBeforeExit(code);
|
|
437
|
-
}, 100);
|
|
438
|
-
});
|
|
439
|
-
process2.on(CEvent.disconnect, () => {
|
|
440
|
-
ServerListenEventError.processDisconnected();
|
|
441
|
-
});
|
|
442
|
-
process2.on(CEvent.exit, (code) => {
|
|
443
|
-
ServerListenEventError.exited(code);
|
|
444
|
-
});
|
|
445
|
-
process2.on(CEvent.rejectionHandled, (promise) => {
|
|
446
|
-
ServerListenEventError.promiseRejectionHandled(promise);
|
|
447
|
-
});
|
|
448
|
-
process2.on(CEvent.uncaughtException, (error) => {
|
|
449
|
-
ServerListenEventError.uncaughtException(error);
|
|
450
|
-
});
|
|
451
|
-
process2.on(CEvent.uncaughtExceptionMonitor, (error) => {
|
|
452
|
-
ServerListenEventError.uncaughtExceptionMonitor(error);
|
|
453
|
-
});
|
|
454
|
-
process2.on(CEvent.unhandledRejection, (reason, promise) => {
|
|
455
|
-
ServerListenEventError.unhandledRejection(reason, promise);
|
|
456
|
-
});
|
|
457
|
-
process2.on(CEvent.warning, (warning) => {
|
|
458
|
-
ServerListenEventError.warning(warning);
|
|
459
|
-
});
|
|
460
|
-
process2.on(CEvent.message, (message) => {
|
|
461
|
-
ServerListenEventError.message(message);
|
|
462
|
-
});
|
|
463
|
-
process2.on(CEvent.multipleResolves, (type, promise, reason) => {
|
|
464
|
-
ServerListenEventError.multipleResolves(type, promise, reason);
|
|
465
|
-
});
|
|
466
|
-
process2.on(CEvent.sigint, () => {
|
|
467
|
-
ServerListenEventError.processInterrupted();
|
|
468
|
-
});
|
|
469
|
-
process2.on(CEvent.sigterm, (signal) => {
|
|
470
|
-
ServerListenEventError.sigtermSignalReceived(signal);
|
|
471
|
-
});
|
|
472
|
-
app.use((err, req, res, next) => {
|
|
473
|
-
ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
|
|
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
|
-
// src/application/service/core.service.ts
|
|
558
|
-
import process3 from "node:process";
|
|
559
|
-
import chalk2 from "chalk";
|
|
560
|
-
import * as path from "path";
|
|
561
|
-
import * as fs from "fs";
|
|
562
|
-
import colors6 from "ansi-colors";
|
|
563
|
-
|
|
564
|
-
// src/core/utils/modulesLoaded.utils.ts
|
|
565
|
-
import colors5 from "ansi-colors";
|
|
566
|
-
|
|
567
|
-
// src/core/utils/logMessage.utils.ts
|
|
568
|
-
import colors4 from "ansi-colors";
|
|
569
|
-
var LogMessageUtils = class {
|
|
570
|
-
static success(title, action, contentAction) {
|
|
571
|
-
console.log(`${colors4.green(`\u2714`)} ${colors4.bgGreen(` ${colors4.bold(`${colors4.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors4.bgGreen(`${colors4.white(` Success `)}`)} [ ${action} ] ${contentAction} - [ Status ] ${colors4.bgGreen(`${colors4.white(` 200 `)}`)}`);
|
|
572
|
-
}
|
|
573
|
-
static warning(title, action, contentAction) {
|
|
574
|
-
console.warn(`${colors4.yellow(`\u26A0\uFE0F`)} ${colors4.bgYellow(` ${colors4.bold(`${colors4.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors4.bgYellow(`${colors4.white(` Warning `)}`)} ${contentAction}`);
|
|
575
|
-
}
|
|
576
|
-
static info(title, action, contentAction) {
|
|
577
|
-
console.info(`${colors4.cyan(`\u24D8`)} ${colors4.bgCyan(` ${colors4.bold(`${colors4.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors4.bgCyan(`${colors4.white(` Info `)}`)} ${contentAction}`);
|
|
578
|
-
}
|
|
579
|
-
static error(title, errorType, stackTrace, messageContent, httpCodeValue) {
|
|
580
|
-
console.error(`${colors4.red(`\u2718`)} ${colors4.bgRed(` ${colors4.bold(`${colors4.white(`${title}`)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors4.red(`${colors4.bold(` ${errorType} `)}`)} ] | [ ${colors4.bold(`stack trace`)} ] ${colors4.red(`${stackTrace}`)} - ${colors4.red(`${messageContent}`)} - [ ${colors4.red(`${colors4.bold(` HttpCode `)}`)} ] ${colors4.red(`${colors4.bold(` ${httpCodeValue} `)}`)} `);
|
|
581
|
-
}
|
|
582
|
-
static requestError(title, errorName, errorMessage, errorCode) {
|
|
583
|
-
console.error(`[ ${colors4.red(`${title}`)} ] ${dateTimeFormattedUtils} | ${colors4.bgRed(`${colors4.white(` ERROR `)}`)} ${colors4.red(`[ ${errorName} ]`)} ${colors4.red(`${errorMessage}`)} - [ Status ] ${colors4.bgRed(`${colors4.white(` ${errorCode} `)}`)}`);
|
|
584
|
-
}
|
|
179
|
+
errorDBHost: (host) => `A database host ${host} does not allow connection. Please either set the host like this: ${colors3.bgRed(`${colors3.white(`localhost`)}`)} in your .env file`
|
|
585
180
|
};
|
|
586
181
|
|
|
587
|
-
// src/core/utils/modulesLoaded.utils.ts
|
|
588
|
-
function modulesLoadedUtils(allAppRoutes, dbConChecker) {
|
|
589
|
-
LogMessageUtils.success("Kernel", "load kernel", "Modules app have been successfully loaded");
|
|
590
|
-
console.log(`${colors5.whiteBright(` content`)} ${colors5.green("Kernel :")} ${colors5.cyan(`${colors5.bold(`server side`)}`)} has been loaded successfully ${colors5.green(`\u2714`)}`);
|
|
591
|
-
allAppRoutes ? console.log(`${colors5.whiteBright(` content`)} ${colors5.green("Kernel :")} ${colors5.cyan(`${colors5.bold(`Routers service`)} `)} has been loaded successfully ${colors5.green(`\u2714`)}`) : console.log(`${colors5.red(`\u2718`)} ${colors5.bgRed(` ${colors5.bold(`${colors5.white(` Register routes `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors5.red(`${colors5.bold(` fail `)}`)} ] | [ ${colors5.bold(` loading `)} ] - ${colors5.red(` routers `)} - The route register failed to load `);
|
|
592
|
-
typeof dbConChecker == "function" ? console.log(`${colors5.whiteBright(` content`)} ${colors5.green("Kernel :")} ${colors5.cyan(`${colors5.bold(`database checker connection`)}`)} has been loaded successfully ${colors5.green(`\u2714`)}`) : "";
|
|
593
|
-
}
|
|
594
|
-
|
|
595
182
|
// src/application/service/core.service.ts
|
|
596
183
|
var CoreService = class {
|
|
597
184
|
/**
|
|
@@ -607,7 +194,7 @@ var CoreService = class {
|
|
|
607
194
|
* Returns an Object containing a node version, openssl, and v0
|
|
608
195
|
*/
|
|
609
196
|
getVersions() {
|
|
610
|
-
const { node, openssl, v8 } =
|
|
197
|
+
const { node, openssl, v8 } = process2.versions;
|
|
611
198
|
const data = {
|
|
612
199
|
"node version": node,
|
|
613
200
|
"openssl": openssl,
|
|
@@ -627,14 +214,14 @@ var CoreService = class {
|
|
|
627
214
|
* and Memory usage system
|
|
628
215
|
*/
|
|
629
216
|
getUsageMemory() {
|
|
630
|
-
const memoryData =
|
|
217
|
+
const memoryData = process2.memoryUsage();
|
|
631
218
|
const data = {
|
|
632
219
|
"Resident Set Size - total memory allocated for the process execution": this.formatMemoryUsage(memoryData.rss),
|
|
633
220
|
"Total size of the allocated heap": this.formatMemoryUsage(memoryData.heapTotal),
|
|
634
221
|
"Actual memory used during the execution": this.formatMemoryUsage(memoryData.heapUsed),
|
|
635
222
|
"V8 external memory": this.formatMemoryUsage(memoryData.external),
|
|
636
|
-
"Memory usage user": this.formatMemoryUsage(
|
|
637
|
-
"Memory usage system": this.formatMemoryUsage(
|
|
223
|
+
"Memory usage user": this.formatMemoryUsage(process2.cpuUsage().user),
|
|
224
|
+
"Memory usage system": this.formatMemoryUsage(process2.cpuUsage().system)
|
|
638
225
|
};
|
|
639
226
|
return {
|
|
640
227
|
"rss": data["Resident Set Size - total memory allocated for the process execution"],
|
|
@@ -649,11 +236,11 @@ var CoreService = class {
|
|
|
649
236
|
* Return an Object containing a project path and running server time
|
|
650
237
|
*/
|
|
651
238
|
getProjectInfo() {
|
|
652
|
-
const startTime =
|
|
653
|
-
const endTime =
|
|
239
|
+
const startTime = process2.hrtime();
|
|
240
|
+
const endTime = process2.hrtime(startTime);
|
|
654
241
|
const executionTime = (endTime[0] * 1e9 + endTime[1]) / 1e6;
|
|
655
242
|
return {
|
|
656
|
-
"projectPath": path.join(
|
|
243
|
+
"projectPath": path.join(process2.cwd()),
|
|
657
244
|
"startingTime": `${executionTime.toFixed(5)} ms`
|
|
658
245
|
};
|
|
659
246
|
}
|
|
@@ -663,7 +250,7 @@ var CoreService = class {
|
|
|
663
250
|
* @private
|
|
664
251
|
*/
|
|
665
252
|
getEnvFileLoading(filePath) {
|
|
666
|
-
const fullPath = path.resolve(
|
|
253
|
+
const fullPath = path.resolve(process2.cwd(), filePath);
|
|
667
254
|
if (fs.existsSync(fullPath)) {
|
|
668
255
|
const env = fs.readFileSync(fullPath, "utf-8");
|
|
669
256
|
const lines = env.split("\n");
|
|
@@ -671,7 +258,7 @@ var CoreService = class {
|
|
|
671
258
|
const match = line.match(/^([^#=]+)=([^#]+)$/);
|
|
672
259
|
if (match) {
|
|
673
260
|
const key = match[1].trim();
|
|
674
|
-
|
|
261
|
+
process2.env[key] = match[2].trim();
|
|
675
262
|
}
|
|
676
263
|
});
|
|
677
264
|
}
|
|
@@ -683,35 +270,35 @@ var CoreService = class {
|
|
|
683
270
|
*/
|
|
684
271
|
getServerRunningMode(development, production) {
|
|
685
272
|
this.getEnvFileLoading(".env");
|
|
686
|
-
const isDevelopment =
|
|
273
|
+
const isDevelopment = process2.env.NODE_ENV === "development";
|
|
687
274
|
if (isDevelopment) {
|
|
688
|
-
return `The server is running in ${
|
|
275
|
+
return `The server is running in ${colors4.bgBlue(`${colors4.bold(`${development}`)}`)} mode`;
|
|
689
276
|
} else {
|
|
690
|
-
return `The server is running in ${
|
|
277
|
+
return `The server is running in ${colors4.bgBlue(`${colors4.bold(`${production}`)}`)} mode`;
|
|
691
278
|
}
|
|
692
279
|
}
|
|
693
280
|
infoServer(nodeVersion, startingTime, host, port, rss, heapUsed, user, system) {
|
|
694
281
|
const paddingLength = 52;
|
|
695
282
|
const msg0 = " ".padEnd(paddingLength, " ");
|
|
696
283
|
const msg1 = " [OK] Web server listening";
|
|
697
|
-
const msg2Value = `${
|
|
284
|
+
const msg2Value = `${colors4.bgBlue(`${colors4.bold(`${nodeVersion}`)}`)}`;
|
|
698
285
|
const msg2 = ` The Web server is using Node.js version`;
|
|
699
|
-
const msg3Value = `${
|
|
286
|
+
const msg3Value = `${colors4.bgBlue(`${colors4.bold(`${startingTime}`)}`)}`;
|
|
700
287
|
const msg3 = ` Startup time:`;
|
|
701
288
|
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(
|
|
289
|
+
const msg5 = ` ${colors4.underline(`http://${host}:${port}`)}`;
|
|
290
|
+
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
291
|
+
console.log(chalk.bgGreen.white(msg1.padEnd(paddingLength, " ")));
|
|
292
|
+
console.log(chalk.bgGreen.white(msg2, msg2Value.padEnd(30.5, " ")));
|
|
293
|
+
console.log(chalk.bgGreen.white(msg3, msg3Value.padEnd(56, " ")));
|
|
294
|
+
console.log(chalk.bgGreen.white(msg4.padEnd(71, " ")));
|
|
295
|
+
console.log(chalk.bgGreen.white(msg5.padEnd(61, " ")));
|
|
296
|
+
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
710
297
|
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 :`} ${
|
|
298
|
+
console.log(`${`Resident Set Size - total memory allocated for the process execution :`} ${colors4.cyan(`${colors4.bold(`${rss}`)}`)}`);
|
|
299
|
+
console.log(`${`Actual memory used during the execution :`} ${colors4.cyan(`${colors4.bold(`${heapUsed}`)}`)}`);
|
|
300
|
+
console.log(`${`Memory usage by user :`} ${colors4.cyan(`${colors4.bold(`${user}`)}`)}`);
|
|
301
|
+
console.log(`${`Memory usage by system :`} ${colors4.cyan(`${colors4.bold(`${system}`)}`)}`);
|
|
715
302
|
console.log(``);
|
|
716
303
|
}
|
|
717
304
|
coreListenerEventLoaderModuleService(kernelModule) {
|
|
@@ -733,7 +320,7 @@ var CoreService = class {
|
|
|
733
320
|
const stackTrace = new StackTraceError(
|
|
734
321
|
messageException.loadedModulesError,
|
|
735
322
|
messageException.loadedModules,
|
|
736
|
-
|
|
323
|
+
status.NOT_ACCEPTABLE,
|
|
737
324
|
true
|
|
738
325
|
);
|
|
739
326
|
throw new Error(stackTrace.message);
|
|
@@ -763,34 +350,34 @@ var WebServerCore = class {
|
|
|
763
350
|
() => {
|
|
764
351
|
try {
|
|
765
352
|
if (this.host === "" && this.port === 0) {
|
|
766
|
-
|
|
353
|
+
eventErrorOnListeningServer.hostPortUndefined();
|
|
767
354
|
} else if (this.host === "") {
|
|
768
|
-
|
|
355
|
+
eventErrorOnListeningServer.hostUndefined();
|
|
769
356
|
} else if (this.port === 0) {
|
|
770
|
-
|
|
357
|
+
eventErrorOnListeningServer.portUndefined();
|
|
771
358
|
} else {
|
|
772
359
|
this.registerRoutes(routers);
|
|
773
360
|
}
|
|
774
361
|
} catch (err) {
|
|
775
|
-
this.traceError(err.message, "Error",
|
|
362
|
+
this.traceError(err.message, "Error", HttpStatusCode.NOT_ACCEPTABLE);
|
|
776
363
|
}
|
|
777
364
|
}
|
|
778
365
|
);
|
|
779
366
|
}
|
|
780
367
|
onListeningOnServerEvent(serverWeb, kernelModule) {
|
|
781
|
-
serverWeb.on(
|
|
782
|
-
|
|
783
|
-
}).on(
|
|
784
|
-
|
|
785
|
-
}).on(
|
|
786
|
-
|
|
787
|
-
}).on(
|
|
368
|
+
serverWeb.on(eventName2.error, (err) => {
|
|
369
|
+
eventErrorOnListeningServer.onEventError(err);
|
|
370
|
+
}).on(eventName2.close, () => {
|
|
371
|
+
eventErrorOnListeningServer.serverClosing();
|
|
372
|
+
}).on(eventName2.drop, () => {
|
|
373
|
+
eventErrorOnListeningServer.dropNewConnection();
|
|
374
|
+
}).on(eventName2.listening, () => {
|
|
788
375
|
this.infoWebApp();
|
|
789
376
|
this.serverUtility.coreListenerEventLoaderModuleService(kernelModule);
|
|
790
377
|
});
|
|
791
378
|
}
|
|
792
379
|
onRequestOnServerEvent(serverWeb) {
|
|
793
|
-
serverWeb.on(
|
|
380
|
+
serverWeb.on(eventName2.request, (req, res) => {
|
|
794
381
|
requestCallsEvent(req, res, this.host, this.port, dateTimeFormattedUtils);
|
|
795
382
|
});
|
|
796
383
|
}
|
|
@@ -819,45 +406,10 @@ var WebServerCore = class {
|
|
|
819
406
|
this.serverUtility.getUsageMemory().system
|
|
820
407
|
);
|
|
821
408
|
}
|
|
822
|
-
traceError(props, name,
|
|
823
|
-
return new
|
|
409
|
+
traceError(props, name, status2) {
|
|
410
|
+
return new StackTraceError2(props, name, status2, true);
|
|
824
411
|
}
|
|
825
412
|
};
|
|
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
413
|
export {
|
|
858
|
-
WebServerCore as WebServer
|
|
859
|
-
CErrorName as errorName,
|
|
860
|
-
CEvent as event,
|
|
861
|
-
CEventNameError as eventName,
|
|
862
|
-
getEnvVariable
|
|
414
|
+
WebServerCore as WebServer
|
|
863
415
|
};
|