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