diff --git a/src/pages/api/geo.ts b/src/pages/api/geo.ts index e249653..bbd3ad0 100644 --- a/src/pages/api/geo.ts +++ b/src/pages/api/geo.ts @@ -52,14 +52,16 @@ export const GET: APIRoute = async ({ request, locals }) => { request.headers.get('x-forwarded-for')?.split(',')[0]?.trim() || '127.0.0.1'; - // 2. Safely resolve persistent Cloudflare KV (without touching deprecated locals.runtime.env) + // 2. Safely resolve persistent Cloudflare KV let kv: any = null; try { - if ((locals as any)?.env) { + if ((locals as any)?.env?.GEO_KV || (locals as any)?.env?.GEO_ANALYTICS) { kv = (locals as any).env.GEO_KV || (locals as any).env.GEO_ANALYTICS; + } else if ((locals as any)?.runtime?.env?.GEO_KV || (locals as any)?.runtime?.env?.GEO_ANALYTICS) { + kv = (locals as any).runtime.env.GEO_KV || (locals as any).runtime.env.GEO_ANALYTICS; } } catch { - // ignore + // ignore - fall back to edge memory } let activeCounts: Record = { ...visitorCounts };