refactor(hikes): route via self-hosted BRouter instance

Point routeBrouter at a local BRouter server ($BROUTER_URL, default http://127.0.0.1:17777) instead of the public brouter.de, matching the bundled brouter package + systemd service.
This commit is contained in:
2026-05-25 14:51:46 +02:00
parent 8459327717
commit 59b4630746
2 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "homepage", "name": "homepage",
"version": "1.89.0", "version": "1.89.1",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
+6 -1
View File
@@ -57,6 +57,11 @@ const OSRM_PROFILE: Record<RoutingProfile, string> = {
road: 'driving' road: 'driving'
}; };
// Self-hosted BRouter instance (see the `brouter` package + systemd service).
// Defaults to the localhost server so production needs no extra config; override
// with the BROUTER_URL env var (e.g. to point at a remote instance in dev).
const BROUTER_URL = (process.env.BROUTER_URL || 'http://127.0.0.1:17777').replace(/\/+$/, '');
async function fetchJson<T>(url: string, signal: AbortSignal): Promise<T | null> { async function fetchJson<T>(url: string, signal: AbortSignal): Promise<T | null> {
try { try {
const res = await fetch(url, { const res = await fetch(url, {
@@ -121,7 +126,7 @@ async function routeBrouter(
signal: AbortSignal signal: AbortSignal
): Promise<Array<[number, number, number?]> | null> { ): Promise<Array<[number, number, number?]> | null> {
const url = const url =
`https://brouter.de/brouter?lonlats=${a.lng},${a.lat}|${b.lng},${b.lat}` + `${BROUTER_URL}/brouter?lonlats=${a.lng},${a.lat}|${b.lng},${b.lat}` +
`&profile=${BROUTER_PROFILE[profile]}&alternativeidx=0&format=geojson`; `&profile=${BROUTER_PROFILE[profile]}&alternativeidx=0&format=geojson`;
const json = await fetchJson<BrouterGeoJson>(url, signal); const json = await fetchJson<BrouterGeoJson>(url, signal);
if (!json?.features?.[0]?.geometry?.coordinates) return null; if (!json?.features?.[0]?.geometry?.coordinates) return null;