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]); });