Skip to content

Commit e8f1306

Browse files
committed
fix(ingest): normalize OVERPASS_URL so a bare origin also resolves
overpassUrl() returned the env value verbatim, so a self-hoster setting OVERPASS_URL=http://overpass (a bare origin, no /api/interpreter) would POST to the wrong path and get no data — while the openmapx side, which normalizes, would accept it. Add OC's own normalizeOverpassUrl (append /api/interpreter when absent, strip a trailing slash) so both a bare origin and a full endpoint resolve identically, matching openmapx's behavior without OC depending on @openmapx/core.
1 parent ae2f25b commit e8f1306

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

services/ingest/src/__tests__/osm-import.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,4 +236,16 @@ describe("overpassUrl", () => {
236236
"http://overpass/api/interpreter"
237237
);
238238
});
239+
240+
it("normalizes a bare-origin OVERPASS_URL to the interpreter path", () => {
241+
expect(overpassUrl({ OVERPASS_URL: "http://overpass" })).toBe(
242+
"http://overpass/api/interpreter"
243+
);
244+
});
245+
246+
it("normalizes a trailing-slash OVERPASS_URL", () => {
247+
expect(overpassUrl({ OVERPASS_URL: "http://overpass/" })).toBe(
248+
"http://overpass/api/interpreter"
249+
);
250+
});
239251
});

services/ingest/src/pipeline/osm-import.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,30 @@ export interface OsmWaySource {
9696
// different fetcher, behind the OsmWaySource interface above.
9797
const DEFAULT_OVERPASS_URL = "https://overpass-api.de/api/interpreter";
9898

99+
/**
100+
* Normalizes an Overpass endpoint to the `…/api/interpreter` path so a bare
101+
* origin (`http://overpass`) and a full endpoint (`http://overpass/api/interpreter`)
102+
* resolve identically. Mirrors the openmapx-side client (which also accepts
103+
* either form) so a shared `OVERPASS_URL` behaves the same for both — without OC
104+
* taking a dependency on openmapx's `@openmapx/core`.
105+
*/
106+
function normalizeOverpassUrl(url: string): string {
107+
const trimmed = url.replace(/\/$/, "");
108+
return trimmed.endsWith("/api/interpreter") ? trimmed : `${trimmed}/api/interpreter`;
109+
}
110+
99111
/**
100112
* Resolves the Overpass endpoint from `OVERPASS_URL`, falling back to the
101113
* public instance when unset or empty (Compose's `${VAR:-}` unset-injection).
102114
* A self-hoster running their own Overpass (e.g. a planet instance already on
103115
* the stack) can point large per-region pulls at it to avoid the public
104-
* server's fair-use budget and client-timeout risk on heavy bboxes.
116+
* server's fair-use budget and client-timeout risk on heavy bboxes. The value
117+
* may be a bare origin or a full `…/api/interpreter` endpoint — both normalize
118+
* to the same interpreter URL.
105119
*/
106120
export function overpassUrl(env: NodeJS.ProcessEnv = process.env): string {
107121
const raw = env["OVERPASS_URL"];
108-
return raw != null && raw !== "" ? raw : DEFAULT_OVERPASS_URL;
122+
return raw != null && raw !== "" ? normalizeOverpassUrl(raw) : DEFAULT_OVERPASS_URL;
109123
}
110124

111125
const HIGHWAY_FILTER =

0 commit comments

Comments
 (0)