From 10b1b2b3aa3ee549738c5ad9a27c70ec9c7639d7 Mon Sep 17 00:00:00 2001 From: Dev Date: Mon, 15 Apr 2024 00:06:53 +0100 Subject: [PATCH] Added nullguard when `req.socket.remoteAddress` is null inside `handleRequest()` --- project/src/servers/HttpServer.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/project/src/servers/HttpServer.ts b/project/src/servers/HttpServer.ts index 1adf92c6..952ed451 100644 --- a/project/src/servers/HttpServer.ts +++ b/project/src/servers/HttpServer.ts @@ -79,17 +79,20 @@ export class HttpServer if (this.httpConfig.logRequests) { // TODO: Extend to include 192.168 / 10.10 ranges or check subnet - const isLocalRequest = req.socket.remoteAddress.startsWith("127.0.0"); - if (isLocalRequest) + const isLocalRequest = req.socket.remoteAddress?.startsWith("127.0.0"); + if (typeof isLocalRequest !== "undefined") { - this.logger.info(this.localisationService.getText("client_request", req.url)); - } - else - { - this.logger.info(this.localisationService.getText("client_request_ip", { - ip: req.socket.remoteAddress, - url: req.url.replaceAll("/", "\\"), // Localisation service escapes `/` into hex code `/` - })); + if (isLocalRequest) + { + this.logger.info(this.localisationService.getText("client_request", req.url)); + } + else + { + this.logger.info(this.localisationService.getText("client_request_ip", { + ip: req.socket.remoteAddress, + url: req.url.replaceAll("/", "\\"), // Localisation service escapes `/` into hex code `/` + })); + } } }