Skip to content

Commit 764397c

Browse files
committed
feat: overpass API fallback
1 parent 2297714 commit 764397c

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/maps/api/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { APILocations } from "@/maps/schema";
22

33
export const OVERPASS_API = "https://overpass-api.de/api/interpreter";
4+
export const OVERPASS_API_FALLBACK = "https://overpass.private.coffee/api/interpreter";
45
export const GEOCODER_API = "https://photon.komoot.io/api/";
56
export const PASTEBIN_API_POST_URL =
67
"https://cors-anywhere.com/https://pastebin.com/api/api_post.php";

src/maps/api/overpass.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { safeUnion } from "@/maps/geo-utils";
1313

1414
import { cacheFetch } from "./cache";
15-
import { LOCATION_FIRST_TAG, OVERPASS_API } from "./constants";
15+
import { LOCATION_FIRST_TAG, OVERPASS_API, OVERPASS_API_FALLBACK } from "./constants";
1616
import type {
1717
EncompassingTentacleQuestionSchema,
1818
HomeGameMatchingQuestions,
@@ -26,12 +26,21 @@ export const getOverpassData = async (
2626
loadingText?: string,
2727
cacheType: CacheType = CacheType.CACHE,
2828
) => {
29-
const response = await cacheFetch(
30-
`${OVERPASS_API}?data=${encodeURIComponent(query)}`,
29+
const encodedQuery = encodeURIComponent(query);
30+
let response = await cacheFetch(
31+
`${OVERPASS_API}?data=${encodedQuery}`,
3132
loadingText,
3233
cacheType,
3334
);
3435

36+
if (!response.ok) {
37+
response = await cacheFetch(
38+
`${OVERPASS_API_FALLBACK}?data=${encodedQuery}`,
39+
loadingText,
40+
cacheType,
41+
);
42+
}
43+
3544
if (!response.ok) {
3645
toast.error(
3746
`Could not load data from Overpass: ${response.status} ${response.statusText}`,

0 commit comments

Comments
 (0)