Skip to content

Commit 496509a

Browse files
committed
fix: authedFetch URL resolution breaks when DENO_DEPLOY_ENDPOINT contains a path
1 parent ba9131c commit 496509a

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export async function authedFetch(
303303
`token=${auth}; deno_auth_ghid=force`,
304304
);
305305

306-
const url = new URL(endpoint, context.endpoint);
306+
const url = new URL(`${context.endpoint}/${endpoint}`);
307307

308308
let fallbackBody: ReadableStream | undefined;
309309
if (init.body instanceof ReadableStream) {

tests/url_resolution.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { assertEquals } from "@std/assert";
2+
3+
// Reproduces the URL resolution behavior in authedFetch.
4+
// Before the fix: new URL(endpoint, base) drops path segments from the base.
5+
// After the fix: string concatenation preserves the full base path.
6+
7+
Deno.test("new URL() two-arg drops base path segments", () => {
8+
// This is the OLD (broken) behavior that motivates the fix.
9+
// When the endpoint is a proxy URL with a path, the path-based
10+
// target host segment gets silently dropped.
11+
const base = "https://proxy.example.com/target-host";
12+
const endpoint = "api/diffsync/org/app/rev123";
13+
14+
const broken = new URL(endpoint, base);
15+
// new URL resolves relative to the parent of "target-host", losing it:
16+
assertEquals(broken.pathname, "/api/diffsync/org/app/rev123");
17+
// "target-host" is gone — the proxy can no longer route the request.
18+
});
19+
20+
Deno.test("string concatenation preserves base path segments", () => {
21+
// This is the FIXED behavior: concatenation keeps the full base path.
22+
const base = "https://proxy.example.com/target-host";
23+
const endpoint = "api/diffsync/org/app/rev123";
24+
25+
const fixed = new URL(`${base}/${endpoint}`);
26+
assertEquals(
27+
fixed.pathname,
28+
"/target-host/api/diffsync/org/app/rev123",
29+
);
30+
});
31+
32+
Deno.test("string concatenation works for standard endpoint too", () => {
33+
// Ensure the fix doesn't regress the normal (non-proxy) case.
34+
const base = "https://console.deno.com";
35+
const endpoint = "api/diffsync/org/app/rev123";
36+
37+
const fixed = new URL(`${base}/${endpoint}`);
38+
assertEquals(fixed.pathname, "/api/diffsync/org/app/rev123");
39+
assertEquals(fixed.hostname, "console.deno.com");
40+
});

util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function error(
2323
): never {
2424
console.error();
2525
console.error(`${red("✗")} An error occurred:`);
26-
console.error(` ${error.replaceAll("\n", "\n ")}`);
26+
console.error(` ${String(error ?? "Unknown error").replaceAll("\n", "\n ")}`);
2727
const trace = response?.headers.get("x-deno-trace-id");
2828
if (context.debug) {
2929
console.error(` stack:\n${new Error().stack}`);

0 commit comments

Comments
 (0)