BugFix: Proxy data, Logging with IP adresses

This commit is contained in:
2024-09-20 18:28:43 +02:00
parent 178f2b4810
commit 860d30b16f
11 changed files with 86 additions and 29 deletions

View File

@@ -0,0 +1,16 @@
import { Request } from 'express';
export interface RealIpInfo {
ip: string | undefined;
countryCode?: string;
}
export function getRealIpInfo(req: Request): RealIpInfo {
const ip =
(req.headers['cf-connecting-ip'] as string) ||
(req.headers['x-real-ip'] as string) ||
(typeof req.headers['x-forwarded-for'] === 'string' ? req.headers['x-forwarded-for'].split(',')[0] : req.connection.remoteAddress);
const countryCode = req.headers['cf-ipcountry'] as string;
return { ip, countryCode };
}