Route journal BRouter calls through the planner

The planner is the BRouter client in this architecture — route
compute, rate limiting, and the eventual move of BRouter off-box all
live there. The journal had two places that called BRouter directly
(demo-bot and /api/v1/routes/compute) and both were broken on prod
because the journal service has no BROUTER_URL.

Fix:
- Extend the planner's /api/route with an optional `format: "gpx"`
  that returns BRouter's raw GPX (for server-to-server callers that
  don't need the way-tag enriched GeoJSON).
- Point the journal demo-bot at `PLANNER_URL/api/route` with
  `format: "gpx"` instead of calling BRouter directly.
- Point /api/v1/routes/compute at `PLANNER_URL/api/route` instead of
  BRouter directly.

Journal no longer needs BROUTER_URL at all. When BRouter moves to a
dedicated host later, only the planner changes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ullrich Schäfer 2026-04-19 11:11:10 +02:00
parent 017a098fca
commit 42f4c98014
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9
4 changed files with 90 additions and 20 deletions

View file

@ -1,6 +1,6 @@
import { data } from "react-router";
import type { Route } from "./+types/api.route";
import { computeRoute, BRouterError } from "~/lib/brouter";
import { computeRoute, computeSegmentGpx, BRouterError } from "~/lib/brouter";
import { checkRateLimit } from "~/lib/rate-limit";
export async function action({ request }: Route.ActionArgs) {
@ -9,11 +9,12 @@ export async function action({ request }: Route.ActionArgs) {
}
const body = await request.json();
const { waypoints, profile, sessionId, noGoAreas } = body as {
const { waypoints, profile, sessionId, noGoAreas, format } = body as {
waypoints: Array<{ lat: number; lon: number }>;
profile?: string;
sessionId?: string;
noGoAreas?: Array<{ points: Array<{ lat: number; lon: number }> }>;
format?: "geojson" | "gpx";
};
if (!waypoints || waypoints.length < 2) {
@ -35,6 +36,20 @@ export async function action({ request }: Route.ActionArgs) {
}
try {
// `format: "gpx"` returns BRouter's raw GPX without the way-tag
// enrichment the interactive planner needs. Used by server-to-server
// callers (e.g. the Journal's demo-bot) that just want the track.
if (format === "gpx") {
const gpx = await computeSegmentGpx({ waypoints, profile, noGoAreas });
return new Response(gpx, {
status: 200,
headers: {
"content-type": "application/gpx+xml; charset=utf-8",
"x-ratelimit-remaining": String(limit.remaining),
},
});
}
const route = await computeRoute({ waypoints, profile, noGoAreas });
return data(route, {
headers: { "X-RateLimit-Remaining": String(limit.remaining) },