feat: let a deployment choose its geocoders, or none, via OSRM_GEOCODERS - #527
Merged
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
🟢 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_GEOCODERSparsing inleaflet_options(array or JSON string; supports bare-string entries; emptyurl=> 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #321. Part of #160.
Address search and the reverse lookups that name dropped, dragged and URL-restored waypoints go to
nominatim.openstreetmap.orgwith no way to redirect or stop them at runtime.NOMINATIM_ENDPOINTis 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
OSRM_GEOCODERS{name, url}, shaped likeOSRM_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:latestAn entry whose
urlis empty is the coordinates-only geocoder — it contacts nothing:docker run -p 9966:9966 -e 'OSRM_GEOCODERS=[{"url":""}]' ghcr.io/project-osrm/osrm-frontend:latestNotable decisions
reverseis what disables the lookups. LRM'sGeocoderElementfalls straight through towaypointNameFallbackwhen the geocoder has noreversemethod, 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.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.geocodeandsuggestparse them locally; only the network lookups go away.OSRM_GEOCODERSkeeps the single build-time entry, so an untouched deployment is byte-for-byte unchanged and theNOMINATIM_ENDPOINTsubstitution keeps working.leafletOptions.geocodersis a getter, so it reflects the current runtime config the same wayservicesdoes.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_GEOCODERSunset the two waypoints resolve to "White House, …" and "United States Capitol, …"; with the coordinates-only entry they read38.897700, -77.036500and38.889900, -77.009100, with no geocoder request and an identical route.🤖 Claude Code, Claude Opus 5