This commit is contained in:
Francis Cao
2026-04-29 13:11:06 -07:00
2 changed files with 6 additions and 6 deletions
+5 -3
View File
@@ -77,8 +77,10 @@ function decodeHeader(s: string | undefined | null): string | undefined | null {
} }
export async function getLocation(ip: string = '', headers: Headers, skipHeaders: boolean) { export async function getLocation(ip: string = '', headers: Headers, skipHeaders: boolean) {
// Ignore local ips const cleanIp = stripPort(ip);
if (!ip || (await isLocalhost(ip))) {
// Ignore local or invalid ips
if (!cleanIp || !ipaddr.isValid(cleanIp) || (await isLocalhost(cleanIp))) {
return null; return null;
} }
@@ -108,7 +110,7 @@ export async function getLocation(ip: string = '', headers: Headers, skipHeaders
); );
} }
const result = globalThis[MAXMIND]?.get(stripPort(ip)); const result = globalThis[MAXMIND]?.get(cleanIp);
if (result) { if (result) {
const country = result.country?.iso_code ?? result?.registered_country?.iso_code; const country = result.country?.iso_code ?? result?.registered_country?.iso_code;
+1 -3
View File
@@ -84,9 +84,7 @@ export function getIpAddress(headers: Headers) {
if (header === 'forwarded') { if (header === 'forwarded') {
const match = ip.match(/for=(\[?[0-9a-fA-F:.]+]?)/); const match = ip.match(/for=(\[?[0-9a-fA-F:.]+]?)/);
if (match) { return match ? resolveIp(match[1]) : undefined;
return resolveIp(match[1]);
}
} }
return resolveIp(ip); return resolveIp(ip);