add support for CloudFront headers in getLocation

This commit is contained in:
Michael Wallner 2025-08-26 17:28:13 +02:00
parent 04fd5d370c
commit 8df72c55e5
No known key found for this signature in database
GPG key ID: 84874FC650A92153

View file

@ -119,6 +119,19 @@ export async function getLocation(ip: string = '', headers: Headers, hasPayloadI
city,
};
}
// CloudFront headers
if (headers.get('cloudfront-viewer-country')) {
const country = decodeHeader(headers.get('cloudfront-viewer-country'));
const region = decodeHeader(headers.get('cloudfront-viewer-country-region'));
const city = decodeHeader(headers.get('cloudfront-viewer-city'));
return {
country,
region: getRegionCode(country, region),
city,
};
}
}
// Database lookup