feat(geo): support overriding Nominatim endpoint via env

This commit is contained in:
Luffy
2026-09-16 14:30:31 +08:00
parent 06610bd97e
commit c0195557d4
7 changed files with 30 additions and 3 deletions
+1 -1
View File
@@ -82,7 +82,7 @@ TREK_PLUGINS_ENABLED / _DEV_LINK / _IGNORE_TREK_RANGE / _DIR / _DATA_DIR / TREK_
OIDC_*, SMTP_*, FORCE_HTTPS, COOKIE_SECURE, HSTS_INCLUDE_SUBDOMAINS,
ALLOWED_ORIGINS, UNSPLASH_ACCESS_KEY, WEBAUTHN_*, TZ, ADMIN_EMAIL,
ADMIN_PASSWORD, IDEMPOTENCY_TTL_SECONDS, MCP_RATE_LIMIT (request-path check),
LLM_TIMEOUT_MS.
LLM_TIMEOUT_MS, NOMINATIM_URL.
## Exemptions — raw `process.env` stays
+1
View File
@@ -265,6 +265,7 @@ export function deriveIntegrations(raw: RawEnv) {
return {
unsplashAccessKey: raw.UNSPLASH_ACCESS_KEY?.trim(),
transitApiBase: stripTrailingSlashes(raw.TRANSIT_API_URL || 'https://api.transitous.org'),
nominatimUrl: stripTrailingSlashes(raw.NOMINATIM_URL || 'https://nominatim.openstreetmap.org'),
overpassUrl: raw.OVERPASS_URL,
// Longer than the `[timeout:20]` the query itself carries, or we abort an answer the
// mirror was still allowed to be working on. See OVERPASS_QUERY_TIMEOUT_S.
+1
View File
@@ -108,6 +108,7 @@ export const envSchema = z.object({
// Integrations
UNSPLASH_ACCESS_KEY: anyString,
TRANSIT_API_URL: url,
NOMINATIM_URL: url,
// OVERPASS_URL accepts a comma-separated endpoint list and silently drops
// non-http(s) entries today — left unvalidated to keep that behavior.
OVERPASS_URL: anyString,
+2 -2
View File
@@ -1,4 +1,5 @@
import { UA } from '../maps/maps.helpers';
import { readEnv } from '../../app-config';
/**
* The one Nominatim client.
@@ -21,7 +22,6 @@ import { UA } from '../maps/maps.helpers';
* header, not the weaker one.
*/
const BASE = 'https://nominatim.openstreetmap.org';
const MIN_INTERVAL_MS = 1100;
let lastCall = 0;
@@ -171,7 +171,7 @@ export async function nominatimFetch(
): Promise<Response> {
await throttle(opts.lane ?? 'interactive');
const signal = opts.signal ?? (opts.timeoutMs ? AbortSignal.timeout(opts.timeoutMs) : undefined);
return fetch(`${BASE}/${path}?${params.toString()}`, {
return fetch(`${readEnv().integrations.nominatimUrl}/${path}?${params.toString()}`, {
headers: { 'User-Agent': UA },
...(signal ? { signal } : {}),
});