* server sided external api calls * fix uploading gpx files * rename api/v1/nominatim with api/v1/geocoding to prepare photon support * remove NOMINATIM_MAX_RETRIES (side-kick from other PR) * re-add nominatim url fallback * docu, env var defaults and fallbacks, docker compose files * refactor * furhter refactorings and fixes * PUBLIC_VALHALLA_ENABLED in docker compose files added * fix env var names --------- Co-authored-by: Flomp <Flomp@users.noreply.github.com>
35 lines
961 B
TypeScript
35 lines
961 B
TypeScript
import { resolveBaseUrl } from "$lib/server/url";
|
|
import type { RequestEvent } from "@sveltejs/kit";
|
|
|
|
const OVERPASS_MAX_RETRIES = 2;
|
|
|
|
function getOverpassBaseUrl(): string {
|
|
return resolveBaseUrl("OVERPASS_API_URL", "https://overpass-api.de");
|
|
}
|
|
|
|
export async function fetchOverpass(event: RequestEvent, params: URLSearchParams): Promise<Response> {
|
|
const baseUrl = getOverpassBaseUrl();
|
|
const base = new URL(baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`);
|
|
const url = new URL("api/interpreter", base);
|
|
const query = params.toString();
|
|
if (query.length) {
|
|
url.search = query;
|
|
}
|
|
|
|
let attempt = 0;
|
|
|
|
while (true) {
|
|
try {
|
|
return await event.fetch(url.toString(), {
|
|
method: "GET",
|
|
});
|
|
} catch (error) {
|
|
if (attempt < OVERPASS_MAX_RETRIES) {
|
|
attempt++;
|
|
continue;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|
|
}
|