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
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import process from "process";
|
|
2
|
-
import colors from "ansi-colors";
|
|
3
|
-
import express from "express";
|
|
4
|
-
import chalk from "chalk";
|
|
5
|
-
import StackTraceError from "@webApp/core/handlers/errors/base/stackTraceError";
|
|
6
|
-
import {HttpStatusCodesConstant as status} from "@webApp/domains/constants/httpStatusCodes.constant";
|
|
7
|
-
import {LogMessageUtils} from "@webApp/core/utils/logMessage.utils";
|
|
8
|
-
import {dateTimeFormattedUtils as currentDate} from "@webApp/core/utils/dateTimeFormatted.utils";
|
|
9
|
-
import {messageException as msg} from "@webApp/application/exceptions/messages.exception";
|
|
10
|
-
import {CEventNameError as eventName} from "@webApp/domains/constants/eventNameError.constant";
|
|
11
|
-
import {LoggerCore} from "opticore-logger";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export class ServerListenEventError {
|
|
15
|
-
private static logger: LoggerCore = new LoggerCore();
|
|
16
|
-
private static stackTrace: StackTraceError;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
*/
|
|
21
|
-
static hostPortUndefined(): void {
|
|
22
|
-
this.stackTrace = this.traceError(msg.errorHostUrl, msg.listening, status.BAD_REQUEST);
|
|
23
|
-
this.logger.error(this.stackTrace.message, msg.webServer, msg.badHost, this.stackTrace.stack, status.BAD_REQUEST);
|
|
24
|
-
process.exit();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
*
|
|
29
|
-
*/
|
|
30
|
-
static hostUndefined(): void {
|
|
31
|
-
this.stackTrace = this.traceError(msg.badHost, msg.listening, status.BAD_REQUEST);
|
|
32
|
-
this.logger.error(this.stackTrace.message, msg.webServer, msg.badHost, this.stackTrace.stack, status.BAD_REQUEST);
|
|
33
|
-
process.exit();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
*/
|
|
39
|
-
static portUndefined(): void {
|
|
40
|
-
this.stackTrace = this.traceError(msg.badPort, msg.listening, status.BAD_REQUEST);
|
|
41
|
-
this.logger.error(this.stackTrace.message, msg.webServer, msg.badHost, this.stackTrace.stack, status.BAD_REQUEST);
|
|
42
|
-
process.exit();
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* @param err
|
|
48
|
-
*/
|
|
49
|
-
static onEventError(err: Error): void {
|
|
50
|
-
this.logger.error(err.message, "Server start error", "Error", err.stack, status.SERVICE_UNAVAILABLE);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
*
|
|
55
|
-
* @param error
|
|
56
|
-
*/
|
|
57
|
-
static listenerError(error: Error): void {
|
|
58
|
-
this.stackTrace = this.traceError(error.message, error.name, status.BAD_REQUEST);
|
|
59
|
-
this.logger.error(this.stackTrace.message, "Event error", "Error", error.stack, status.BAD_REQUEST);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
* @param code
|
|
65
|
-
*/
|
|
66
|
-
static processBeforeExit(code: number): void {
|
|
67
|
-
this.stackTrace = this.traceError(`Process will exit with code: ${code}`, "BeforeExit", status.SERVICE_UNAVAILABLE);
|
|
68
|
-
this.logger.error(this.stackTrace.message, "BeforeExit", "process before exit", this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
69
|
-
process.exit(code);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
*
|
|
74
|
-
*/
|
|
75
|
-
static processDisconnected(): void {
|
|
76
|
-
this.stackTrace = this.traceError("Child process disconnected", "process disconnected", status.SERVICE_UNAVAILABLE);
|
|
77
|
-
this.logger.error(this.stackTrace.message, "Disconnected", "process disconnected", this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
78
|
-
process.exit();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
*
|
|
83
|
-
* @param code
|
|
84
|
-
*/
|
|
85
|
-
static exited(code: number){
|
|
86
|
-
switch (code) {
|
|
87
|
-
case 0:
|
|
88
|
-
this.logger.success("completed", "The process finished as expected and everything is ok");
|
|
89
|
-
console.log("");
|
|
90
|
-
const paddingLength: number = 35;
|
|
91
|
-
const msg0: string = ' '.padEnd(paddingLength, ' ');
|
|
92
|
-
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, ' ')));
|
|
93
|
-
console.log(`${colors.bgGreen(` [OK] The server shutting down `)}`);
|
|
94
|
-
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, ' ')));
|
|
95
|
-
break;
|
|
96
|
-
case 1:
|
|
97
|
-
this.stackTrace = this.traceError("Something went wrong", "General Errors", status.SERVICE_UNAVAILABLE);
|
|
98
|
-
this.logger.error(this.stackTrace.message, "Exited", "General Errors", this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
99
|
-
break
|
|
100
|
-
case 2:
|
|
101
|
-
this.stackTrace = this.traceError("Incorrect using of shell commands", "Misuse of shell builtins", status.SERVICE_UNAVAILABLE);
|
|
102
|
-
this.logger.error(this.stackTrace.message, "Exited", "Incorrect using of shell commands", this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
103
|
-
break;
|
|
104
|
-
case 126:
|
|
105
|
-
this.stackTrace = this.traceError(
|
|
106
|
-
"Incorrect using of shell commands",
|
|
107
|
-
"The command is found but is not executable (e.g., trying to execute a directory)",
|
|
108
|
-
status.SERVICE_UNAVAILABLE
|
|
109
|
-
);
|
|
110
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
111
|
-
break
|
|
112
|
-
case 127:
|
|
113
|
-
this.stackTrace = this.traceError(
|
|
114
|
-
"Command not found",
|
|
115
|
-
"The command was not found in the system's PATH or is misspelled",
|
|
116
|
-
status.SERVICE_UNAVAILABLE
|
|
117
|
-
);
|
|
118
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
119
|
-
break;
|
|
120
|
-
case 128:
|
|
121
|
-
this.stackTrace = this.traceError(
|
|
122
|
-
"The command was not found in the system's PATH or is misspelled",
|
|
123
|
-
"Invalid argument",
|
|
124
|
-
status.SERVICE_UNAVAILABLE
|
|
125
|
-
);
|
|
126
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
127
|
-
break;
|
|
128
|
-
case 130:
|
|
129
|
-
this.stackTrace = this.traceError(
|
|
130
|
-
"Indicates that the script was manually terminated by the user using the Control-C (SIGINT) signal",
|
|
131
|
-
"Script terminated",
|
|
132
|
-
status.SERVICE_UNAVAILABLE
|
|
133
|
-
);
|
|
134
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
135
|
-
break;
|
|
136
|
-
case 137:
|
|
137
|
-
this.stackTrace = this.traceError(
|
|
138
|
-
"Indicates that the process was terminated by a SIGKILL signal, possibly due to an out-of-memory situation",
|
|
139
|
-
"SIGKILL",
|
|
140
|
-
status.SERVICE_UNAVAILABLE
|
|
141
|
-
);
|
|
142
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
143
|
-
break;
|
|
144
|
-
case 139:
|
|
145
|
-
this.stackTrace = this.traceError(
|
|
146
|
-
"Indicates that the process accessed an illegal memory address (segfault)",
|
|
147
|
-
"Segmentation fault",
|
|
148
|
-
status.SERVICE_UNAVAILABLE
|
|
149
|
-
);
|
|
150
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
151
|
-
break;
|
|
152
|
-
case 143:
|
|
153
|
-
this.stackTrace = this.traceError(
|
|
154
|
-
"Indicates that the process received a SIGTERM signal to terminate",
|
|
155
|
-
"process received a SIGTERM",
|
|
156
|
-
status.SERVICE_UNAVAILABLE
|
|
157
|
-
);
|
|
158
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
159
|
-
break;
|
|
160
|
-
case 255:
|
|
161
|
-
this.stackTrace = this.traceError(
|
|
162
|
-
"An exit code that is outside the allowable range (0-255 for Unix-like systems)",
|
|
163
|
-
"out of range",
|
|
164
|
-
status.SERVICE_UNAVAILABLE
|
|
165
|
-
);
|
|
166
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
167
|
-
break;
|
|
168
|
-
default:
|
|
169
|
-
this.stackTrace = this.traceError(
|
|
170
|
-
"Error is occurring",
|
|
171
|
-
"errors",
|
|
172
|
-
status.SERVICE_UNAVAILABLE
|
|
173
|
-
);
|
|
174
|
-
this.logger.error(this.stackTrace.message, "Exited", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
*
|
|
181
|
-
* @param promise
|
|
182
|
-
*/
|
|
183
|
-
static promiseRejectionHandled(promise: Promise<any>): void {
|
|
184
|
-
this.stackTrace = this.traceError(
|
|
185
|
-
`Promise rejection is handled at : ${promise}`,
|
|
186
|
-
"rejection promise",
|
|
187
|
-
status.SERVICE_UNAVAILABLE
|
|
188
|
-
);
|
|
189
|
-
this.logger.error(this.stackTrace.message, "PromiseRejectionHandled", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
*
|
|
194
|
-
* @param error
|
|
195
|
-
*/
|
|
196
|
-
static uncaughtException(error: any): void {
|
|
197
|
-
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.') {
|
|
198
|
-
console.log("");
|
|
199
|
-
} else {
|
|
200
|
-
this.stackTrace = this.traceError(error.message, "uncaught exception handled", status.SERVICE_UNAVAILABLE);
|
|
201
|
-
this.logger.error(this.stackTrace.message, "UncaughtException", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
*
|
|
207
|
-
* @param error
|
|
208
|
-
*/
|
|
209
|
-
static uncaughtExceptionMonitor(error: any): void {
|
|
210
|
-
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.') {
|
|
211
|
-
console.log("");
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
*
|
|
217
|
-
* @param reason
|
|
218
|
-
* @param promise
|
|
219
|
-
*/
|
|
220
|
-
static unhandledRejection(reason: any, promise: Promise<any>): void{
|
|
221
|
-
this.stackTrace = this.traceError(
|
|
222
|
-
`Unhandled Rejection at: Promise ${promise} -- reason ${reason}`,
|
|
223
|
-
"Unhandled rejection",
|
|
224
|
-
status.SERVICE_UNAVAILABLE
|
|
225
|
-
);
|
|
226
|
-
this.logger.error(this.stackTrace.message, "UnhandledRejection", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
*
|
|
231
|
-
* @param warning
|
|
232
|
-
*/
|
|
233
|
-
static warning(warning: any): void {
|
|
234
|
-
this.stackTrace = this.traceError(warning.message, "warning", status.SERVICE_UNAVAILABLE);
|
|
235
|
-
this.logger.error(this.stackTrace.message, "Warning", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
*
|
|
240
|
-
* @param message
|
|
241
|
-
*/
|
|
242
|
-
static message(message: any): void {
|
|
243
|
-
this.stackTrace = this.traceError(
|
|
244
|
-
`process got message ${message}`,
|
|
245
|
-
"message exception",
|
|
246
|
-
status.SERVICE_UNAVAILABLE
|
|
247
|
-
);
|
|
248
|
-
this.logger.error(this.stackTrace.message, "Message", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
*
|
|
253
|
-
* @param type
|
|
254
|
-
* @param promise
|
|
255
|
-
* @param reason
|
|
256
|
-
*/
|
|
257
|
-
static multipleResolves(type: string, promise: Promise<any>, reason: any): void {
|
|
258
|
-
this.stackTrace = this.traceError(
|
|
259
|
-
`${promise} -- ${reason}`,
|
|
260
|
-
`Multiple resolves detected : ${type}`,
|
|
261
|
-
status.SERVICE_UNAVAILABLE
|
|
262
|
-
);
|
|
263
|
-
this.logger.error(this.stackTrace.message, "multipleResolves", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
*
|
|
268
|
-
*/
|
|
269
|
-
static processInterrupted(): void {
|
|
270
|
-
this.logger.success("[ OK ] Success", "The Web server has been stopped !")
|
|
271
|
-
process.exit(0);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
*
|
|
276
|
-
* @param signal
|
|
277
|
-
*/
|
|
278
|
-
static sigtermSignalReceived(signal: any): void {
|
|
279
|
-
this.stackTrace = this.traceError(
|
|
280
|
-
`Process ${process.pid} received a SIGTERM signal : ${signal.toString()}`,
|
|
281
|
-
"SIGTERM",
|
|
282
|
-
status.NOT_ACCEPTABLE
|
|
283
|
-
);
|
|
284
|
-
this.logger.error(this.stackTrace.message, "SIGTERM", this.stackTrace.name, this.stackTrace.stack, status.NOT_ACCEPTABLE);
|
|
285
|
-
process.exit(0);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
*
|
|
290
|
-
*/
|
|
291
|
-
static serverClosing(): void {
|
|
292
|
-
console.log(`${colors.bgCyanBright(` ${colors.bold(`${colors.white(` INFO `)}`)}`)} All processes are stopped`);
|
|
293
|
-
console.log(" Server is closed");
|
|
294
|
-
process.exit();
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
*
|
|
299
|
-
*/
|
|
300
|
-
static dropNewConnection(): void {
|
|
301
|
-
console.log(`${colors.cyan(`ⓘ`)} ${colors.bgCyan(` ${colors.bold(`${colors.white(` Server maxConnection `)}`)} `)} ${currentDate} | ${colors.bgCyan(`${colors.white(` Info `)}`)} The server dropped new connections`);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
*
|
|
306
|
-
* @param errorEmitter
|
|
307
|
-
* @param err
|
|
308
|
-
* @param req
|
|
309
|
-
* @param res
|
|
310
|
-
* @param next
|
|
311
|
-
*/
|
|
312
|
-
static expressErrorHandlingMiddleware(errorEmitter: any,
|
|
313
|
-
err: Error,
|
|
314
|
-
req: express.Request,
|
|
315
|
-
res: express.Response,
|
|
316
|
-
next: express.NextFunction): void {
|
|
317
|
-
if (err) {
|
|
318
|
-
errorEmitter.emit(eventName.error, err);
|
|
319
|
-
if (typeof res.status === 'function') {
|
|
320
|
-
res.status(500).send('Internal Server Error');
|
|
321
|
-
} else {
|
|
322
|
-
console.error('res.status is not a function');
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
this.stackTrace = this.traceError(err.message, "Express error", status.NOT_ACCEPTABLE);
|
|
326
|
-
this.logger.error(this.stackTrace.message, "Express error-handling middleware", this.stackTrace.name, this.stackTrace.stack, status.SERVICE_UNAVAILABLE);
|
|
327
|
-
} else {
|
|
328
|
-
next();
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
private static traceError(props: string, name: string, status: number): StackTraceError {
|
|
333
|
-
return new StackTraceError(props, name, status, true);
|
|
334
|
-
}
|
|
335
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import colors from "ansi-colors";
|
|
2
|
-
import {IncomingMessage, ServerResponse} from "node:http";
|
|
3
|
-
import {LoggerCore} from "opticore-logger";
|
|
4
|
-
|
|
5
|
-
export function requestCallsEvent(req: IncomingMessage, res: ServerResponse, host: string, port: number, loadingTime: any) {
|
|
6
|
-
const logger: LoggerCore = new LoggerCore();
|
|
7
|
-
|
|
8
|
-
const currentDatePath: string = `Request called`;
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
if(req.originalUrl === "undefined") {
|
|
11
|
-
console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] The route do not exist. - [ Status ] ${colors.red(`${colors.white(` 404 `)}`)}`);
|
|
12
|
-
logger.error("The route do not exist.");
|
|
13
|
-
} else {
|
|
14
|
-
switch (res.statusCode) {
|
|
15
|
-
case 200:
|
|
16
|
-
switch (req.method) {
|
|
17
|
-
case 'POST': // @ts-ignore
|
|
18
|
-
logger.info(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`);
|
|
19
|
-
break;
|
|
20
|
-
case 'GET':
|
|
21
|
-
case 'PUT': // @ts-ignore
|
|
22
|
-
logger.info(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`);
|
|
23
|
-
break;
|
|
24
|
-
case 'DELETE': // @ts-ignore
|
|
25
|
-
logger.info(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`);
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
break;
|
|
29
|
-
case 404:
|
|
30
|
-
switch (req.method) {
|
|
31
|
-
case 'POST': // @ts-ignore
|
|
32
|
-
console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.red(`${colors.white(` 404 `)}`)}`);
|
|
33
|
-
break;
|
|
34
|
-
case 'GET': // @ts-ignore
|
|
35
|
-
console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 404 `)}`)}`);
|
|
36
|
-
break;
|
|
37
|
-
case 'PUT': // @ts-ignore
|
|
38
|
-
console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 404 `)}`)}`);
|
|
39
|
-
break;
|
|
40
|
-
case 'DELETE': // @ts-ignore
|
|
41
|
-
console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 404 `)}`)}`);
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
break;
|
|
45
|
-
case 401:
|
|
46
|
-
switch (req.method) {
|
|
47
|
-
case 'POST': // @ts-ignore
|
|
48
|
-
console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
|
|
49
|
-
break;
|
|
50
|
-
case 'GET': // @ts-ignore
|
|
51
|
-
console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
|
|
52
|
-
break;
|
|
53
|
-
case 'PUT': // @ts-ignore
|
|
54
|
-
console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
|
|
55
|
-
break;
|
|
56
|
-
case 'DELETE': // @ts-ignore
|
|
57
|
-
console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
break;
|
|
61
|
-
case 500:
|
|
62
|
-
switch (req.method) {
|
|
63
|
-
case 'POST': // @ts-ignore
|
|
64
|
-
console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.red(`${colors.bold(` 500 `)}`)}`);
|
|
65
|
-
break;
|
|
66
|
-
case 'GET': // @ts-ignore
|
|
67
|
-
console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 500 `)}`)}`);
|
|
68
|
-
break;
|
|
69
|
-
case 'PUT': // @ts-ignore
|
|
70
|
-
console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 500 `)}`)}`);
|
|
71
|
-
break;
|
|
72
|
-
case 'DELETE': // @ts-ignore
|
|
73
|
-
console.log(`[ ${colors.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgRed(`${colors.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors.red(`${colors.bold(` 500 `)}`)}`);
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
break;
|
|
77
|
-
default:
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
console.log(`[ ${colors.blueBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.blueBright(` ${res.statusMessage} `)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.blueBright(` ${res.req.socket._httpMessage.statusCode} `)}`);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {HttpStatusCodesConstant} from "@webApp/domains/constants/httpStatusCodes.constant";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Handling and catch a Node.js error.
|
|
6
|
-
*/
|
|
7
|
-
export default class StackTraceError extends Error {
|
|
8
|
-
public readonly name: string;
|
|
9
|
-
public readonly httpCode: HttpStatusCodesConstant | any;
|
|
10
|
-
public readonly isOperational: boolean;
|
|
11
|
-
|
|
12
|
-
// Centralized error objet that derives from Node's Error.
|
|
13
|
-
constructor(props: string | undefined, name: string, httpCode: HttpStatusCodesConstant | any, isOperational: boolean) {
|
|
14
|
-
super(props);
|
|
15
|
-
|
|
16
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
17
|
-
this.name = name;
|
|
18
|
-
this.httpCode = httpCode;
|
|
19
|
-
this.isOperational = isOperational;
|
|
20
|
-
|
|
21
|
-
Error.captureStackTrace(this);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "@webApp/domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "@webApp/domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Handling and catch a Node.js error.
|
|
8
|
-
*/
|
|
9
|
-
export default class StackTraceAssertionError extends StackTraceError {
|
|
10
|
-
constructor(message: string) {
|
|
11
|
-
super(message, errorName.evalError, status.INTERNAL_SERVER_ERROR, true);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Handling and catch a Node.js error.
|
|
7
|
-
*/
|
|
8
|
-
export default class StackTraceEvalError extends StackTraceError {
|
|
9
|
-
constructor(message: string) {
|
|
10
|
-
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Handling and catch a Node.js error.
|
|
8
|
-
*/
|
|
9
|
-
export default class StackTraceGeneralError extends StackTraceError {
|
|
10
|
-
constructor(message: string) {
|
|
11
|
-
super(message, errorName.evalError, status.INTERNAL_SERVER_ERROR, false);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Handling and catch a Node.js error.
|
|
7
|
-
*/
|
|
8
|
-
export default class StackTraceOpenSSLError extends StackTraceError {
|
|
9
|
-
constructor(message: string) {
|
|
10
|
-
super(message, errorName.evalError, status.INTERNAL_SERVER_ERROR, false);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Handling and catch a Node.js error.
|
|
7
|
-
*/
|
|
8
|
-
export default class StackTraceRangeError extends StackTraceError {
|
|
9
|
-
constructor(message: string) {
|
|
10
|
-
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Handling and catch a Node.js error.
|
|
8
|
-
*/
|
|
9
|
-
export default class StackTraceReferenceError extends StackTraceError {
|
|
10
|
-
constructor(message: string) {
|
|
11
|
-
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Handling and catch a Node.js error.
|
|
7
|
-
*/
|
|
8
|
-
export default class StackTraceSyntaxError extends StackTraceError {
|
|
9
|
-
constructor(message: string) {
|
|
10
|
-
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Handling and catch a Node.js error.
|
|
8
|
-
*/
|
|
9
|
-
export default class StackTraceSystemError extends StackTraceError {
|
|
10
|
-
constructor(message: string, code: string) {
|
|
11
|
-
super(message, errorName.systemError, status.INTERNAL_SERVER_ERROR, false);
|
|
12
|
-
this.message = `${message} (code: ${code})`;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Handling and catch a Node.js error.
|
|
8
|
-
*/
|
|
9
|
-
export default class StackTraceTypeError extends StackTraceError {
|
|
10
|
-
constructor(message: string) {
|
|
11
|
-
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Handling and catch a Node.js error.
|
|
8
|
-
*/
|
|
9
|
-
export default class StackTraceURIError extends StackTraceError {
|
|
10
|
-
constructor(message: string) {
|
|
11
|
-
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import colors from "ansi-colors";
|
|
2
|
-
import express from "express";
|
|
3
|
-
import {dateTimeFormattedUtils} from "./dateTimeFormatted.utils";
|
|
4
|
-
import {LogMessageUtils} from "@webApp/core/utils/logMessage.utils";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export function modulesLoadedUtils(allAppRoutes: express.Router[], dbConChecker: () => void): void {
|
|
8
|
-
LogMessageUtils.success("Kernel", "load kernel", "Modules app have been successfully loaded");
|
|
9
|
-
console.log(`${colors.whiteBright(` content`)} ${colors.green('Kernel :')} ${colors.cyan(`${colors.bold(`server side`)}`)} has been loaded successfully ${colors.green(`✔`)}`);
|
|
10
|
-
allAppRoutes
|
|
11
|
-
? console.log(`${colors.whiteBright(` content`)} ${colors.green('Kernel :')} ${colors.cyan(`${colors.bold(`Routers service`)} `)} has been loaded successfully ${colors.green(`✔`)}`)
|
|
12
|
-
: console.log(`${colors.red(`✘`)} ${colors.bgRed(` ${colors.bold(`${colors.white(` Register routes `)}`)} `)} | ${dateTimeFormattedUtils} | [ ${colors.red(`${colors.bold(` fail `)}`)} ] | [ ${colors.bold(` loading `)} ] - ${colors.red(` routers `)} - The route register failed to load `);
|
|
13
|
-
typeof dbConChecker == "function"
|
|
14
|
-
? console.log(`${colors.whiteBright(` content`)} ${colors.green('Kernel :')} ${colors.cyan(`${colors.bold(`database checker connection`)}`)} has been loaded successfully ${colors.green(`✔`)}`)
|
|
15
|
-
: "";
|
|
16
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export const CErrorName = {
|
|
2
|
-
evalError: "EvalError",
|
|
3
|
-
syntaxError: "SyntaxError",
|
|
4
|
-
rangeError: "RangeError",
|
|
5
|
-
referenceError: "ReferenceError",
|
|
6
|
-
typeError: "TypeError",
|
|
7
|
-
uriError: "URIError",
|
|
8
|
-
systemError: "SystemError",
|
|
9
|
-
assertionError: "AssertionError",
|
|
10
|
-
openSSLError: "OpenSSLError",
|
|
11
|
-
generalError: "GeneralError"
|
|
12
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export const CEvent = {
|
|
2
|
-
beforeExit: "beforeExit",
|
|
3
|
-
disconnect: "disconnect",
|
|
4
|
-
exit: "exit",
|
|
5
|
-
rejectionHandled: "rejectionHandled",
|
|
6
|
-
uncaughtException: "uncaughtException",
|
|
7
|
-
uncaughtExceptionMonitor: "uncaughtExceptionMonitor",
|
|
8
|
-
unhandledRejection: "unhandledRejection",
|
|
9
|
-
warning: "warning",
|
|
10
|
-
message: "message",
|
|
11
|
-
multipleResolves: "multipleResolves",
|
|
12
|
-
worker: "worker",
|
|
13
|
-
sigint: "SIGINT",
|
|
14
|
-
sigterm: "SIGTERM"
|
|
15
|
-
}
|