Enable IP Geolocation in Cloudflare to Extract User Fingerprint Data from Every Request
Mad stuff!
export const extractUAData = (
req: Request
): {
country: string;
city: string;
postalCode: string;
ipv4: string;
ipv6: string;
geo: { lat: string; lng: string };
region: string;
continent: string;
timezone: string;
os: string;
} => ({
country: req.headers["cf-ipcountry"]?.toString() || "",
city: req.headers["cf-ipcity"]?.toString() || "",
postalCode: req.headers["cf-postal-code"]?.toString() || "",
ipv4:
req?.headers["x-forwarded-for"]?.toString() ||
req.headers["cf-connecting-ip"]?.toString() ||
"",
ipv6: req.headers["x-envoy-external-address"]?.toString() || "",
geo: {
lat: req.headers["cf-iplatitude"]?.toString() || "",
lng: req.headers["cf-iplongitude"]?.toString() || "",
},
region: req.headers["cf-region"]?.toString() || "",
continent: req.headers["cf-ipcontinent"]?.toString() || "",
timezone: req.headers["cf-timezone"]?.toString() || "",
os: req.headers["sec-ch-ua-platform"]?.toString() || "",
});