BugFix: Proxy data, Logging with IP adresses
This commit is contained in:
16
bizmatch-server/src/utils/ip.util.ts
Normal file
16
bizmatch-server/src/utils/ip.util.ts
Normal 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 };
|
||||
}
|
||||
Reference in New Issue
Block a user