Remove insecure and bloated module

This commit is contained in:
Cooldude2606 committed 2024-01-18 18:50:30 +00:00
1 parent 9bcbc1e7f3
commit 0e68596fbd
3 files changed
+47 -13

No files matched your search

+43 -8
View File
@@ -3,7 +3,6 @@ import { BlockList, type AddressInfo, isIPv4, isIPv6 } from "net";
import type { ControllerArgs } from "../controller";
import express, { type Request, type Response, type NextFunction, type Application } from "express";
import type { Static } from "@sinclair/typebox";
import * as expressWinston from "express-winston";
import compression from "compression";
import events, { EventEmitter } from "events";
@@ -165,10 +164,31 @@ export default class Controller {
this.app = express();
this.app.locals.controller = this;
this.app.locals.streams = new Map();
this.app.use(expressWinston.logger({
winstonInstance: this.clusterLogger,
level: "http",
}));
// Log all requests made to express
this.app.use((req, res, next) => {
const startNs = process.hrtime.bigint();
res.once("finish", () => {
const endNs = process.hrtime.bigint();
const durationMs = (Number(endNs - startNs) / 1e6);
logger.log({
level: "http",
message: `HTTP ${req.httpVersion} ${req.method} ${req.originalUrl}` +
` (Status ${res.statusCode} in ${durationMs}ms)`,
meta: {
method: req.method,
url: req.originalUrl,
statusCode: res.statusCode,
responseTime: durationMs,
httpVersion: req.httpVersion,
headers: req.headers,
query: req.query,
},
});
});
next();
});
this.trustedProxies = this.parseTrustedProxies();
this.wsServer = new WsServer(this);
@@ -288,9 +308,24 @@ export default class Controller {
// Load plugins
await this.loadPlugins();
this.app.use(expressWinston.errorLogger({
winstonInstance: this.clusterLogger,
}));
// Log all express errors from middleware or routes (app.use is missing the type overload)
this.app.use((err: Error, req: express.Request, res: express.Response, next: express.NextFunction): void => {
logger.log({
level: "error",
message: "Error while handling HTTP" +
`${req.httpVersion} ${req.method} ${req.originalUrl}:\n${err.stack}`,
meta: {
method: req.method,
url: req.originalUrl,
httpVersion: req.httpVersion,
headers: req.headers,
query: req.query,
},
});
next();
});
this.wsServer = new WsServer(this);