Pixel route.

This commit is contained in:
Mike Cao 2025-08-18 15:49:10 -07:00
parent 3c5c1e48e9
commit 0ac8bd41b6
10 changed files with 139 additions and 64 deletions

View file

@ -89,8 +89,8 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
export async function getLocation(ip: string = '', headers: Headers, hasPayloadIP: boolean) {
// Ignore local ips
if (await isLocalhost(ip)) {
return;
if (!ip || (await isLocalhost(ip))) {
return null;
}
if (!hasPayloadIP && !process.env.SKIP_LOCATION_HEADERS) {
@ -130,7 +130,7 @@ export async function getLocation(ip: string = '', headers: Headers, hasPayloadI
);
}
const result = globalThis[MAXMIND].get(ip?.split(':')[0]);
const result = globalThis[MAXMIND]?.get(ip?.split(':')[0]);
if (result) {
const country = result.country?.iso_code ?? result?.registered_country?.iso_code;