Skip to content

Commit 2888e8f

Browse files
authored
fix(runtime): avoid infinite recursion in fetch for external URLs (#4153)
1 parent 75cc89d commit 2888e8f

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

src/runtime/internal/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export function fetch(
9090
return serverFetch(resource, init, context);
9191
}
9292
resource = (resource as any)._request || resource; // unwrap srvx request
93-
return fetch(resource, init);
93+
return globalThis.fetch(resource, init);
9494
}
9595

9696
function createNitroApp(): NitroApp {

test/fixture/server/routes/fetch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export default async () => {
1010
).then((res) => res.json()),
1111
"nitro/runtime.serverFetch": await runtimeServerFetch("/api/hello").then((res) => res.json()),
1212
"nitro/runtime.fetch": await runtimeFetch("/api/hello").then((res) => res.json()),
13+
"nitro/runtime.fetch.url": await runtimeFetch(new URL("http://localhost/api/hello")).then(
14+
(res) => res.json()
15+
),
1316
"nitro/serverFetch": await nitroServerFetch("/api/hello").then((res) => res.json()),
1417
"nitro/fetch": await nitroFetch("/api/hello").then((res) => res.json()),
1518
};

0 commit comments

Comments
 (0)