request remote address
This commit is contained in:
parent
02a13c8f15
commit
99f4bd6b2d
@ -151,7 +151,8 @@ export type Request = {
|
|||||||
verified: boolean,
|
verified: boolean,
|
||||||
loginMethod: string
|
loginMethod: string
|
||||||
} & Session,
|
} & Session,
|
||||||
files: {[key: string]: UploadedFile}
|
files: { [key: string]: UploadedFile },
|
||||||
|
remoteAddress: string
|
||||||
} & ExpressRequest
|
} & ExpressRequest
|
||||||
|
|
||||||
export type Response = {
|
export type Response = {
|
||||||
|
@ -192,7 +192,8 @@ class Server extends EventEmitter {
|
|||||||
this.#_app.use(express.json({ limit: '10mb' }));
|
this.#_app.use(express.json({ limit: '10mb' }));
|
||||||
this.#_app.use(express.urlencoded({ extended: true }));
|
this.#_app.use(express.urlencoded({ extended: true }));
|
||||||
|
|
||||||
// Not sure why these are a problem
|
// Not sure why binding is a problem
|
||||||
|
this.#_app.use(this.#attachMisc.bind(this) as never);
|
||||||
this.#_app.use(this.#logRequest.bind(this) as never); // Logs every request
|
this.#_app.use(this.#logRequest.bind(this) as never); // Logs every request
|
||||||
this.#_app.use(this.#logError.bind(this) as never); // Logs endpoints that error and sends a 500
|
this.#_app.use(this.#logError.bind(this) as never); // Logs endpoints that error and sends a 500
|
||||||
this.#_app.use(this.#ready.bind(this) as never); // denies requests before the server is ready
|
this.#_app.use(this.#ready.bind(this) as never); // denies requests before the server is ready
|
||||||
@ -233,6 +234,11 @@ class Server extends EventEmitter {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#attachMisc (req: Request, _res: Response, next: NextFunction) {
|
||||||
|
req.remoteAddress = req.get('X-Forwarded-For') || req.socket.remoteAddress as string;
|
||||||
|
next();
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
||||||
#logError (err: Error, _req: Request, res: Response, _next: NextFunction) {
|
#logError (err: Error, _req: Request, res: Response, _next: NextFunction) {
|
||||||
this.#logger.error(`Unhandled error:\n${err.stack || err}`);
|
this.#logger.error(`Unhandled error:\n${err.stack || err}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user