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:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "homepage",
|
||||
"version": "1.89.0",
|
||||
"version": "1.89.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -57,6 +57,11 @@ const OSRM_PROFILE: Record<RoutingProfile, string> = {
|
||||
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> {
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
@@ -121,7 +126,7 @@ async function routeBrouter(
|
||||
signal: AbortSignal
|
||||
): Promise<Array<[number, number, number?]> | null> {
|
||||
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`;
|
||||
const json = await fetchJson<BrouterGeoJson>(url, signal);
|
||||
if (!json?.features?.[0]?.geometry?.coordinates) return null;
|
||||
|
||||
Reference in New Issue
Block a user