From 8cd3c379192d6fe9f6e5cf064c3040f9a2e3f641 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Sat, 7 Sep 2024 10:24:28 -0500 Subject: [PATCH] Fall back in dev --- src/state/geolocation.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/state/geolocation.tsx b/src/state/geolocation.tsx index e6f10e3369..9c45fda800 100644 --- a/src/state/geolocation.tsx +++ b/src/state/geolocation.tsx @@ -3,6 +3,7 @@ import EventEmitter from 'eventemitter3' import {networkRetry} from '#/lib/async/retry' import {logger} from '#/logger' +import {IS_DEV} from '#/env' import {Device, device} from '#/storage' const events = new EventEmitter() @@ -28,7 +29,7 @@ export const DEFAULT_GEOLOCATION: Device['geolocation'] = { } async function getGeolocation(): Promise { - const res = await fetch(`https://ipapi.bsky.workers.dev/`) + const res = await fetch(`https://app.staging.bsky.dev/ipcc `) if (!res.ok) { throw new Error(`geolocation: lookup failed ${res.status}`) @@ -36,9 +37,9 @@ async function getGeolocation(): Promise { const json = await res.json() - if (json.country_code) { + if (json.countryCode) { return { - countryCode: json.country_code, + countryCode: json.countryCode, } } else { return undefined @@ -60,6 +61,16 @@ let geolocationResolution: Promise | undefined * resolved, use {@link ensureGeolocationResolved} */ export function beginResolveGeolocation() { + /** + * In dev, IP server is unavailable, so we just set the default geolocation + * and fail closed. + */ + if (IS_DEV) { + geolocationResolution = new Promise(y => y()) + device.set(['geolocation'], DEFAULT_GEOLOCATION) + return + } + geolocationResolution = new Promise(async resolve => { try { // Try once, fail fast