skip Nominatim lookups when the server has none configured

Add GET /api/geocode/status ({configured}), like /api/overpass/status. The outline client and the last-resort place search ask it once per page and send no lookup a server without a Nominatim endpoint would refuse, so a default install no longer logs a 503 on its first named landmark or grounds ask. An older server or a failed probe leaves the capability unknown and lookups proceed as before.
This commit is contained in:
manjunath committed 2026-10-30 22:33:55 +05:30
1 parent 24228b145e
commit f32ab5446b
10 files changed
+157 -6

No files matched your search

+15
View File
@@ -1,4 +1,5 @@
import { readResponseJsonCapped } from './httpBody.js';
import { createNominatimStatus } from './nominatimStatus.js';
/**
* Browser client for the server's guarded outline route. The server owns the
@@ -61,6 +62,11 @@ export function createNominatimOutlineClient({
fetchImpl = (...args) => globalThis.fetch(...args),
endpoint = DEFAULT_ENDPOINT,
maxRemembered = 64,
// The app's own route can say up front that Nominatim is not configured;
// another endpoint is simply asked.
configured = endpoint === DEFAULT_ENDPOINT
? createNominatimStatus({ fetchImpl })
: null,
} = {}) {
let unavailable = null;
const remembered = new Map();
@@ -90,6 +96,15 @@ export function createNominatimOutlineClient({
if (remembered.has(key)) return remembered.get(key);
// A cancelled ask spends nothing.
signal?.throwIfAborted();
if (configured && (await configured()) === false) {
signal?.throwIfAborted();
unavailable = {
unavailable: true,
retryable: false,
code: 'NOMINATIM_DISABLED',
};
return unavailable;
}
const controller = new AbortController();
const abort = () => controller.abort();