osrm-frontend
This is the frontend served at https://map.project-osrm.org.
This frontend builds heavily on top of Leaflet Routing Machine.
If you need a simple OSRM integration in your webpage, you should start from there.
Deploying the demo to GitHub Pages
The Deploy demo to GitHub Pages workflow builds and publishes dist-demo/ on each
push to gh-pages, including every pull request merge. Lint, build and tests must
pass before the site is uploaded and deployed. You can also run it from the
Actions tab with gh-pages selected;
other branches are skipped. Deployment runs are serialized, and the published
URL appears in the github-pages deployment environment.
The classic demo remains the default at /. The new vector demo is available
at /new/. Both include their own debug/ viewer and use the public services
configured in the frontend. The links between editions carry stops, routing
settings and the current map view.
Run npm run build followed by npm run assemble:demo-site from a clone that
contains the classic commit pinned in scripts/build_demo_site.sh. The
assembly step builds the classic source with deploy/classic-demo.patch and
combines it with the vector build. Serve dist-demo/ with a static server to
check both paths before publishing. GitHub Actions uploads this directory
without committing generated files to gh-pages.
One-time setup
- In repository Settings → Pages → Build and deployment, set Source to
GitHub Actions (rather than deploying directly from a branch).
- Ensure the
github-pages environment permits deployments from gh-pages.
For fully automatic deployment, do not require manual reviewer approval on
that environment.
- Merge the workflow into
gh-pages through a pull request. Pushes then deploy
automatically; use the manual trigger to retry a deployment.
No additional secrets or API tokens are needed. The deploy job uses GitHub's
built-in token with pages: write and id-token: write permissions; the build
job has read-only repository access. See GitHub's
custom Pages workflow documentation.
Custom domain with external DNS
Keep your existing DNS provider and configure a subdomain such as
map.example.com:
- In repository Settings → Pages → Custom domain, enter the hostname and
save it before updating DNS.
- At your DNS provider, create a CNAME from the hostname (e.g.
map) to
<owner>.github.io — for this repository, project-osrm.github.io. Do not
include the repository name, https://, or a path. Replace any conflicting
records for that hostname.
- Wait for GitHub's DNS check and certificate provisioning to finish, then
enable Enforce HTTPS and verify the demo and
debug/ on the custom domain.
A CNAME file is not required when publishing with a custom Actions workflow;
configure the domain in repository settings. Apex domains such as example.com
also work with external DNS, using GitHub's documented A/AAAA records or an
ALIAS/ANAME record. See the
custom domain instructions.
Using Docker
The easiest and quickest way to setup your own routing engine backend is to use Docker images we provide.
We base our Docker images on Alpine Linux and make sure they are as lightweight as possible.
Serves the frontend at http://localhost:9966 running queries against the routing engine backend:
docker run -p 9966:9966 ghcr.io/project-osrm/osrm-frontend:latest
By default Docker uses a single routing profile named default and sends requests to http://localhost:5000.
Recommended: multiple profiles with OSRM_MODES
OSRM_MODES is the current Docker runtime configuration interface. It accepts a JSON array of objects
with the following fields:
| Field |
Required |
Purpose |
name |
yes |
Label shown in the mode selector. |
url |
yes |
Backend base URL. /route/v1 is appended unless path is set. |
path |
no |
Explicit routing path, e.g. https://routing.openstreetmap.de/routed-bike/route/v1. |
profile |
no |
Internal profile (driving, bike, foot). Defaults by position: 0 → driving, 1 → bike, 2 → foot. |
tileUrl |
no |
Component vector tile URL template with {x}, {y}, {z} and optional {profile}. Set false to disable tiles for this mode. Standard /route/v1 paths infer the sibling /tile/v1 endpoint; custom paths require this field. |
debugUrl |
no |
Debug map opened by the "Open in Debug Map" tool button while this mode is active. Defaults to the bundled debug/. |
docker run -p 9966:9966 \
-e 'OSRM_MODES=[{"name":"car","url":"https://routing.openstreetmap.de/routed-car"},{"name":"foot","url":"https://routing.openstreetmap.de/routed-foot"},{"name":"bike","url":"https://routing.openstreetmap.de/routed-bike"}]' \
ghcr.io/project-osrm/osrm-frontend:latest
Deprecated: single backend with OSRM_BACKEND
OSRM_BACKEND is deprecated. It is still supported for backward compatibility and configures exactly one backend named default.
docker run -p 9966:9966 \
-e OSRM_BACKEND='http://localhost:5001' \
ghcr.io/project-osrm/osrm-frontend:latest
Precedence
- If only
OSRM_BACKEND is set, the frontend configures one backend and emits a deprecation warning.
- If only
OSRM_MODES is set, the frontend parses the JSON and configures the listed modes.
- If both are set,
OSRM_MODES wins and the frontend emits a deprecation warning for OSRM_BACKEND.
Vector backgrounds
The static demo uses Shortbread vector tiles from vector.openstreetmap.org.
OpenStreetMap and Dark Vector share one renderer and tile cache: switching between
them changes the palette without reloading tiles. Switching to another provider
hides and pauses the vector renderer, retaining its loaded tiles for the return
trip. The cache lasts for the current page session. Dark Vector uses the dark palette;
OpenStreetMap uses the original light style. Docker defaults to the classic
CARTO Streets raster layer. Set OSRM_VECTOR_STYLE to opt in to a vector source.
Set OSRM_VECTOR_STYLE to an HTTP(S) or root-relative MapLibre style JSON URL,
or images/openstreetmap/style.json for the built-in shared OSM backgrounds.
The style specifies vector tile sources, fonts, sprites and their attribution.
OSRM_VECTOR_NAME names the layer in the layer control (default: Dark Vector);
OSRM_VECTOR_ATTRIBUTION adds any required provider credit. Set these keys in
window.osrmConfig for a static deployment, or as Docker environment variables.
docker run -p 9966:9966 \
-e OSRM_VECTOR_STYLE=https://tiles.example.com/style.json \
-e OSRM_VECTOR_NAME='Local vector' \
ghcr.io/project-osrm/osrm-frontend:latest
Dark Vector uses the configured vector style with the selected theme. OpenStreetMap
shares the built-in Shortbread source with Dark Vector in the static demo. The
layer menu lists OpenStreetMap, Dark Vector, OpenStreetMap.de, Satellite and Outdoors,
in that order (Dark Vector appears when configured). OpenStreetMap is the demo default.
The renderer loads when a vector background is selected. A coarse grid sits
behind the first view while vector tiles load. If the renderer or style fails,
the layer control offers other backgrounds and the loading message offers a
retry. Styles hosted on another origin must allow CORS requests for the style
and its tile, font and sprite resources. A configured vector background is the
default unless OSRM_DEFAULT_LAYER selects another layer.
Dark Vector uses a dark slate palette with blue water and muted green land cover.
The translucent grey directions sidebar has blue route cards, expandable
instructions and selectable duration labels on the map.
The sidebar stays beside the map on desktop and becomes a bottom sheet on smaller
screens. The map extends behind the translucent panel; route and entrance fitting reserve
the unobscured area beside the sidebar or above the mobile sheet.
Set OSRM_VECTOR_THEME=original to keep the provider's original colors and the
classic interface. The dark theme preserves vector source attribution, fonts,
labels and road geometry; it removes raster backdrop layers from the vector style.
Route options
Open Route options below the waypoint inputs to exclude a comma-separated list
of road classes, such as motorway,toll,ferry, or allow U-turns at via points.
The backend's routing profile determines which classes and combinations it supports;
unsupported exclusions are reported as routing errors. By default no classes are
excluded and routes continue straight at via points where possible.
These settings travel in shared links as exclude=motorway,toll and u=true.
Browser Back and Forward restore them along with the waypoints.
Backends behind HTTP authentication
The frontend has no configuration option for backend credentials, and embedding them in the
backend URL (https://user:password@example.com) does not work: browsers refuse to send
credentials embedded in subresource URLs, so the request either fails with 401 or never
completes. This is browser policy and cannot be worked around from the page. Credentials placed
in OSRM_MODES would also end up in config.json, readable by everyone who loads the frontend.
The supported approach is to keep the credentials on the server side, behind a reverse proxy that
serves the frontend and the routing endpoint from the same origin. With nginx:
location /osrm/ {
proxy_pass https://osrm.internal.example.com/;
proxy_set_header Authorization "Basic <base64 of user:password>";
}
Then point a mode at the proxied path instead of at the backend directly. Relative URLs are
supported and produce same-origin requests:
docker run -p 9966:9966 \
-e 'OSRM_MODES=[{"name":"car","url":"/osrm"}]' \
ghcr.io/project-osrm/osrm-frontend:latest
If the proxy has to live on a different origin than the frontend, it must answer the CORS
preflight (OPTIONS) request without requiring authentication, and include
Access-Control-Allow-Headers: authorization in the response. Otherwise the browser rejects the
routing request before it is ever sent.
In case Docker complains about not being able to connect to the Docker daemon make sure you are in the docker group.
sudo usermod -aG docker $USER
To build the docker image locally:
docker build -f docker/Dockerfile -t osrm-frontend .
docker run -p 9966:9966 osrm-frontend
Development
Install dependencies via
npm install
Then compile assets and start the local server with
npm start
On Windows with no Unix tools installed (bash and cp) the server could be started with two other commands
executed by npm start internally:
npm run compile
npm run start-index
Changing Backends
For Docker deployments, prefer runtime configuration via OSRM_MODES (see above)
instead of editing source files. If you need source-level customization, edit the
parseModes() and buildServices() functions in src/leaflet_options.js.
Geocoding
Address search and the reverse lookups that name dropped or dragged waypoints go
to the public Nominatim instance by
default. OSRM_GEOCODERS decides which geocoders a deployment offers — a JSON
array shaped like OSRM_MODES:
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 at all. The search box still accepts typed coordinates, and waypoints are
named by their coordinates (34.129382, -118.141254) — a form that pastes back
into the search box. Configure it alone when the deployment may not reach a
third-party geocoder:
docker run -p 9966:9966 -e 'OSRM_GEOCODERS=[{"url":""}]' ghcr.io/project-osrm/osrm-frontend:latest
| Field |
Default |
Description |
name |
Geocoder <n>, or Coordinates only for an empty url |
Display name. |
url |
— |
Nominatim endpoint. Empty means no geocoding at all. |
The first entry is the one in use. With OSRM_GEOCODERS unset, the single entry
is the Nominatim instance baked in at build time via NOMINATIM_ENDPOINT.
Customizing Tile Layers and Overlays
Base layers (layer)
The layer property in src/leaflet_options.js defines the base tile layers
shown as radio buttons in the map's layer control (bottom-left corner).
Default base layers: