Skip to content

feat: let a deployment choose its geocoders, or none, via OSRM_GEOCODERS - #527

Merged
DennisOSRM merged 1 commit into
gh-pagesfrom
feat/geocoder-config
Sep 9, 2026
Merged

DennisOSRM merged 1 commit into
gh-pagesfrom
feat/geocoder-config

Conversation

@DennisOSRM

Copy link
Copy Markdown
Contributor

Closes #321. Part of #160.

Address search and the reverse lookups that name dropped, dragged and URL-restored waypoints go to nominatim.openstreetmap.org with no way to redirect or stop them at runtime. NOMINATIM_ENDPOINT is a build-time string substitution, so a Docker deployment cannot change it at all — which leaves an operator who may not reach third parties without an option, and puts avoidable load on the OSM servers.

What this adds

Variable Default Description
OSRM_GEOCODERS the instance baked in at build time JSON array of {name, url}, shaped like OSRM_MODES. The first entry is the one in use.
docker run -p 9966:9966 \
  -e 'OSRM_GEOCODERS=[{"name":"House Nominatim","url":"https://nominatim.internal/"}]' \
  ghcr.io/project-osrm/osrm-frontend:latest

An entry whose url is empty is the coordinates-only geocoder — it contacts nothing:

docker run -p 9966:9966 -e 'OSRM_GEOCODERS=[{"url":""}]' ghcr.io/project-osrm/osrm-frontend:latest

Notable decisions

  • Omitting reverse is what disables the lookups. LRM's GeocoderElement falls straight through to waypointNameFallback when the geocoder has no reverse method, so the coordinates-only geocoder disables the automatic request a map click, a drag or a URL-restored waypoint would otherwise trigger — no call sites had to learn about it.
  • Waypoint names switch to plain decimals (38.897700, -77.036500) when geocoding is off. The existing hemispheric fallback reads better but cannot be pasted back into the search box, which is exactly what a deployment without geocoding leaves users doing with every pinned location.
  • The search box still resolves typed coordinates. geocode and suggest parse them locally; only the network lookups go away.
  • An unset OSRM_GEOCODERS keeps the single build-time entry, so an untouched deployment is byte-for-byte unchanged and the NOMINATIM_ENDPOINT substitution keeps working.
  • A bare string entry is accepted as the URL, matching how the other list-shaped variables are forgiving about input.
  • Only the first entry is used. The selector that lets a user switch between several is a follow-up — that is the part of Add UI option to change endpoint (Nominatim to Directions API) #160 this does not cover.

leafletOptions.geocoders is a getter, so it reflects the current runtime config the same way services does.

Testing

19 new tests (test/geocoder_config.test.js, plus two entrypoint cases covering the pass-through and the empty default). Full suite (637 tests) and build pass.

Verified in the browser against both configurations: with OSRM_GEOCODERS unset the two waypoints resolve to "White House, …" and "United States Capitol, …"; with the coordinates-only entry they read 38.897700, -77.036500 and 38.889900, -77.009100, with no geocoder request and an identical route.

🤖 Claude Code, Claude Opus 5

Address search and the reverse lookups that name dropped, dragged and
URL-restored waypoints went to nominatim.openstreetmap.org with no way
to redirect or stop them at runtime: NOMINATIM_ENDPOINT is a build-time
string substitution, so a Docker deployment could not change it at all.
That leaves an operator who may not reach third parties without an
option, and puts avoidable load on the OSM servers.

OSRM_GEOCODERS names the geocoders on offer, shaped like OSRM_MODES. An
entry with an empty url is the coordinates-only geocoder: it has no
reverse method, so LRM's GeocoderElement falls straight through to the
waypoint name fallback and nothing is requested. The search box still
resolves typed coordinates, and waypoints are named in plain decimals
that paste back into it, rather than the hemispheric form that does not.

With OSRM_GEOCODERS unset the sole entry is the instance baked in at
build time, so an untouched deployment is unchanged.

Only the first entry is used for now; a later change adds the selector
that lets a user switch between several.

Refs #321, #160
Copilot AI lite review requested due to automatic review settings September 9, 2026 19:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The implementation matches the stated behavior (including “no reverse” to disable lookups), preserves defaults when unset, and is covered by focused new tests.

Pull request overview

This PR adds runtime-configurable geocoding selection for OSRM Frontend deployments via OSRM_GEOCODERS, including a “coordinates-only” option that disables network geocoding while keeping coordinate parsing in the search box—addressing the need to avoid involuntary requests to the public Nominatim instance.

Changes:

  • Introduces OSRM_GEOCODERS parsing in leaflet_options (array or JSON string; supports bare-string entries; empty url => coordinates-only).
  • Adds a coordinates-only geocoder implementation plus a pasteable decimal coordinate fallback for waypoint naming when geocoding is disabled.
  • Updates Docker runtime config emission, docs, and adds targeted tests for config parsing and the coordinates-only behavior.
File summaries
File Description
test/geocoder_config.test.js Adds unit tests covering OSRM_GEOCODERS parsing and the coordinates-only geocoder behavior.
test/entrypoint.test.js Verifies Docker entrypoint passes OSRM_GEOCODERS through (and emits empty when unset).
src/leaflet_options.js Adds geocoders getter + OSRM_GEOCODERS parsing with default fallback to bundled Nominatim.
src/index.js Switches routing geocoder and waypoint naming fallback based on whether geocoding is disabled.
src/geocoder.js Implements coordinatesOnly() geocoder and plainCoordinateNameFallback() formatting.
README.md Documents OSRM_GEOCODERS usage and the coordinates-only mode for offline/egress-restricted deployments.
docker/entrypoint.sh Passes OSRM_GEOCODERS into config.json for runtime configuration in Docker deployments.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@DennisOSRM
DennisOSRM merged commit 067092c into gh-pages Sep 9, 2026
6 checks passed
@DennisOSRM
DennisOSRM deleted the feat/geocoder-config branch September 9, 2026 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: option to disable reverse geocoding that relies on 3rd party

2 participants