opticore-webapp 1.0.0 → 1.0.1
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 +162 -161
- package/dist/index.js +175 -174
- package/package.json +1 -1
- package/src/core/handlers/errors/stackTraceEvalError.ts +3 -3
- package/src/core/handlers/errors/stackTraceGeneralError.ts +3 -3
- package/src/core/handlers/errors/stackTraceOpenSSLError.ts +3 -3
- package/src/core/handlers/errors/stackTraceRangeError.ts +3 -3
- package/src/core/handlers/errors/stackTraceReferenceError.ts +3 -3
- package/src/core/handlers/errors/stackTraceSyntaxError.ts +3 -3
- package/src/core/handlers/errors/stackTraceSystemError.ts +3 -3
- package/src/core/handlers/errors/stackTraceTypeError.ts +3 -3
- package/src/core/handlers/errors/stackTraceURIError.ts +3 -3
- package/src/core/handlers/eventProcess.handler.ts +1 -1
package/dist/index.cjs
CHANGED
|
@@ -146,156 +146,14 @@ var StackTraceError = class extends Error {
|
|
|
146
146
|
var import_express = __toESM(require("express"), 1);
|
|
147
147
|
var import_node_process = __toESM(require("process"), 1);
|
|
148
148
|
var import_node_events = __toESM(require("events"), 1);
|
|
149
|
-
var import_serverListen_event = require("@/errors/serverListen.event.error");
|
|
150
|
-
function eventProcessHandler() {
|
|
151
|
-
const errorEmitter = new import_node_events.default();
|
|
152
|
-
const app = (0, import_express.default)();
|
|
153
|
-
errorEmitter.on(CEventNameError.error, (error) => {
|
|
154
|
-
import_serverListen_event.ServerListenEventError.listenerError(error);
|
|
155
|
-
});
|
|
156
|
-
import_node_process.default.on(CEvent.beforeExit, (code) => {
|
|
157
|
-
setTimeout(() => {
|
|
158
|
-
import_serverListen_event.ServerListenEventError.processBeforeExit(code);
|
|
159
|
-
}, 100);
|
|
160
|
-
});
|
|
161
|
-
import_node_process.default.on(CEvent.disconnect, () => {
|
|
162
|
-
import_serverListen_event.ServerListenEventError.processDisconnected();
|
|
163
|
-
});
|
|
164
|
-
import_node_process.default.on(CEvent.exit, (code) => {
|
|
165
|
-
import_serverListen_event.ServerListenEventError.exited(code);
|
|
166
|
-
});
|
|
167
|
-
import_node_process.default.on(CEvent.rejectionHandled, (promise) => {
|
|
168
|
-
import_serverListen_event.ServerListenEventError.promiseRejectionHandled(promise);
|
|
169
|
-
});
|
|
170
|
-
import_node_process.default.on(CEvent.uncaughtException, (error) => {
|
|
171
|
-
import_serverListen_event.ServerListenEventError.uncaughtException(error);
|
|
172
|
-
});
|
|
173
|
-
import_node_process.default.on(CEvent.uncaughtExceptionMonitor, (error) => {
|
|
174
|
-
import_serverListen_event.ServerListenEventError.uncaughtExceptionMonitor(error);
|
|
175
|
-
});
|
|
176
|
-
import_node_process.default.on(CEvent.unhandledRejection, (reason, promise) => {
|
|
177
|
-
import_serverListen_event.ServerListenEventError.unhandledRejection(reason, promise);
|
|
178
|
-
});
|
|
179
|
-
import_node_process.default.on(CEvent.warning, (warning) => {
|
|
180
|
-
import_serverListen_event.ServerListenEventError.warning(warning);
|
|
181
|
-
});
|
|
182
|
-
import_node_process.default.on(CEvent.message, (message) => {
|
|
183
|
-
import_serverListen_event.ServerListenEventError.message(message);
|
|
184
|
-
});
|
|
185
|
-
import_node_process.default.on(CEvent.multipleResolves, (type, promise, reason) => {
|
|
186
|
-
import_serverListen_event.ServerListenEventError.multipleResolves(type, promise, reason);
|
|
187
|
-
});
|
|
188
|
-
import_node_process.default.on(CEvent.sigint, () => {
|
|
189
|
-
import_serverListen_event.ServerListenEventError.processInterrupted();
|
|
190
|
-
});
|
|
191
|
-
import_node_process.default.on(CEvent.sigterm, (signal) => {
|
|
192
|
-
import_serverListen_event.ServerListenEventError.sigtermSignalReceived(signal);
|
|
193
|
-
});
|
|
194
|
-
app.use((err, req, res, next) => {
|
|
195
|
-
import_serverListen_event.ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// src/core/events/requestCalls.event.ts
|
|
200
|
-
var import_ansi_colors = __toESM(require("ansi-colors"), 1);
|
|
201
|
-
var import_opticore_logger = require("opticore-logger");
|
|
202
|
-
function requestCallsEvent(req, res, host, port, loadingTime) {
|
|
203
|
-
const logger = new import_opticore_logger.LoggerCore();
|
|
204
|
-
const currentDatePath = `Request called`;
|
|
205
|
-
if (req.originalUrl === "undefined") {
|
|
206
|
-
console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] The route do not exist. - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.white(` 404 `)}`)}`);
|
|
207
|
-
logger.error("The route do not exist.");
|
|
208
|
-
} else {
|
|
209
|
-
switch (res.statusCode) {
|
|
210
|
-
case 200:
|
|
211
|
-
switch (req.method) {
|
|
212
|
-
case "POST":
|
|
213
|
-
console.log(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
|
|
214
|
-
logger.info(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
|
|
215
|
-
break;
|
|
216
|
-
case "GET":
|
|
217
|
-
case "PUT":
|
|
218
|
-
console.log(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
|
|
219
|
-
logger.info(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
|
|
220
|
-
break;
|
|
221
|
-
case "DELETE":
|
|
222
|
-
console.log(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
|
|
223
|
-
logger.info(`[ ${import_ansi_colors.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` 200 `)}`)}`);
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
break;
|
|
227
|
-
case 404:
|
|
228
|
-
switch (req.method) {
|
|
229
|
-
case "POST":
|
|
230
|
-
console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.white(` 404 `)}`)}`);
|
|
231
|
-
break;
|
|
232
|
-
case "GET":
|
|
233
|
-
console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 404 `)}`)}`);
|
|
234
|
-
break;
|
|
235
|
-
case "PUT":
|
|
236
|
-
console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 404 `)}`)}`);
|
|
237
|
-
break;
|
|
238
|
-
case "DELETE":
|
|
239
|
-
console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 404 `)}`)}`);
|
|
240
|
-
break;
|
|
241
|
-
}
|
|
242
|
-
break;
|
|
243
|
-
case 401:
|
|
244
|
-
switch (req.method) {
|
|
245
|
-
case "POST":
|
|
246
|
-
console.log(`[ ${import_ansi_colors.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgYellowBright(`${import_ansi_colors.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgYellow(`${import_ansi_colors.default.bold(` 401 `)}`)}`);
|
|
247
|
-
break;
|
|
248
|
-
case "GET":
|
|
249
|
-
console.log(`[ ${import_ansi_colors.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgYellowBright(`${import_ansi_colors.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgYellow(`${import_ansi_colors.default.bold(` 401 `)}`)}`);
|
|
250
|
-
break;
|
|
251
|
-
case "PUT":
|
|
252
|
-
console.log(`[ ${import_ansi_colors.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgYellowBright(`${import_ansi_colors.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgYellow(`${import_ansi_colors.default.bold(` 401 `)}`)}`);
|
|
253
|
-
break;
|
|
254
|
-
case "DELETE":
|
|
255
|
-
console.log(`[ ${import_ansi_colors.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgYellowBright(`${import_ansi_colors.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.bgYellow(`${import_ansi_colors.default.bold(` 401 `)}`)}`);
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
break;
|
|
259
|
-
case 500:
|
|
260
|
-
switch (req.method) {
|
|
261
|
-
case "POST":
|
|
262
|
-
console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 500 `)}`)}`);
|
|
263
|
-
break;
|
|
264
|
-
case "GET":
|
|
265
|
-
console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 500 `)}`)}`);
|
|
266
|
-
break;
|
|
267
|
-
case "PUT":
|
|
268
|
-
console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 500 `)}`)}`);
|
|
269
|
-
break;
|
|
270
|
-
case "DELETE":
|
|
271
|
-
console.log(`[ ${import_ansi_colors.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` 500 `)}`)}`);
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
break;
|
|
275
|
-
default:
|
|
276
|
-
console.log(`[ ${import_ansi_colors.default.blueBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors.default.blueBright(` ${res.statusMessage} `)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors.default.blueBright(` ${res.req.socket._httpMessage.statusCode} `)}`);
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
// src/domains/constants/eventNameError.constant.ts
|
|
283
|
-
var CEventNameError = {
|
|
284
|
-
error: "error",
|
|
285
|
-
listening: "listening",
|
|
286
|
-
close: "close",
|
|
287
|
-
connection: "connection",
|
|
288
|
-
drop: "drop",
|
|
289
|
-
request: "request"
|
|
290
|
-
};
|
|
291
149
|
|
|
292
150
|
// src/core/events/errors/serverListen.event.error.ts
|
|
293
151
|
var import_process = __toESM(require("process"), 1);
|
|
294
|
-
var
|
|
152
|
+
var import_ansi_colors3 = __toESM(require("ansi-colors"), 1);
|
|
295
153
|
var import_chalk = __toESM(require("chalk"), 1);
|
|
296
154
|
|
|
297
155
|
// src/core/utils/logMessage.utils.ts
|
|
298
|
-
var
|
|
156
|
+
var import_ansi_colors = __toESM(require("ansi-colors"), 1);
|
|
299
157
|
|
|
300
158
|
// src/core/utils/dateTimeFormatted.utils.ts
|
|
301
159
|
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()}`;
|
|
@@ -303,24 +161,24 @@ var dateTimeFormattedUtils = `${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @
|
|
|
303
161
|
// src/core/utils/logMessage.utils.ts
|
|
304
162
|
var LogMessageUtils = class {
|
|
305
163
|
static success(title, action, contentAction) {
|
|
306
|
-
console.log(`${
|
|
164
|
+
console.log(`${import_ansi_colors.default.green(`\u2714`)} ${import_ansi_colors.default.bgGreen(` ${import_ansi_colors.default.bold(`${import_ansi_colors.default.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` Success `)}`)} [ ${action} ] ${contentAction} - [ Status ] ${import_ansi_colors.default.bgGreen(`${import_ansi_colors.default.white(` 200 `)}`)}`);
|
|
307
165
|
}
|
|
308
166
|
static warning(title, action, contentAction) {
|
|
309
|
-
console.warn(`${
|
|
167
|
+
console.warn(`${import_ansi_colors.default.yellow(`\u26A0\uFE0F`)} ${import_ansi_colors.default.bgYellow(` ${import_ansi_colors.default.bold(`${import_ansi_colors.default.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${import_ansi_colors.default.bgYellow(`${import_ansi_colors.default.white(` Warning `)}`)} ${contentAction}`);
|
|
310
168
|
}
|
|
311
169
|
static info(title, action, contentAction) {
|
|
312
|
-
console.info(`${
|
|
170
|
+
console.info(`${import_ansi_colors.default.cyan(`\u24D8`)} ${import_ansi_colors.default.bgCyan(` ${import_ansi_colors.default.bold(`${import_ansi_colors.default.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${import_ansi_colors.default.bgCyan(`${import_ansi_colors.default.white(` Info `)}`)} ${contentAction}`);
|
|
313
171
|
}
|
|
314
172
|
static error(title, errorType, stackTrace, messageContent, httpCodeValue) {
|
|
315
|
-
console.error(`${
|
|
173
|
+
console.error(`${import_ansi_colors.default.red(`\u2718`)} ${import_ansi_colors.default.bgRed(` ${import_ansi_colors.default.bold(`${import_ansi_colors.default.white(`${title}`)}`)} `)} | ${dateTimeFormattedUtils} | [ ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` ${errorType} `)}`)} ] | [ ${import_ansi_colors.default.bold(`stack trace`)} ] ${import_ansi_colors.default.red(`${stackTrace}`)} - ${import_ansi_colors.default.red(`${messageContent}`)} - [ ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` HttpCode `)}`)} ] ${import_ansi_colors.default.red(`${import_ansi_colors.default.bold(` ${httpCodeValue} `)}`)} `);
|
|
316
174
|
}
|
|
317
175
|
static requestError(title, errorName, errorMessage, errorCode) {
|
|
318
|
-
console.error(`[ ${
|
|
176
|
+
console.error(`[ ${import_ansi_colors.default.red(`${title}`)} ] ${dateTimeFormattedUtils} | ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` ERROR `)}`)} ${import_ansi_colors.default.red(`[ ${errorName} ]`)} ${import_ansi_colors.default.red(`${errorMessage}`)} - [ Status ] ${import_ansi_colors.default.bgRed(`${import_ansi_colors.default.white(` ${errorCode} `)}`)}`);
|
|
319
177
|
}
|
|
320
178
|
};
|
|
321
179
|
|
|
322
180
|
// src/application/exceptions/messages.exception.ts
|
|
323
|
-
var
|
|
181
|
+
var import_ansi_colors2 = __toESM(require("ansi-colors"), 1);
|
|
324
182
|
var messageException = {
|
|
325
183
|
dbConnection: "DataBase connection",
|
|
326
184
|
dbConnectionClosed: "MySQL connection is closed",
|
|
@@ -384,11 +242,21 @@ var messageException = {
|
|
|
384
242
|
errorHost: "The host can't be empty or blank. Please define a string host in .env",
|
|
385
243
|
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`,
|
|
386
244
|
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`,
|
|
387
|
-
errorDBHost: (host) => `A database host ${host} does not allow connection. Please either set the host like this: ${
|
|
245
|
+
errorDBHost: (host) => `A database host ${host} does not allow connection. Please either set the host like this: ${import_ansi_colors2.default.bgRed(`${import_ansi_colors2.default.white(`localhost`)}`)} in your .env file`
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// src/domains/constants/eventNameError.constant.ts
|
|
249
|
+
var CEventNameError = {
|
|
250
|
+
error: "error",
|
|
251
|
+
listening: "listening",
|
|
252
|
+
close: "close",
|
|
253
|
+
connection: "connection",
|
|
254
|
+
drop: "drop",
|
|
255
|
+
request: "request"
|
|
388
256
|
};
|
|
389
257
|
|
|
390
258
|
// src/core/events/errors/serverListen.event.error.ts
|
|
391
|
-
var
|
|
259
|
+
var ServerListenEventError = class {
|
|
392
260
|
static hostPortUndefined() {
|
|
393
261
|
const stackTrace = this.traceError(messageException.errorHostUrl, messageException.listening, 400 /* BAD_REQUEST */);
|
|
394
262
|
LogMessageUtils.error(
|
|
@@ -487,7 +355,7 @@ var ServerListenEventError2 = class {
|
|
|
487
355
|
const paddingLength = 35;
|
|
488
356
|
const msg0 = " ".padEnd(paddingLength, " ");
|
|
489
357
|
console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
490
|
-
console.log(`${
|
|
358
|
+
console.log(`${import_ansi_colors3.default.bgGreen(` [OK] The server shutting down `)}`);
|
|
491
359
|
console.log(import_chalk.default.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
492
360
|
break;
|
|
493
361
|
case 1:
|
|
@@ -759,12 +627,12 @@ var ServerListenEventError2 = class {
|
|
|
759
627
|
import_process.default.exit(0);
|
|
760
628
|
}
|
|
761
629
|
static serverClosing() {
|
|
762
|
-
console.log(`${
|
|
630
|
+
console.log(`${import_ansi_colors3.default.bgCyanBright(` ${import_ansi_colors3.default.bold(`${import_ansi_colors3.default.white(` INFO `)}`)}`)} All processes are stopped`);
|
|
763
631
|
console.log(" Server is closed");
|
|
764
632
|
import_process.default.exit();
|
|
765
633
|
}
|
|
766
634
|
static dropNewConnection() {
|
|
767
|
-
console.log(`${
|
|
635
|
+
console.log(`${import_ansi_colors3.default.cyan(`\u24D8`)} ${import_ansi_colors3.default.bgCyan(` ${import_ansi_colors3.default.bold(`${import_ansi_colors3.default.white(` Server maxConnection `)}`)} `)} ${dateTimeFormattedUtils} | ${import_ansi_colors3.default.bgCyan(`${import_ansi_colors3.default.white(` Info `)}`)} The server dropped new connections`);
|
|
768
636
|
}
|
|
769
637
|
static expressErrorHandlingMiddleware(errorEmitter, err, req, res, next) {
|
|
770
638
|
if (err) {
|
|
@@ -791,6 +659,139 @@ var ServerListenEventError2 = class {
|
|
|
791
659
|
}
|
|
792
660
|
};
|
|
793
661
|
|
|
662
|
+
// src/core/handlers/eventProcess.handler.ts
|
|
663
|
+
function eventProcessHandler() {
|
|
664
|
+
const errorEmitter = new import_node_events.default();
|
|
665
|
+
const app = (0, import_express.default)();
|
|
666
|
+
errorEmitter.on(CEventNameError.error, (error) => {
|
|
667
|
+
ServerListenEventError.listenerError(error);
|
|
668
|
+
});
|
|
669
|
+
import_node_process.default.on(CEvent.beforeExit, (code) => {
|
|
670
|
+
setTimeout(() => {
|
|
671
|
+
ServerListenEventError.processBeforeExit(code);
|
|
672
|
+
}, 100);
|
|
673
|
+
});
|
|
674
|
+
import_node_process.default.on(CEvent.disconnect, () => {
|
|
675
|
+
ServerListenEventError.processDisconnected();
|
|
676
|
+
});
|
|
677
|
+
import_node_process.default.on(CEvent.exit, (code) => {
|
|
678
|
+
ServerListenEventError.exited(code);
|
|
679
|
+
});
|
|
680
|
+
import_node_process.default.on(CEvent.rejectionHandled, (promise) => {
|
|
681
|
+
ServerListenEventError.promiseRejectionHandled(promise);
|
|
682
|
+
});
|
|
683
|
+
import_node_process.default.on(CEvent.uncaughtException, (error) => {
|
|
684
|
+
ServerListenEventError.uncaughtException(error);
|
|
685
|
+
});
|
|
686
|
+
import_node_process.default.on(CEvent.uncaughtExceptionMonitor, (error) => {
|
|
687
|
+
ServerListenEventError.uncaughtExceptionMonitor(error);
|
|
688
|
+
});
|
|
689
|
+
import_node_process.default.on(CEvent.unhandledRejection, (reason, promise) => {
|
|
690
|
+
ServerListenEventError.unhandledRejection(reason, promise);
|
|
691
|
+
});
|
|
692
|
+
import_node_process.default.on(CEvent.warning, (warning) => {
|
|
693
|
+
ServerListenEventError.warning(warning);
|
|
694
|
+
});
|
|
695
|
+
import_node_process.default.on(CEvent.message, (message) => {
|
|
696
|
+
ServerListenEventError.message(message);
|
|
697
|
+
});
|
|
698
|
+
import_node_process.default.on(CEvent.multipleResolves, (type, promise, reason) => {
|
|
699
|
+
ServerListenEventError.multipleResolves(type, promise, reason);
|
|
700
|
+
});
|
|
701
|
+
import_node_process.default.on(CEvent.sigint, () => {
|
|
702
|
+
ServerListenEventError.processInterrupted();
|
|
703
|
+
});
|
|
704
|
+
import_node_process.default.on(CEvent.sigterm, (signal) => {
|
|
705
|
+
ServerListenEventError.sigtermSignalReceived(signal);
|
|
706
|
+
});
|
|
707
|
+
app.use((err, req, res, next) => {
|
|
708
|
+
ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// src/core/events/requestCalls.event.ts
|
|
713
|
+
var import_ansi_colors4 = __toESM(require("ansi-colors"), 1);
|
|
714
|
+
var import_opticore_logger = require("opticore-logger");
|
|
715
|
+
function requestCallsEvent(req, res, host, port, loadingTime) {
|
|
716
|
+
const logger = new import_opticore_logger.LoggerCore();
|
|
717
|
+
const currentDatePath = `Request called`;
|
|
718
|
+
if (req.originalUrl === "undefined") {
|
|
719
|
+
console.log(`[ ${import_ansi_colors4.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] The route do not exist. - [ Status ] ${import_ansi_colors4.default.red(`${import_ansi_colors4.default.white(` 404 `)}`)}`);
|
|
720
|
+
logger.error("The route do not exist.");
|
|
721
|
+
} else {
|
|
722
|
+
switch (res.statusCode) {
|
|
723
|
+
case 200:
|
|
724
|
+
switch (req.method) {
|
|
725
|
+
case "POST":
|
|
726
|
+
console.log(`[ ${import_ansi_colors4.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgGreen(`${import_ansi_colors4.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.white(` 200 `)}`)}`);
|
|
727
|
+
logger.info(`[ ${import_ansi_colors4.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgGreen(`${import_ansi_colors4.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.white(` 200 `)}`)}`);
|
|
728
|
+
break;
|
|
729
|
+
case "GET":
|
|
730
|
+
case "PUT":
|
|
731
|
+
console.log(`[ ${import_ansi_colors4.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgGreen(`${import_ansi_colors4.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.white(` 200 `)}`)}`);
|
|
732
|
+
logger.info(`[ ${import_ansi_colors4.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgGreen(`${import_ansi_colors4.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.white(` 200 `)}`)}`);
|
|
733
|
+
break;
|
|
734
|
+
case "DELETE":
|
|
735
|
+
console.log(`[ ${import_ansi_colors4.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgGreen(`${import_ansi_colors4.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.white(` 200 `)}`)}`);
|
|
736
|
+
logger.info(`[ ${import_ansi_colors4.default.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgGreen(`${import_ansi_colors4.default.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.bgCyan(`${import_ansi_colors4.default.white(` 200 `)}`)}`);
|
|
737
|
+
break;
|
|
738
|
+
}
|
|
739
|
+
break;
|
|
740
|
+
case 404:
|
|
741
|
+
switch (req.method) {
|
|
742
|
+
case "POST":
|
|
743
|
+
console.log(`[ ${import_ansi_colors4.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors4.default.red(`${import_ansi_colors4.default.white(` 404 `)}`)}`);
|
|
744
|
+
break;
|
|
745
|
+
case "GET":
|
|
746
|
+
console.log(`[ ${import_ansi_colors4.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.red(`${import_ansi_colors4.default.bold(` 404 `)}`)}`);
|
|
747
|
+
break;
|
|
748
|
+
case "PUT":
|
|
749
|
+
console.log(`[ ${import_ansi_colors4.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.red(`${import_ansi_colors4.default.bold(` 404 `)}`)}`);
|
|
750
|
+
break;
|
|
751
|
+
case "DELETE":
|
|
752
|
+
console.log(`[ ${import_ansi_colors4.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.red(`${import_ansi_colors4.default.bold(` 404 `)}`)}`);
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
break;
|
|
756
|
+
case 401:
|
|
757
|
+
switch (req.method) {
|
|
758
|
+
case "POST":
|
|
759
|
+
console.log(`[ ${import_ansi_colors4.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgYellowBright(`${import_ansi_colors4.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors4.default.bgYellow(`${import_ansi_colors4.default.bold(` 401 `)}`)}`);
|
|
760
|
+
break;
|
|
761
|
+
case "GET":
|
|
762
|
+
console.log(`[ ${import_ansi_colors4.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgYellowBright(`${import_ansi_colors4.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors4.default.bgYellow(`${import_ansi_colors4.default.bold(` 401 `)}`)}`);
|
|
763
|
+
break;
|
|
764
|
+
case "PUT":
|
|
765
|
+
console.log(`[ ${import_ansi_colors4.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgYellowBright(`${import_ansi_colors4.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors4.default.bgYellow(`${import_ansi_colors4.default.bold(` 401 `)}`)}`);
|
|
766
|
+
break;
|
|
767
|
+
case "DELETE":
|
|
768
|
+
console.log(`[ ${import_ansi_colors4.default.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgYellowBright(`${import_ansi_colors4.default.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors4.default.bgYellow(`${import_ansi_colors4.default.bold(` 401 `)}`)}`);
|
|
769
|
+
break;
|
|
770
|
+
}
|
|
771
|
+
break;
|
|
772
|
+
case 500:
|
|
773
|
+
switch (req.method) {
|
|
774
|
+
case "POST":
|
|
775
|
+
console.log(`[ ${import_ansi_colors4.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors4.default.red(`${import_ansi_colors4.default.bold(` 500 `)}`)}`);
|
|
776
|
+
break;
|
|
777
|
+
case "GET":
|
|
778
|
+
console.log(`[ ${import_ansi_colors4.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.red(`${import_ansi_colors4.default.bold(` 500 `)}`)}`);
|
|
779
|
+
break;
|
|
780
|
+
case "PUT":
|
|
781
|
+
console.log(`[ ${import_ansi_colors4.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.red(`${import_ansi_colors4.default.bold(` 500 `)}`)}`);
|
|
782
|
+
break;
|
|
783
|
+
case "DELETE":
|
|
784
|
+
console.log(`[ ${import_ansi_colors4.default.red(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.bgRed(`${import_ansi_colors4.default.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${import_ansi_colors4.default.red(`${import_ansi_colors4.default.bold(` 500 `)}`)}`);
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
break;
|
|
788
|
+
default:
|
|
789
|
+
console.log(`[ ${import_ansi_colors4.default.blueBright(`${currentDatePath}`)} ] ${loadingTime} | ${import_ansi_colors4.default.blueBright(` ${res.statusMessage} `)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${import_ansi_colors4.default.blueBright(` ${res.req.socket._httpMessage.statusCode} `)}`);
|
|
790
|
+
break;
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
|
|
794
795
|
// src/application/service/core.service.ts
|
|
795
796
|
var import_node_process2 = __toESM(require("process"), 1);
|
|
796
797
|
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
@@ -978,11 +979,11 @@ var WebServerCore = class {
|
|
|
978
979
|
() => {
|
|
979
980
|
try {
|
|
980
981
|
if (this.host === "" && this.port === 0) {
|
|
981
|
-
|
|
982
|
+
ServerListenEventError.hostPortUndefined();
|
|
982
983
|
} else if (this.host === "") {
|
|
983
|
-
|
|
984
|
+
ServerListenEventError.hostUndefined();
|
|
984
985
|
} else if (this.port === 0) {
|
|
985
|
-
|
|
986
|
+
ServerListenEventError.portUndefined();
|
|
986
987
|
} else {
|
|
987
988
|
this.registerRoutes(routers);
|
|
988
989
|
}
|
|
@@ -994,11 +995,11 @@ var WebServerCore = class {
|
|
|
994
995
|
}
|
|
995
996
|
onListeningOnServerEvent(serverWeb, kernelModule) {
|
|
996
997
|
serverWeb.on(CEventNameError.error, (err) => {
|
|
997
|
-
|
|
998
|
+
ServerListenEventError.onEventError(err);
|
|
998
999
|
}).on(CEventNameError.close, () => {
|
|
999
|
-
|
|
1000
|
+
ServerListenEventError.serverClosing();
|
|
1000
1001
|
}).on(CEventNameError.drop, () => {
|
|
1001
|
-
|
|
1002
|
+
ServerListenEventError.dropNewConnection();
|
|
1002
1003
|
}).on(CEventNameError.listening, () => {
|
|
1003
1004
|
this.infoWebApp();
|
|
1004
1005
|
this.serverUtility.coreListenerEventLoaderModuleService(kernelModule);
|
package/dist/index.js
CHANGED
|
@@ -103,158 +103,16 @@ var StackTraceError = class extends Error {
|
|
|
103
103
|
|
|
104
104
|
// src/core/handlers/eventProcess.handler.ts
|
|
105
105
|
import express from "express";
|
|
106
|
-
import
|
|
106
|
+
import process2 from "node:process";
|
|
107
107
|
import EventEmitter from "node:events";
|
|
108
|
-
import { ServerListenEventError } from "@/errors/serverListen.event.error";
|
|
109
|
-
function eventProcessHandler() {
|
|
110
|
-
const errorEmitter = new EventEmitter();
|
|
111
|
-
const app = express();
|
|
112
|
-
errorEmitter.on(CEventNameError.error, (error) => {
|
|
113
|
-
ServerListenEventError.listenerError(error);
|
|
114
|
-
});
|
|
115
|
-
process.on(CEvent.beforeExit, (code) => {
|
|
116
|
-
setTimeout(() => {
|
|
117
|
-
ServerListenEventError.processBeforeExit(code);
|
|
118
|
-
}, 100);
|
|
119
|
-
});
|
|
120
|
-
process.on(CEvent.disconnect, () => {
|
|
121
|
-
ServerListenEventError.processDisconnected();
|
|
122
|
-
});
|
|
123
|
-
process.on(CEvent.exit, (code) => {
|
|
124
|
-
ServerListenEventError.exited(code);
|
|
125
|
-
});
|
|
126
|
-
process.on(CEvent.rejectionHandled, (promise) => {
|
|
127
|
-
ServerListenEventError.promiseRejectionHandled(promise);
|
|
128
|
-
});
|
|
129
|
-
process.on(CEvent.uncaughtException, (error) => {
|
|
130
|
-
ServerListenEventError.uncaughtException(error);
|
|
131
|
-
});
|
|
132
|
-
process.on(CEvent.uncaughtExceptionMonitor, (error) => {
|
|
133
|
-
ServerListenEventError.uncaughtExceptionMonitor(error);
|
|
134
|
-
});
|
|
135
|
-
process.on(CEvent.unhandledRejection, (reason, promise) => {
|
|
136
|
-
ServerListenEventError.unhandledRejection(reason, promise);
|
|
137
|
-
});
|
|
138
|
-
process.on(CEvent.warning, (warning) => {
|
|
139
|
-
ServerListenEventError.warning(warning);
|
|
140
|
-
});
|
|
141
|
-
process.on(CEvent.message, (message) => {
|
|
142
|
-
ServerListenEventError.message(message);
|
|
143
|
-
});
|
|
144
|
-
process.on(CEvent.multipleResolves, (type, promise, reason) => {
|
|
145
|
-
ServerListenEventError.multipleResolves(type, promise, reason);
|
|
146
|
-
});
|
|
147
|
-
process.on(CEvent.sigint, () => {
|
|
148
|
-
ServerListenEventError.processInterrupted();
|
|
149
|
-
});
|
|
150
|
-
process.on(CEvent.sigterm, (signal) => {
|
|
151
|
-
ServerListenEventError.sigtermSignalReceived(signal);
|
|
152
|
-
});
|
|
153
|
-
app.use((err, req, res, next) => {
|
|
154
|
-
ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// src/core/events/requestCalls.event.ts
|
|
159
|
-
import colors from "ansi-colors";
|
|
160
|
-
import { LoggerCore } from "opticore-logger";
|
|
161
|
-
function requestCallsEvent(req, res, host, port, loadingTime) {
|
|
162
|
-
const logger = new LoggerCore();
|
|
163
|
-
const currentDatePath = `Request called`;
|
|
164
|
-
if (req.originalUrl === "undefined") {
|
|
165
|
-
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 `)}`)}`);
|
|
166
|
-
logger.error("The route do not exist.");
|
|
167
|
-
} else {
|
|
168
|
-
switch (res.statusCode) {
|
|
169
|
-
case 200:
|
|
170
|
-
switch (req.method) {
|
|
171
|
-
case "POST":
|
|
172
|
-
console.log(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`);
|
|
173
|
-
logger.info(`[ ${colors.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgGreen(`${colors.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgCyan(`${colors.white(` 200 `)}`)}`);
|
|
174
|
-
break;
|
|
175
|
-
case "GET":
|
|
176
|
-
case "PUT":
|
|
177
|
-
console.log(`[ ${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 `)}`)}`);
|
|
178
|
-
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 `)}`)}`);
|
|
179
|
-
break;
|
|
180
|
-
case "DELETE":
|
|
181
|
-
console.log(`[ ${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 `)}`)}`);
|
|
182
|
-
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 `)}`)}`);
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
break;
|
|
186
|
-
case 404:
|
|
187
|
-
switch (req.method) {
|
|
188
|
-
case "POST":
|
|
189
|
-
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 `)}`)}`);
|
|
190
|
-
break;
|
|
191
|
-
case "GET":
|
|
192
|
-
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 `)}`)}`);
|
|
193
|
-
break;
|
|
194
|
-
case "PUT":
|
|
195
|
-
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 `)}`)}`);
|
|
196
|
-
break;
|
|
197
|
-
case "DELETE":
|
|
198
|
-
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 `)}`)}`);
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
break;
|
|
202
|
-
case 401:
|
|
203
|
-
switch (req.method) {
|
|
204
|
-
case "POST":
|
|
205
|
-
console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
|
|
206
|
-
break;
|
|
207
|
-
case "GET":
|
|
208
|
-
console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
|
|
209
|
-
break;
|
|
210
|
-
case "PUT":
|
|
211
|
-
console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
|
|
212
|
-
break;
|
|
213
|
-
case "DELETE":
|
|
214
|
-
console.log(`[ ${colors.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors.bgYellowBright(`${colors.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors.bgYellow(`${colors.bold(` 401 `)}`)}`);
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
break;
|
|
218
|
-
case 500:
|
|
219
|
-
switch (req.method) {
|
|
220
|
-
case "POST":
|
|
221
|
-
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 `)}`)}`);
|
|
222
|
-
break;
|
|
223
|
-
case "GET":
|
|
224
|
-
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 `)}`)}`);
|
|
225
|
-
break;
|
|
226
|
-
case "PUT":
|
|
227
|
-
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 `)}`)}`);
|
|
228
|
-
break;
|
|
229
|
-
case "DELETE":
|
|
230
|
-
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 `)}`)}`);
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
break;
|
|
234
|
-
default:
|
|
235
|
-
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} `)}`);
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// src/domains/constants/eventNameError.constant.ts
|
|
242
|
-
var CEventNameError = {
|
|
243
|
-
error: "error",
|
|
244
|
-
listening: "listening",
|
|
245
|
-
close: "close",
|
|
246
|
-
connection: "connection",
|
|
247
|
-
drop: "drop",
|
|
248
|
-
request: "request"
|
|
249
|
-
};
|
|
250
108
|
|
|
251
109
|
// src/core/events/errors/serverListen.event.error.ts
|
|
252
|
-
import
|
|
253
|
-
import
|
|
110
|
+
import process from "process";
|
|
111
|
+
import colors3 from "ansi-colors";
|
|
254
112
|
import chalk from "chalk";
|
|
255
113
|
|
|
256
114
|
// src/core/utils/logMessage.utils.ts
|
|
257
|
-
import
|
|
115
|
+
import colors from "ansi-colors";
|
|
258
116
|
|
|
259
117
|
// src/core/utils/dateTimeFormatted.utils.ts
|
|
260
118
|
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()}`;
|
|
@@ -262,24 +120,24 @@ var dateTimeFormattedUtils = `${(/* @__PURE__ */ new Date()).getMonth()}-${(/* @
|
|
|
262
120
|
// src/core/utils/logMessage.utils.ts
|
|
263
121
|
var LogMessageUtils = class {
|
|
264
122
|
static success(title, action, contentAction) {
|
|
265
|
-
console.log(`${
|
|
123
|
+
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 `)}`)}`);
|
|
266
124
|
}
|
|
267
125
|
static warning(title, action, contentAction) {
|
|
268
|
-
console.warn(`${
|
|
126
|
+
console.warn(`${colors.yellow(`\u26A0\uFE0F`)} ${colors.bgYellow(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgYellow(`${colors.white(` Warning `)}`)} ${contentAction}`);
|
|
269
127
|
}
|
|
270
128
|
static info(title, action, contentAction) {
|
|
271
|
-
console.info(`${
|
|
129
|
+
console.info(`${colors.cyan(`\u24D8`)} ${colors.bgCyan(` ${colors.bold(`${colors.white(`${title}`)}`)} `)} ${dateTimeFormattedUtils} | ${colors.bgCyan(`${colors.white(` Info `)}`)} ${contentAction}`);
|
|
272
130
|
}
|
|
273
131
|
static error(title, errorType, stackTrace, messageContent, httpCodeValue) {
|
|
274
|
-
console.error(`${
|
|
132
|
+
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} `)}`)} `);
|
|
275
133
|
}
|
|
276
134
|
static requestError(title, errorName, errorMessage, errorCode) {
|
|
277
|
-
console.error(`[ ${
|
|
135
|
+
console.error(`[ ${colors.red(`${title}`)} ] ${dateTimeFormattedUtils} | ${colors.bgRed(`${colors.white(` ERROR `)}`)} ${colors.red(`[ ${errorName} ]`)} ${colors.red(`${errorMessage}`)} - [ Status ] ${colors.bgRed(`${colors.white(` ${errorCode} `)}`)}`);
|
|
278
136
|
}
|
|
279
137
|
};
|
|
280
138
|
|
|
281
139
|
// src/application/exceptions/messages.exception.ts
|
|
282
|
-
import
|
|
140
|
+
import colors2 from "ansi-colors";
|
|
283
141
|
var messageException = {
|
|
284
142
|
dbConnection: "DataBase connection",
|
|
285
143
|
dbConnectionClosed: "MySQL connection is closed",
|
|
@@ -343,11 +201,21 @@ var messageException = {
|
|
|
343
201
|
errorHost: "The host can't be empty or blank. Please define a string host in .env",
|
|
344
202
|
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`,
|
|
345
203
|
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`,
|
|
346
|
-
errorDBHost: (host) => `A database host ${host} does not allow connection. Please either set the host like this: ${
|
|
204
|
+
errorDBHost: (host) => `A database host ${host} does not allow connection. Please either set the host like this: ${colors2.bgRed(`${colors2.white(`localhost`)}`)} in your .env file`
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// src/domains/constants/eventNameError.constant.ts
|
|
208
|
+
var CEventNameError = {
|
|
209
|
+
error: "error",
|
|
210
|
+
listening: "listening",
|
|
211
|
+
close: "close",
|
|
212
|
+
connection: "connection",
|
|
213
|
+
drop: "drop",
|
|
214
|
+
request: "request"
|
|
347
215
|
};
|
|
348
216
|
|
|
349
217
|
// src/core/events/errors/serverListen.event.error.ts
|
|
350
|
-
var
|
|
218
|
+
var ServerListenEventError = class {
|
|
351
219
|
static hostPortUndefined() {
|
|
352
220
|
const stackTrace = this.traceError(messageException.errorHostUrl, messageException.listening, 400 /* BAD_REQUEST */);
|
|
353
221
|
LogMessageUtils.error(
|
|
@@ -357,7 +225,7 @@ var ServerListenEventError2 = class {
|
|
|
357
225
|
messageException.errorHostUrl,
|
|
358
226
|
400 /* BAD_REQUEST */
|
|
359
227
|
);
|
|
360
|
-
|
|
228
|
+
process.exit();
|
|
361
229
|
}
|
|
362
230
|
static hostUndefined() {
|
|
363
231
|
const stackTrace = this.traceError(messageException.badHost, messageException.listening, 400 /* BAD_REQUEST */);
|
|
@@ -368,7 +236,7 @@ var ServerListenEventError2 = class {
|
|
|
368
236
|
messageException.errorHost,
|
|
369
237
|
400 /* BAD_REQUEST */
|
|
370
238
|
);
|
|
371
|
-
|
|
239
|
+
process.exit();
|
|
372
240
|
}
|
|
373
241
|
static portUndefined() {
|
|
374
242
|
const stackTrace = this.traceError(messageException.badPort, messageException.listening, 400 /* BAD_REQUEST */);
|
|
@@ -379,7 +247,7 @@ var ServerListenEventError2 = class {
|
|
|
379
247
|
messageException.errorPort,
|
|
380
248
|
400 /* BAD_REQUEST */
|
|
381
249
|
);
|
|
382
|
-
|
|
250
|
+
process.exit();
|
|
383
251
|
}
|
|
384
252
|
static onEventError(err) {
|
|
385
253
|
LogMessageUtils.error(
|
|
@@ -417,7 +285,7 @@ var ServerListenEventError2 = class {
|
|
|
417
285
|
`Process will exit with code: ${code}`,
|
|
418
286
|
503 /* SERVICE_UNAVAILABLE */
|
|
419
287
|
);
|
|
420
|
-
|
|
288
|
+
process.exit(code);
|
|
421
289
|
}
|
|
422
290
|
static processDisconnected() {
|
|
423
291
|
const stackTrace = this.traceError(
|
|
@@ -432,7 +300,7 @@ var ServerListenEventError2 = class {
|
|
|
432
300
|
"Child process disconnected",
|
|
433
301
|
503 /* SERVICE_UNAVAILABLE */
|
|
434
302
|
);
|
|
435
|
-
|
|
303
|
+
process.exit();
|
|
436
304
|
}
|
|
437
305
|
static exited(code) {
|
|
438
306
|
switch (code) {
|
|
@@ -446,7 +314,7 @@ var ServerListenEventError2 = class {
|
|
|
446
314
|
const paddingLength = 35;
|
|
447
315
|
const msg0 = " ".padEnd(paddingLength, " ");
|
|
448
316
|
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
449
|
-
console.log(`${
|
|
317
|
+
console.log(`${colors3.bgGreen(` [OK] The server shutting down `)}`);
|
|
450
318
|
console.log(chalk.bgGreen.white(msg0.padEnd(paddingLength, " ")));
|
|
451
319
|
break;
|
|
452
320
|
case 1:
|
|
@@ -697,14 +565,14 @@ var ServerListenEventError2 = class {
|
|
|
697
565
|
static processInterrupted() {
|
|
698
566
|
LogMessageUtils.success(
|
|
699
567
|
"[ OK ] Success",
|
|
700
|
-
`Process ${
|
|
568
|
+
`Process ${process.pid} has been interrupted`,
|
|
701
569
|
"The Web server has been stopped !"
|
|
702
570
|
);
|
|
703
|
-
|
|
571
|
+
process.exit(0);
|
|
704
572
|
}
|
|
705
573
|
static sigtermSignalReceived(signal) {
|
|
706
574
|
const stackTrace = this.traceError(
|
|
707
|
-
`Process ${
|
|
575
|
+
`Process ${process.pid} received a SIGTERM signal`,
|
|
708
576
|
"SIGTERM",
|
|
709
577
|
406 /* NOT_ACCEPTABLE */
|
|
710
578
|
);
|
|
@@ -712,18 +580,18 @@ var ServerListenEventError2 = class {
|
|
|
712
580
|
"SIGTERM",
|
|
713
581
|
"SIGTERM",
|
|
714
582
|
stackTrace.stack,
|
|
715
|
-
`Process ${
|
|
583
|
+
`Process ${process.pid} received a SIGTERM signal : ${signal.toString()}`,
|
|
716
584
|
406 /* NOT_ACCEPTABLE */
|
|
717
585
|
);
|
|
718
|
-
|
|
586
|
+
process.exit(0);
|
|
719
587
|
}
|
|
720
588
|
static serverClosing() {
|
|
721
|
-
console.log(`${
|
|
589
|
+
console.log(`${colors3.bgCyanBright(` ${colors3.bold(`${colors3.white(` INFO `)}`)}`)} All processes are stopped`);
|
|
722
590
|
console.log(" Server is closed");
|
|
723
|
-
|
|
591
|
+
process.exit();
|
|
724
592
|
}
|
|
725
593
|
static dropNewConnection() {
|
|
726
|
-
console.log(`${
|
|
594
|
+
console.log(`${colors3.cyan(`\u24D8`)} ${colors3.bgCyan(` ${colors3.bold(`${colors3.white(` Server maxConnection `)}`)} `)} ${dateTimeFormattedUtils} | ${colors3.bgCyan(`${colors3.white(` Info `)}`)} The server dropped new connections`);
|
|
727
595
|
}
|
|
728
596
|
static expressErrorHandlingMiddleware(errorEmitter, err, req, res, next) {
|
|
729
597
|
if (err) {
|
|
@@ -750,6 +618,139 @@ var ServerListenEventError2 = class {
|
|
|
750
618
|
}
|
|
751
619
|
};
|
|
752
620
|
|
|
621
|
+
// src/core/handlers/eventProcess.handler.ts
|
|
622
|
+
function eventProcessHandler() {
|
|
623
|
+
const errorEmitter = new EventEmitter();
|
|
624
|
+
const app = express();
|
|
625
|
+
errorEmitter.on(CEventNameError.error, (error) => {
|
|
626
|
+
ServerListenEventError.listenerError(error);
|
|
627
|
+
});
|
|
628
|
+
process2.on(CEvent.beforeExit, (code) => {
|
|
629
|
+
setTimeout(() => {
|
|
630
|
+
ServerListenEventError.processBeforeExit(code);
|
|
631
|
+
}, 100);
|
|
632
|
+
});
|
|
633
|
+
process2.on(CEvent.disconnect, () => {
|
|
634
|
+
ServerListenEventError.processDisconnected();
|
|
635
|
+
});
|
|
636
|
+
process2.on(CEvent.exit, (code) => {
|
|
637
|
+
ServerListenEventError.exited(code);
|
|
638
|
+
});
|
|
639
|
+
process2.on(CEvent.rejectionHandled, (promise) => {
|
|
640
|
+
ServerListenEventError.promiseRejectionHandled(promise);
|
|
641
|
+
});
|
|
642
|
+
process2.on(CEvent.uncaughtException, (error) => {
|
|
643
|
+
ServerListenEventError.uncaughtException(error);
|
|
644
|
+
});
|
|
645
|
+
process2.on(CEvent.uncaughtExceptionMonitor, (error) => {
|
|
646
|
+
ServerListenEventError.uncaughtExceptionMonitor(error);
|
|
647
|
+
});
|
|
648
|
+
process2.on(CEvent.unhandledRejection, (reason, promise) => {
|
|
649
|
+
ServerListenEventError.unhandledRejection(reason, promise);
|
|
650
|
+
});
|
|
651
|
+
process2.on(CEvent.warning, (warning) => {
|
|
652
|
+
ServerListenEventError.warning(warning);
|
|
653
|
+
});
|
|
654
|
+
process2.on(CEvent.message, (message) => {
|
|
655
|
+
ServerListenEventError.message(message);
|
|
656
|
+
});
|
|
657
|
+
process2.on(CEvent.multipleResolves, (type, promise, reason) => {
|
|
658
|
+
ServerListenEventError.multipleResolves(type, promise, reason);
|
|
659
|
+
});
|
|
660
|
+
process2.on(CEvent.sigint, () => {
|
|
661
|
+
ServerListenEventError.processInterrupted();
|
|
662
|
+
});
|
|
663
|
+
process2.on(CEvent.sigterm, (signal) => {
|
|
664
|
+
ServerListenEventError.sigtermSignalReceived(signal);
|
|
665
|
+
});
|
|
666
|
+
app.use((err, req, res, next) => {
|
|
667
|
+
ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
// src/core/events/requestCalls.event.ts
|
|
672
|
+
import colors4 from "ansi-colors";
|
|
673
|
+
import { LoggerCore } from "opticore-logger";
|
|
674
|
+
function requestCallsEvent(req, res, host, port, loadingTime) {
|
|
675
|
+
const logger = new LoggerCore();
|
|
676
|
+
const currentDatePath = `Request called`;
|
|
677
|
+
if (req.originalUrl === "undefined") {
|
|
678
|
+
console.log(`[ ${colors4.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgRed(`${colors4.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] The route do not exist. - [ Status ] ${colors4.red(`${colors4.white(` 404 `)}`)}`);
|
|
679
|
+
logger.error("The route do not exist.");
|
|
680
|
+
} else {
|
|
681
|
+
switch (res.statusCode) {
|
|
682
|
+
case 200:
|
|
683
|
+
switch (req.method) {
|
|
684
|
+
case "POST":
|
|
685
|
+
console.log(`[ ${colors4.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgGreen(`${colors4.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors4.bgCyan(`${colors4.white(` 200 `)}`)}`);
|
|
686
|
+
logger.info(`[ ${colors4.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgGreen(`${colors4.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors4.bgCyan(`${colors4.white(` 200 `)}`)}`);
|
|
687
|
+
break;
|
|
688
|
+
case "GET":
|
|
689
|
+
case "PUT":
|
|
690
|
+
console.log(`[ ${colors4.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgGreen(`${colors4.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.bgCyan(`${colors4.white(` 200 `)}`)}`);
|
|
691
|
+
logger.info(`[ ${colors4.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgGreen(`${colors4.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.bgCyan(`${colors4.white(` 200 `)}`)}`);
|
|
692
|
+
break;
|
|
693
|
+
case "DELETE":
|
|
694
|
+
console.log(`[ ${colors4.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgGreen(`${colors4.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.bgCyan(`${colors4.white(` 200 `)}`)}`);
|
|
695
|
+
logger.info(`[ ${colors4.cyan(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgGreen(`${colors4.white(` Success `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.bgCyan(`${colors4.white(` 200 `)}`)}`);
|
|
696
|
+
break;
|
|
697
|
+
}
|
|
698
|
+
break;
|
|
699
|
+
case 404:
|
|
700
|
+
switch (req.method) {
|
|
701
|
+
case "POST":
|
|
702
|
+
console.log(`[ ${colors4.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgRed(`${colors4.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors4.red(`${colors4.white(` 404 `)}`)}`);
|
|
703
|
+
break;
|
|
704
|
+
case "GET":
|
|
705
|
+
console.log(`[ ${colors4.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgRed(`${colors4.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.red(`${colors4.bold(` 404 `)}`)}`);
|
|
706
|
+
break;
|
|
707
|
+
case "PUT":
|
|
708
|
+
console.log(`[ ${colors4.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgRed(`${colors4.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.red(`${colors4.bold(` 404 `)}`)}`);
|
|
709
|
+
break;
|
|
710
|
+
case "DELETE":
|
|
711
|
+
console.log(`[ ${colors4.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgRed(`${colors4.white(` Not found `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.red(`${colors4.bold(` 404 `)}`)}`);
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
break;
|
|
715
|
+
case 401:
|
|
716
|
+
switch (req.method) {
|
|
717
|
+
case "POST":
|
|
718
|
+
console.log(`[ ${colors4.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgYellowBright(`${colors4.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors4.bgYellow(`${colors4.bold(` 401 `)}`)}`);
|
|
719
|
+
break;
|
|
720
|
+
case "GET":
|
|
721
|
+
console.log(`[ ${colors4.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgYellowBright(`${colors4.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors4.bgYellow(`${colors4.bold(` 401 `)}`)}`);
|
|
722
|
+
break;
|
|
723
|
+
case "PUT":
|
|
724
|
+
console.log(`[ ${colors4.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgYellowBright(`${colors4.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors4.bgYellow(`${colors4.bold(` 401 `)}`)}`);
|
|
725
|
+
break;
|
|
726
|
+
case "DELETE":
|
|
727
|
+
console.log(`[ ${colors4.yellowBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgYellowBright(`${colors4.white(` Unauthorized `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors4.bgYellow(`${colors4.bold(` 401 `)}`)}`);
|
|
728
|
+
break;
|
|
729
|
+
}
|
|
730
|
+
break;
|
|
731
|
+
case 500:
|
|
732
|
+
switch (req.method) {
|
|
733
|
+
case "POST":
|
|
734
|
+
console.log(`[ ${colors4.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgRed(`${colors4.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors4.red(`${colors4.bold(` 500 `)}`)}`);
|
|
735
|
+
break;
|
|
736
|
+
case "GET":
|
|
737
|
+
console.log(`[ ${colors4.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgRed(`${colors4.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.red(`${colors4.bold(` 500 `)}`)}`);
|
|
738
|
+
break;
|
|
739
|
+
case "PUT":
|
|
740
|
+
console.log(`[ ${colors4.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgRed(`${colors4.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.red(`${colors4.bold(` 500 `)}`)}`);
|
|
741
|
+
break;
|
|
742
|
+
case "DELETE":
|
|
743
|
+
console.log(`[ ${colors4.red(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.bgRed(`${colors4.white(` Server error `)}`)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ query ] ${JSON.stringify(req.query)} - [ params ] ${JSON.stringify(req.params)} - [ Status ] ${colors4.red(`${colors4.bold(` 500 `)}`)}`);
|
|
744
|
+
break;
|
|
745
|
+
}
|
|
746
|
+
break;
|
|
747
|
+
default:
|
|
748
|
+
console.log(`[ ${colors4.blueBright(`${currentDatePath}`)} ] ${loadingTime} | ${colors4.blueBright(` ${res.statusMessage} `)} [ Host ] http://${host}:${port} - [ Route ] ${req.originalUrl} - [ Status ] ${colors4.blueBright(` ${res.req.socket._httpMessage.statusCode} `)}`);
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
753
754
|
// src/application/service/core.service.ts
|
|
754
755
|
import process3 from "node:process";
|
|
755
756
|
import chalk2 from "chalk";
|
|
@@ -937,11 +938,11 @@ var WebServerCore = class {
|
|
|
937
938
|
() => {
|
|
938
939
|
try {
|
|
939
940
|
if (this.host === "" && this.port === 0) {
|
|
940
|
-
|
|
941
|
+
ServerListenEventError.hostPortUndefined();
|
|
941
942
|
} else if (this.host === "") {
|
|
942
|
-
|
|
943
|
+
ServerListenEventError.hostUndefined();
|
|
943
944
|
} else if (this.port === 0) {
|
|
944
|
-
|
|
945
|
+
ServerListenEventError.portUndefined();
|
|
945
946
|
} else {
|
|
946
947
|
this.registerRoutes(routers);
|
|
947
948
|
}
|
|
@@ -953,11 +954,11 @@ var WebServerCore = class {
|
|
|
953
954
|
}
|
|
954
955
|
onListeningOnServerEvent(serverWeb, kernelModule) {
|
|
955
956
|
serverWeb.on(CEventNameError.error, (err) => {
|
|
956
|
-
|
|
957
|
+
ServerListenEventError.onEventError(err);
|
|
957
958
|
}).on(CEventNameError.close, () => {
|
|
958
|
-
|
|
959
|
+
ServerListenEventError.serverClosing();
|
|
959
960
|
}).on(CEventNameError.drop, () => {
|
|
960
|
-
|
|
961
|
+
ServerListenEventError.dropNewConnection();
|
|
961
962
|
}).on(CEventNameError.listening, () => {
|
|
962
963
|
this.infoWebApp();
|
|
963
964
|
this.serverUtility.coreListenerEventLoaderModuleService(kernelModule);
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../
|
|
2
|
+
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
+
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Handling and catch a Node.js error.
|
|
7
7
|
*/
|
|
8
8
|
export default class StackTraceEvalError extends StackTraceError {
|
|
9
9
|
constructor(message: string) {
|
|
10
|
-
super(message,
|
|
10
|
+
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../
|
|
2
|
+
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
+
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -8,6 +8,6 @@ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpS
|
|
|
8
8
|
*/
|
|
9
9
|
export default class StackTraceGeneralError extends StackTraceError {
|
|
10
10
|
constructor(message: string) {
|
|
11
|
-
super(message,
|
|
11
|
+
super(message, errorName.evalError, status.INTERNAL_SERVER_ERROR, false);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../
|
|
2
|
+
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
+
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Handling and catch a Node.js error.
|
|
7
7
|
*/
|
|
8
8
|
export default class StackTraceOpenSSLError extends StackTraceError {
|
|
9
9
|
constructor(message: string) {
|
|
10
|
-
super(message,
|
|
10
|
+
super(message, errorName.evalError, status.INTERNAL_SERVER_ERROR, false);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../
|
|
2
|
+
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
+
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Handling and catch a Node.js error.
|
|
7
7
|
*/
|
|
8
8
|
export default class StackTraceRangeError extends StackTraceError {
|
|
9
9
|
constructor(message: string) {
|
|
10
|
-
super(message,
|
|
10
|
+
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../
|
|
2
|
+
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
+
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -8,6 +8,6 @@ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpS
|
|
|
8
8
|
*/
|
|
9
9
|
export default class StackTraceReferenceError extends StackTraceError {
|
|
10
10
|
constructor(message: string) {
|
|
11
|
-
super(message,
|
|
11
|
+
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../
|
|
2
|
+
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
+
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Handling and catch a Node.js error.
|
|
7
7
|
*/
|
|
8
8
|
export default class StackTraceSyntaxError extends StackTraceError {
|
|
9
9
|
constructor(message: string) {
|
|
10
|
-
super(message,
|
|
10
|
+
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../
|
|
2
|
+
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
+
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -8,7 +8,7 @@ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpS
|
|
|
8
8
|
*/
|
|
9
9
|
export default class StackTraceSystemError extends StackTraceError {
|
|
10
10
|
constructor(message: string, code: string) {
|
|
11
|
-
super(message,
|
|
11
|
+
super(message, errorName.systemError, status.INTERNAL_SERVER_ERROR, false);
|
|
12
12
|
this.message = `${message} (code: ${code})`;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../
|
|
2
|
+
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
+
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -8,6 +8,6 @@ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpS
|
|
|
8
8
|
*/
|
|
9
9
|
export default class StackTraceTypeError extends StackTraceError {
|
|
10
10
|
constructor(message: string) {
|
|
11
|
-
super(message,
|
|
11
|
+
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import StackTraceError from "./base/stackTraceError";
|
|
2
|
-
import {
|
|
3
|
-
import {HttpStatusCodesConstant as status} from "../../../
|
|
2
|
+
import {CErrorName as errorName} from "../../../domains/constants/errorName.constant";
|
|
3
|
+
import {HttpStatusCodesConstant as status} from "../../../domains/constants/httpStatusCodes.constant";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -8,6 +8,6 @@ import {HttpStatusCodesConstant as status} from "../../../domain/constants/httpS
|
|
|
8
8
|
*/
|
|
9
9
|
export default class StackTraceURIError extends StackTraceError {
|
|
10
10
|
constructor(message: string) {
|
|
11
|
-
super(message,
|
|
11
|
+
super(message, errorName.evalError, status.BAD_REQUEST, true);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -2,7 +2,7 @@ import express, {Express} from "express";
|
|
|
2
2
|
import process from 'node:process';
|
|
3
3
|
import EventEmitter from "node:events";
|
|
4
4
|
import {eventName, event} from "../../index";
|
|
5
|
-
import {ServerListenEventError} from "
|
|
5
|
+
import {ServerListenEventError} from "@webApp/core/events/errors/serverListen.event.error";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
*
|