Proxy error when trying to redirect to external url

When using sveltekit and trying to do a simple redirect like
throw redirect(302, 'https://google.com')
throw redirect(302, 'https://google.com')
I'm getting the error:
[ERROR] Error: Could not proxy request: TypeError: fetch failed

at
/***/node_modules/.pnpm/wrangler@3.0.1/node_modules/wrangler/wrangler-dist/cli.js:110744:29
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async #handleLoopbackCustomService
(/***/node_modules/.pnpm/miniflare@3.0.1/node_modules/miniflare/dist/src/index.js:8910:24)
at async #handleLoopback
(/***/node_modules/.pnpm/miniflare@3.0.1/node_modules/miniflare/dist/src/index.js:8972:20)


[mf:inf] GET /api/oauth 502 (10159ms)
workerd/server/server.c++:2347: error: Uncaught exception: kj/async-io-unix.c++:491: disconnected: worker_do_not_log; Request failed due to internal error
stack: 1059451a3 104a73a33 104a7e650 104a7e80f 10590b49c 104aa3130 1045d7c50 1045d7fe3 1044cf0cc 104a63b98 104a66610
workerd/server/server.c++:2259: error: exception = kj/compat/http.c++:2061: failed: expected !inBody; previous HTTP message body incomplete; can't write more messages
stack: 104a81163 104aab04b 104a4dd4f 104a4deb7 104228d1b 104a6670f 104a668d3 104aaa0bc 10422a8f4
[ERROR] Error: Could not proxy request: TypeError: fetch failed

at
/***/node_modules/.pnpm/wrangler@3.0.1/node_modules/wrangler/wrangler-dist/cli.js:110744:29
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async #handleLoopbackCustomService
(/***/node_modules/.pnpm/miniflare@3.0.1/node_modules/miniflare/dist/src/index.js:8910:24)
at async #handleLoopback
(/***/node_modules/.pnpm/miniflare@3.0.1/node_modules/miniflare/dist/src/index.js:8972:20)


[mf:inf] GET /api/oauth 502 (10159ms)
workerd/server/server.c++:2347: error: Uncaught exception: kj/async-io-unix.c++:491: disconnected: worker_do_not_log; Request failed due to internal error
stack: 1059451a3 104a73a33 104a7e650 104a7e80f 10590b49c 104aa3130 1045d7c50 1045d7fe3 1044cf0cc 104a63b98 104a66610
workerd/server/server.c++:2259: error: exception = kj/compat/http.c++:2061: failed: expected !inBody; previous HTTP message body incomplete; can't write more messages
stack: 104a81163 104aab04b 104a4dd4f 104a4deb7 104228d1b 104a6670f 104a668d3 104aaa0bc 10422a8f4
Using the sveltekit template in npm create cloudflare The redirect works fine with npm run dev but doesn't with npm run pages:dev so likely a wrangler problem.
1 Reply
yeehow
yeehow13mo ago
From looking at this again seems like the proxy is trying to fetch the redirected page. Get different errors for trying to redirect to different sites. I found _redirects but according to the docs for the cloudflare pages adapater (https://kit.svelte.dev/docs/adapter-cloudflare#notes) this doesn't effect server endpoints... Maybe there is a proxy config setting or something simple i'm missing?
SvelteKit docs
Cloudflare Pages • SvelteKit documentation