From 3745fd9218241128c164edbd307202e80efc69ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Wed, 18 Dec 2024 22:25:11 +0500 Subject: [PATCH] Try to fix things. --- index.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/index.ts b/index.ts index 9bf91eb..d65cfdb 100644 --- a/index.ts +++ b/index.ts @@ -40,6 +40,17 @@ let srv = net.createServer(function(socket: net.Socket) { } let addr = a.address; socket.on('data', function(data: Buffer | string) { + if (data[0] === 'P'.charCodeAt(0)) { + if (addr == "127.0.0.1") { + let p = pp.V1ProxyProtocol.parse(String(data)); + addr = p.source.ipAddress; + if (typeof p.data === 'string') { + data = p.data; + } + } else { + console.log("Address " + addr + " tried to use proxy protocol."); + } + } switch (data[0]) { case 0x30: const store = db.prepare("INSERT INTO messages VALUES (?,?,?)"); @@ -63,13 +74,6 @@ let srv = net.createServer(function(socket: net.Socket) { socket.write(str); }); return; - case 'P'.charCodeAt(0): - if (addr == "127.0.0.1") { - addr = pp.V1ProxyProtocol.parse(String(data)).source.ipAddress; - } else { - console.log("Address " + addr + " tried to use proxy protocol."); - } - return; } console.log(addr + "???" + data[0]); });