From 596a8106814d2607fb18d788b8cf8285612abad8 Mon Sep 17 00:00:00 2001 From: ericek111 Date: Thu, 2 Apr 2026 19:20:13 +0200 Subject: [PATCH] drop IPv6 prefix for IPv4 addrs --- src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index aefb600..8846864 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,6 +5,7 @@ import { createNodeWebSocket } from '@hono/node-ws'; import RotRouter from './RotRouter.js'; import N1mmServer from './N1mmServer.js'; import WebsocketManager from './WebsocketManager.js'; +import { getConnInfo } from '@hono/node-server/conninfo'; const router = new RotRouter(); @@ -37,7 +38,8 @@ app.post('/turn/:label', async (c) => { const body = await c.req.parseBody(); const az = Number(body['ROT']); if (isNaN(az)) return c.text('Invalid azimuth', 400); - const sourceIp = c.req.header('x-forwarded-for') ?? c.req.header('x-real-ip') ?? 'unknown'; + const rawIp = c.req.header('x-forwarded-for') ?? getConnInfo(c).remote.address ?? 'unknown'; + const sourceIp = rawIp.startsWith('::ffff:') ? rawIp.slice(7) : rawIp; const ok = router.turn(label, az, sourceIp); return ok ? c.text(`Turning ${label} to ${az}`) : c.text('Unknown rotator', 404); });