Commit 99a9823
fix: support Docker runtime routing config with OSRM_MODES (#423)
* fix: support environment overrides at runtime via docker run -e
Fixes issue #421: Environment override no longer supported.
Users can now override configuration at container runtime using environment variables:
docker run -e OSRM_BACKEND='http://localhost:5001' osrm-frontend
This works as documented by:
1. Creating docker/entrypoint.sh that reads OSRM_* env vars at startup
2. Generating config.json from env vars before nginx starts
3. Loading config.json in index.html before the app bundle runs
4. Using config values in src/leaflet_options.js
Supported environment variables:
- OSRM_BACKEND: Backend routing service URL
- OSRM_CENTER: Map center coordinates (lat,lng)
- OSRM_ZOOM: Initial map zoom level
- OSRM_LANGUAGE: UI language
- OSRM_LABEL: Default routing service label
- OSRM_DEFAULT_LAYER: Default map layer
Build-time configuration still supported via --build-arg.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: address PR review comments for runtime env config
- Fix entrypoint.sh to accept CMD and exec "$@" for standard Docker behavior
- Add JSON escaping in entrypoint.sh to handle special characters in config values
- Validate OSRM_ZOOM to ensure numeric output in JSON
- Change default OSRM_BACKEND from router.project-osrm.org to localhost:5000
(matches README.md documentation)
- Replace synchronous XHR with async fetch in index.html (sync XHR deprecated)
- Fix 404 handling in index.html (XHR fires onload, not onerror for 404)
- Add input validation to leaflet_options.js:
* parseCenter() validates lat/lng, falls back to defaults if invalid
* getZoom() validates numeric value, falls back if NaN
- Add comprehensive test coverage for config overrides in leaflet_options.test.js:
* Tests for OSRM_BACKEND, OSRM_CENTER, OSRM_ZOOM, OSRM_LANGUAGE
* Tests for invalid/edge case values with fallback behavior
* 13 new tests added (now 112 total tests passing)
All tests pass, linting passes, Docker builds and runs correctly.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: use configurable backend for all routing modes (bike, foot)
All three routing modes (driving, bike, foot) now use the same configurable
OSRM_BACKEND, defaulting to localhost:5000 as documented in README.md.
Previously, Bike and Foot modes were hardcoded to routing.openstreetmap.de,
making it impossible to use a local OSRM instance for all modes when deployed
in Docker.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: distinguish Docker vs local dev backends
Introduce OSRM_ENVIRONMENT to differentiate execution context:
- Docker: All modes (driving, bike, foot) use localhost:5000 backend
- Local dev: Bike/foot use public routing.openstreetmap.de services
Changes:
- Add OSRM_ENVIRONMENT env var to Dockerfile (set to 'docker')
- Include OSRM_ENVIRONMENT in generated config.json via entrypoint
- Add getAlternativeBackend() that returns backend for bike/foot based on environment
- Update services array to use public routing services in dev, localhost in Docker
Benefits:
- Docker users can run full-featured local OSRM stack without modification
- Local dev still works with public services (bike/foot) when no local OSRM installed
- No breaking changes to existing behavior
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: use public routing services in dev mode
In local dev (no OSRM_ENVIRONMENT), all routing modes now use public services:
- Driving: router.project-osrm.org
- Bike: routing.openstreetmap.de/routed-bike
- Foot: routing.openstreetmap.de/routed-foot
In Docker (OSRM_ENVIRONMENT=docker), all modes use localhost:5000 backend
for a fully local setup.
Updates:
- Refactor getBackend() to return public service URL in dev mode
- Update tests to expect public services in dev, localhost in Docker
- Add test for Docker mode explicitly
Now 113 tests pass (1 additional test for Docker mode).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat: support per-mode backend configuration
- Add OSRM_BACKEND_DRIVING, OSRM_BACKEND_BIKE, OSRM_BACKEND_FOOT env vars
- Each mode can now have its own backend URL override
- In Docker: all modes default to localhost:5000, but can be customized per mode
- In dev: all three modes available (driving via router.project-osrm.org, bike/foot via routing.openstreetmap.de)
- Backward compatible: OSRM_BACKEND still works as fallback for all modes
- Add 6 tests covering per-mode backend configuration and dev mode availability
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat: support freely-named routing modes via OSRM_MODES JSON
Allow users to define custom names and URLs for routing modes by providing
/etc/osrm/modes.json with a JSON array of {name, url} pairs.
Example modes.json:
[
{ "name": "Car (fastest)", "url": "http://localhost:5000" },
{ "name": "Scenic Route", "url": "http://localhost:5001" },
{ "name": "Walking", "url": "http://localhost:5000" }
]
- Entrypoint now reads /etc/osrm/modes.json at startup (Docker only)
- Falls back to default modes if file not present:
- Docker: Car, Bike, Foot (all using localhost:5000)
- Dev: Car (router.project-osrm.org), Bike (routing.openstreetmap.de), Foot (routing.openstreetmap.de)
- leaflet_options.js now parses OSRM_MODES from config
- Each mode internally mapped to a routing profile (driving, bike, foot)
- Respects OSRM_BACKEND for first mode's URL in default config
- Add 7 tests covering custom modes, default fallbacks, and JSON parsing
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat: support OSRM_MODES via environment variable for docker run
Users can now provide modes directly via docker run without mounting a file:
docker run -e OSRM_MODES='[{"name":"Car","url":"http://localhost:5000"}]' osrm-frontend
Priority order for modes configuration:
1. OSRM_MODES environment variable (highest priority)
2. /etc/osrm/modes.json file (if mounted via -v volume)
3. Default modes (car/bike/foot using localhost:5000)
This makes it convenient for both quick testing and production deployments.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: correct default modes for dev vs Docker
Dev mode (not in Docker):
- Uses three public routing profiles: driving, bike, foot
- Unless OSRM_BACKEND is explicitly provided (then uses just that one)
Docker mode:
- Uses single 'default' profile pointing to localhost:5000
- Can be overridden via OSRM_BACKEND env var or OSRM_MODES JSON
This ensures:
- Dev users see all three public OSRM services
- Docker users get a simple single-mode setup by default
- Either can be customized via environment variables
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: remove localhost default from dev config
Dev mode (npm start) should use public OSRM services, not localhost.
Removed OSRM_BACKEND and OSRM_LABEL from index.html defaults so that
in dev mode, parseModes() correctly defaults to three public profiles
(driving via router.project-osrm.org, bike/foot via routing.openstreetmap.de).
Only Docker mode should default to localhost:5000.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat: add backward compatibility for OSRM_BACKEND with deprecation warning
Supports both old (OSRM_BACKEND) and new (OSRM_MODES) environment variables:
Priority order:
1. OSRM_MODES (new JSON-based modes, highest priority)
2. OSRM_BACKEND (legacy, triggers deprecation warning)
3. Defaults (public services in dev, localhost in Docker)
Deprecation behavior:
- If only OSRM_BACKEND is set: creates single 'default' mode, warns to migrate
- If only OSRM_MODES is set: uses new behavior, no warning
- If both are set: uses OSRM_MODES, warns about both being configured
Example migrations:
Old: docker run -e OSRM_BACKEND='http://localhost:5000'
New: docker run -e OSRM_MODES='[{"name":"default","url":"http://localhost:5000"}]'
Add 3 tests verifying backward compat and deprecation warnings.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* debug: add console logging to diagnose bike/foot backend routing issue
Add detailed logging to parseModes() and buildServices() to see:
- What config is being read
- Which code path is taken (dev vs docker)
- What services array is built
This will help diagnose why bike and foot profiles are routing to
localhost instead of routing.openstreetmap.de in dev mode.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: correct routing backends for all three modes
Dev mode (npm start):
- driving: router.project-osrm.org
- bike: routing.openstreetmap.de/routed-bike with correct path
- foot: routing.openstreetmap.de/routed-foot with correct path
Docker mode (default):
- Single 'default' mode using localhost:5000
- Entrypoint prioritizes: OSRM_MODES > /etc/osrm/modes.json > OSRM_BACKEND > localhost:5000
Fixed entrypoint logic to properly handle OSRM_BACKEND default value
without overriding it prematurely.
Removed debug logging - all 120 tests passing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* feat: Docker defaults to public demo instances like dev mode
Docker now defaults to the same three public profiles as dev mode:
- driving: router.project-osrm.org
- bike: routing.openstreetmap.de/routed-bike
- foot: routing.openstreetmap.de/routed-foot
Users can override with:
- OSRM_MODES=... (JSON)
- OSRM_BACKEND=... (legacy, single mode)
- /etc/osrm/modes.json (file mount)
All 120 tests passing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: revert Docker to localhost:5000 by default
Docker container should default to localhost:5000 with single 'default'
profile unless explicitly configured with env vars.
Dev mode (npm start) continues to use public demo instances.
The distinction is controlled by OSRM_ENVIRONMENT:
- If 'docker' (set by entrypoint): use localhost:5000
- Otherwise (dev/browser): use public instances
All 120 tests passing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: make services lazy-loaded to respect runtime config
Changed services from being computed at module load time to being
computed lazily via a getter. This ensures that when buildServices()
is called, window.osrmConfig has already been updated by config.json
loading (in Docker) or remains with dev defaults (in npm start).
This fixes the issue where Docker was reading config before
OSRM_ENVIRONMENT was set from the loaded config.json.
All 120 tests passing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: read config fresh from window.osrmConfig on each call
parseModes() now reads from window.osrmConfig directly instead of
using the captured config variable. Combined with lazy-loading via
getter, this ensures that OSRM_ENVIRONMENT and other config values
are always read from the current window.osrmConfig, which gets updated
when config.json is loaded.
This fixes Docker container defaulting to public instances instead of
localhost:5000 - it now correctly detects OSRM_ENVIRONMENT='docker'
from the loaded config.json.
All 120 tests passing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* fix: support Docker runtime routing config
- keep Docker default routing on http://localhost:5000 with a single default profile
- support JSON-based OSRM_MODES runtime configuration for multiple profiles
- keep OSRM_BACKEND as a deprecated single-backend fallback with warnings
- document precedence and Docker usage examples
- add tests for deprecation warnings and entrypoint config generation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent aaee5ad commit 99a9823
7 files changed
Lines changed: 716 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
21 | 46 | | |
22 | 47 | | |
23 | 48 | | |
| |||
28 | 53 | | |
29 | 54 | | |
30 | 55 | | |
31 | | - | |
| 56 | + | |
32 | 57 | | |
33 | 58 | | |
34 | 59 | | |
| |||
56 | 81 | | |
57 | 82 | | |
58 | 83 | | |
59 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
60 | 87 | | |
61 | 88 | | |
62 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
28 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
29 | 45 | | |
30 | 46 | | |
31 | 47 | | |
| |||
37 | 53 | | |
38 | 54 | | |
39 | 55 | | |
| 56 | + | |
40 | 57 | | |
| 58 | + | |
| 59 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
16 | 65 | | |
17 | 66 | | |
0 commit comments