Consume headers for IP

This commit is contained in:
2024-10-30 10:38:18 -06:00
parent 6418bff35c
commit c631566ab0
2 changed files with 13 additions and 3 deletions

9
src/utils/ip.ts Normal file
View File

@@ -0,0 +1,9 @@
import { Request } from 'express';
export const ipFromRequest = (req: Request): string | undefined => {
const flyIp = req.headers['fly-client-ip'] as string | undefined;
const forwardedFor = (req.headers['x-forwarded-for'] as string)?.split(
',',
)[0];
return flyIp || forwardedFor || req.ip;
};