Skip to content

Commit

Permalink
use forwarded ip first, bump v1.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
shunjizhan committed Aug 1, 2024
1 parent da33a62 commit d89ede5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "acala-wormhole-relayer",
"version": "1.8.4",
"version": "1.8.5",
"description": "",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,4 @@ export const MINUTE = 60 * SECOND;
export const HOUR = 60 * MINUTE;
export const DAY = 24 * HOUR;

export const VERSION = '1.8.4';
export const VERSION = '1.8.5';
11 changes: 9 additions & 2 deletions src/utils/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Request } from 'express';

export const parseIp = (req: Request): string => {
const rawIp = req.ip
?? req.headers['x-forwarded-for']
const forwardedFor = req.headers['x-forwarded-for'];
const forwardedIp = typeof forwardedFor === 'string'
? forwardedFor.split(',')[0]
: Array.isArray(forwardedFor)
? forwardedFor[0]
: undefined;

const rawIp = forwardedIp
?? req.ip
?? req.socket.remoteAddress
?? 'unknown';

Expand Down

0 comments on commit d89ede5

Please sign in to comment.