diff --git a/package.json b/package.json index fe41eb5..02cea66 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "build": "tsc", "start": "node dist/index.js", "start:test-stack": "docker compose up -d", - "dev": "ts-node-dev --respawn src/index.ts | pino-pretty --singleLine --colorize --ignore time,hostname", + "dev": "ts-node-dev --respawn src/index.ts | pino-pretty --singleLine --colorize --ignore time,hostname,ip", "test": "vitest src/__tests__/*.test.ts --singleThread", "test:coverage": "COVERAGE=1 yarn test --coverage", "test:ci": "yarn start:test-stack; yarn test:coverage", diff --git a/src/middlewares/router.ts b/src/middlewares/router.ts index b31e600..8bffbaf 100644 --- a/src/middlewares/router.ts +++ b/src/middlewares/router.ts @@ -33,6 +33,7 @@ import { shouldRouteXcm, } from '../api'; import { shouldSwapAndRoute, swapAndRoute } from '../api/swapAndRoute'; +import { parseIp } from '../utils/formatter'; interface RouterConfig { schema?: Schema; @@ -128,7 +129,8 @@ const handleRoute = async (req: Request, res: Response) => { ? req.body : req.query; - logger.info({ args }, `⬇ ${reqPath}`); + const ip = parseIp(req); + logger.info({ args, ip }, `⬇ ${reqPath}`); const config = ROUTER_CONFIGS[method]?.[path]; if (!config) { diff --git a/src/utils/formatter.ts b/src/utils/formatter.ts new file mode 100644 index 0000000..6c2d775 --- /dev/null +++ b/src/utils/formatter.ts @@ -0,0 +1,10 @@ +import { Request } from 'express'; + +export const parseIp = (req: Request): string => { + const rawIp = req.ip + ?? req.headers['x-forwarded-for'] + ?? req.socket.remoteAddress + ?? 'unknown'; + + return rawIp.replace(/^::ffff:/, ''); // remove ipv6 prefix +};