request remote address
This commit is contained in:
parent
02a13c8f15
commit
99f4bd6b2d
@ -151,7 +151,8 @@ export type Request = {
|
||||
verified: boolean,
|
||||
loginMethod: string
|
||||
} & Session,
|
||||
files: {[key: string]: UploadedFile}
|
||||
files: { [key: string]: UploadedFile },
|
||||
remoteAddress: string
|
||||
} & ExpressRequest
|
||||
|
||||
export type Response = {
|
||||
|
@ -192,7 +192,8 @@ class Server extends EventEmitter {
|
||||
this.#_app.use(express.json({ limit: '10mb' }));
|
||||
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.#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
|
||||
@ -232,6 +233,11 @@ class Server extends EventEmitter {
|
||||
this.emit('ready');
|
||||
|
||||
}
|
||||
|
||||
#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
|
||||
#logError (err: Error, _req: Request, res: Response, _next: NextFunction) {
|
||||
|
Loading…
Reference in New Issue
Block a user