opticore-webapp 1.0.8 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +139 -599
- package/dist/index.d.cts +5 -63
- package/dist/index.d.ts +5 -63
- package/dist/index.js +146 -594
- package/package.json +7 -6
- package/src/application/service/core.service.ts +11 -8
- package/src/core/handlers/eventProcess.handler.ts +8 -5
- package/src/core/utils/logMessage.utils.ts +2 -2
- package/src/core/utils/modulesLoaded.utils.ts +5 -4
- package/src/core/webServer.core.ts +25 -21
- package/src/domains/interfaces/routeDefinition.interface.ts +2 -2
- package/src/domains/types/kernelModule.type.ts +1 -1
- package/src/index.ts +1 -8
- package/tsup.config.ts +1 -1
- package/src/core/events/errors/serverListen.event.error.ts +0 -335
- package/src/core/events/requestCalls.event.ts +0 -83
- package/src/core/handlers/errors/base/stackTraceError.ts +0 -23
- package/src/core/handlers/errors/stackTraceAssertionError.ts +0 -13
- package/src/core/handlers/errors/stackTraceEvalError.ts +0 -12
- package/src/core/handlers/errors/stackTraceGeneralError.ts +0 -13
- package/src/core/handlers/errors/stackTraceOpenSSLError.ts +0 -12
- package/src/core/handlers/errors/stackTraceRangeError.ts +0 -12
- package/src/core/handlers/errors/stackTraceReferenceError.ts +0 -13
- package/src/core/handlers/errors/stackTraceSyntaxError.ts +0 -12
- package/src/core/handlers/errors/stackTraceSystemError.ts +0 -14
- package/src/core/handlers/errors/stackTraceTypeError.ts +0 -13
- package/src/core/handlers/errors/stackTraceURIError.ts +0 -13
- package/src/domains/constants/errorName.constant.ts +0 -12
- package/src/domains/constants/event.constant.ts +0 -15
- package/src/domains/constants/eventNameError.constant.ts +0 -8
- package/src/domains/constants/httpStatusCodes.constant.ts +0 -375
- package/src/domains/constants/logLevel.constant.ts +0 -6
- package/src/domains/env/access.env.ts +0 -23
- package/src/domains/interfaces/envVariables.interface.ts +0 -16
- package/src/domains/interfaces/kernelModule.interface.ts +0 -6
- package/src/infrastructure/events/.gitkeep +0 -0
- package/src/infrastructure/handlers/.gitkeep +0 -0
- package/src/presentation/middleware/.gitkeep +0 -0
- /package/src/core/{errors → events}/.gitkeep +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opticore-webapp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "wep server",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -25,21 +25,22 @@
|
|
|
25
25
|
"homepage": "https://github.com/guyzoum77/opticore-webApp#readme",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"ansi-colors": "^4.1.3",
|
|
28
|
+
"chalk": "^5.4.1",
|
|
28
29
|
"cors": "^2.8.5",
|
|
29
30
|
"dotenv": "^16.4.7",
|
|
30
|
-
"express": "^4.21.0",
|
|
31
|
-
"express-rate-limit": "^5.5.1",
|
|
32
|
-
"express-session": "^1.0.0",
|
|
33
|
-
"express-useragent": "^1.0.15",
|
|
34
31
|
"gradient-string": "^2.0.2",
|
|
32
|
+
"opticore-catch-exception-error": "^1.0.1",
|
|
33
|
+
"opticore-env-access": "^1.0.2",
|
|
34
|
+
"opticore-express": "^1.0.3",
|
|
35
|
+
"opticore-http-response": "^1.0.3",
|
|
35
36
|
"opticore-logger": "^1.0.10",
|
|
37
|
+
"opticore-requests-called-events": "^1.0.0",
|
|
36
38
|
"opticore-router": "^1.0.7",
|
|
37
39
|
"opticore-validator": "^1.0.3",
|
|
38
40
|
"typescript": "^5.4.5"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
41
43
|
"@types/cors": "^2.8.17",
|
|
42
|
-
"@types/express": "^4.17.21",
|
|
43
44
|
"@types/gradient-string": "^1.1.6",
|
|
44
45
|
"tsup": "^8.3.5"
|
|
45
46
|
}
|
|
@@ -3,12 +3,15 @@ import chalk from 'chalk';
|
|
|
3
3
|
import * as path from "path";
|
|
4
4
|
import * as fs from "fs";
|
|
5
5
|
import colors from "ansi-colors";
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import StackTraceError from "
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
import {
|
|
6
|
+
|
|
7
|
+
import { HttpStatusCode as status } from "opticore-http-response";
|
|
8
|
+
import { StackTraceError } from "opticore-catch-exception-error";
|
|
9
|
+
import { Router } from "opticore-express";
|
|
10
|
+
|
|
11
|
+
import { KernelModuleType } from "@webApp/domains/types/kernelModule.type";
|
|
12
|
+
import { modulesLoadedUtils as loadedModules } from "@webApp/core/utils/modulesLoaded.utils";
|
|
13
|
+
import { messageException as msg } from "@webApp/application/exceptions/messages.exception";
|
|
14
|
+
|
|
12
15
|
|
|
13
16
|
|
|
14
17
|
export class CoreService {
|
|
@@ -153,12 +156,12 @@ export class CoreService {
|
|
|
153
156
|
}
|
|
154
157
|
|
|
155
158
|
public coreListenerEventLoaderModuleService<T extends KernelModuleType>(kernelModule: T) {
|
|
156
|
-
let router:
|
|
159
|
+
let router: Router[] = [];
|
|
157
160
|
let dbCon: (() => void) | undefined;
|
|
158
161
|
|
|
159
162
|
kernelModule.forEach((module): void => {
|
|
160
163
|
if (Array.isArray(module)) {
|
|
161
|
-
router = module as
|
|
164
|
+
router = module as Router[];
|
|
162
165
|
} else if (typeof module === "function") {
|
|
163
166
|
dbCon = module as () => void;
|
|
164
167
|
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import express, {Express} from "express";
|
|
2
1
|
import process from 'node:process';
|
|
3
2
|
import EventEmitter from "node:events";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { express, NextFunction } from "opticore-express";
|
|
4
|
+
import {
|
|
5
|
+
ServerListenEventError,
|
|
6
|
+
CEventNameError as eventName,
|
|
7
|
+
CEvent as event
|
|
8
|
+
} from "opticore-catch-exception-error";
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
*
|
|
9
12
|
*/
|
|
10
13
|
export function eventProcessHandler(): void {
|
|
11
14
|
const errorEmitter = new EventEmitter();
|
|
12
|
-
const app
|
|
15
|
+
const app = express();
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Listener for error events
|
|
@@ -100,7 +103,7 @@ export function eventProcessHandler(): void {
|
|
|
100
103
|
/**
|
|
101
104
|
* Express error-handling middleware
|
|
102
105
|
*/
|
|
103
|
-
app.use((err: Error, req:
|
|
106
|
+
app.use((err: Error, req: Request, res: Response, next: NextFunction): void => {
|
|
104
107
|
ServerListenEventError.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
|
|
105
108
|
});
|
|
106
109
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
import {dateTimeFormattedUtils} from "./dateTimeFormatted.utils";
|
|
1
|
+
import colors from "ansi-colors";
|
|
2
|
+
import { dateTimeFormattedUtils } from "./dateTimeFormatted.utils";
|
|
3
3
|
|
|
4
4
|
export class LogMessageUtils {
|
|
5
5
|
static success(title: string, action: string, contentAction: string): void {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import colors from "ansi-colors";
|
|
2
|
-
import
|
|
3
|
-
import {dateTimeFormattedUtils} from "./dateTimeFormatted.utils";
|
|
4
|
-
import {LogMessageUtils} from "@webApp/core/utils/logMessage.utils";
|
|
2
|
+
import { Router } from "opticore-express";
|
|
3
|
+
import { dateTimeFormattedUtils } from "./dateTimeFormatted.utils";
|
|
4
|
+
import { LogMessageUtils } from "@webApp/core/utils/logMessage.utils";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
export function modulesLoadedUtils(allAppRoutes: Router[], dbConChecker: () => void): void {
|
|
8
9
|
LogMessageUtils.success("Kernel", "load kernel", "Modules app have been successfully loaded");
|
|
9
10
|
console.log(`${colors.whiteBright(` content`)} ${colors.green('Kernel :')} ${colors.cyan(`${colors.bold(`server side`)}`)} has been loaded successfully ${colors.green(`✔`)}`);
|
|
10
11
|
allAppRoutes
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
import {Server as serverWebApp} from "http";
|
|
2
|
-
import {IncomingMessage, ServerResponse} from "node:http";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {requestCallsEvent} from "
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
1
|
+
import { Server as serverWebApp } from "http";
|
|
2
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
3
|
+
import corsOrigin, { CorsOptions } from "cors";
|
|
4
|
+
import {
|
|
5
|
+
CEventNameError as eventName,
|
|
6
|
+
StackTraceError,
|
|
7
|
+
ServerListenEventError as eventErrorOnListeningServer
|
|
8
|
+
} from "opticore-catch-exception-error";
|
|
9
|
+
import { Application, express, Express } from "opticore-express";
|
|
10
|
+
import { getEnvVariable } from "opticore-env-access";
|
|
11
|
+
import { requestCallsEvent } from "opticore-requests-called-events";
|
|
12
|
+
import { HttpStatusCode } from "opticore-http-response";
|
|
13
|
+
|
|
14
|
+
import { IRouteDefinition } from "@webApp/domains/interfaces/routeDefinition.interface";
|
|
15
|
+
import { KernelModuleType } from "@webApp/domains/types/kernelModule.type";
|
|
16
|
+
import { eventProcessHandler } from "@webApp/core/handlers/eventProcess.handler";
|
|
17
|
+
import { CoreService } from "@webApp/application/service/core.service";
|
|
18
|
+
import { dateTimeFormattedUtils as currentDate } from "@webApp/core/utils/dateTimeFormatted.utils";
|
|
19
|
+
|
|
20
|
+
|
|
16
21
|
|
|
17
22
|
|
|
18
23
|
export class WebServerCore {
|
|
19
24
|
private serverUtility: CoreService = new CoreService();
|
|
20
|
-
private expressApp
|
|
21
|
-
private readonly routerExpressApp:
|
|
25
|
+
private expressApp = express();
|
|
26
|
+
private readonly routerExpressApp: Application;
|
|
22
27
|
private readonly port: number;
|
|
23
28
|
private readonly host: string;
|
|
24
29
|
|
|
25
|
-
constructor(app:
|
|
30
|
+
constructor(app: Application, corsOriginOptions?: Partial<CorsOptions>) {
|
|
26
31
|
this.port = Number(getEnvVariable.appPort);
|
|
27
32
|
this.host = getEnvVariable.appHost;
|
|
28
33
|
this.routerExpressApp = app;
|
|
@@ -52,7 +57,7 @@ export class WebServerCore {
|
|
|
52
57
|
this.registerRoutes(routers);
|
|
53
58
|
}
|
|
54
59
|
} catch (err: any) {
|
|
55
|
-
this.traceError(err.message, "Error",
|
|
60
|
+
this.traceError(err.message, "Error", HttpStatusCode.NOT_ACCEPTABLE);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
);
|
|
@@ -77,8 +82,7 @@ export class WebServerCore {
|
|
|
77
82
|
});
|
|
78
83
|
}
|
|
79
84
|
|
|
80
|
-
public kernelModules(registerRouter: { featureRoute: IRouteDefinition[] }[],
|
|
81
|
-
dbConnection: () => void): KernelModuleType {
|
|
85
|
+
public kernelModules(registerRouter: { featureRoute: IRouteDefinition[] }[], dbConnection: () => void): KernelModuleType {
|
|
82
86
|
return [registerRouter, dbConnection] as KernelModuleType
|
|
83
87
|
}
|
|
84
88
|
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import { WebServerCore as WebServer } from "@webApp/core/webServer.core";
|
|
2
|
-
|
|
3
|
-
import { CErrorName as errorName } from "@webApp/domains/constants/errorName.constant";
|
|
4
|
-
import { CEvent as event } from "@webApp/domains/constants/event.constant";
|
|
5
|
-
import { CEventNameError as eventName } from "@webApp/domains/constants/eventNameError.constant";
|
|
2
|
+
|
|
6
3
|
|
|
7
4
|
import { type IRouteDefinition } from "@webApp/domains/interfaces/routeDefinition.interface";
|
|
8
5
|
import { type KernelModuleType } from "@webApp/domains/types/kernelModule.type";
|
|
9
6
|
|
|
10
7
|
export {
|
|
11
|
-
errorName,
|
|
12
|
-
eventName,
|
|
13
|
-
event,
|
|
14
|
-
getEnvVariable,
|
|
15
8
|
IRouteDefinition,
|
|
16
9
|
KernelModuleType,
|
|
17
10
|
WebServer,
|
package/tsup.config.ts
CHANGED
|
@@ -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
|
-
}
|