From 8df72c55e564b10e98102b12333e5d8322f9eaa6 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 26 Aug 2025 17:28:13 +0200 Subject: [PATCH] add support for CloudFront headers in getLocation --- src/lib/detect.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib/detect.ts b/src/lib/detect.ts index 2e6a067dd..526ea2dfc 100644 --- a/src/lib/detect.ts +++ b/src/lib/detect.ts @@ -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