You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a cloudflare worker that intercepts some routes, and just forwards all other routes to the origin. I believe this worked when i wrote the code originally, however it seems to have started failing when i picked up the project again earlier today.
Example Router Code
import{AutoRouter,Router}from'itty-router';constrouter=AutoRouter();router.all('*',async(req)=>{try{returnawaitfetch(req);}catch(e){console.error(e);returnnewResponse('proxy request failed');}});exportdefault{asyncfetch(request,env,ctx){constu=newURL(request.url);u.host='example.com';u.port='';u.protocol='https';constchangedRequest=newRequest(u,request);if(u.searchParams.get('skip')){console.log('fetching directly');returnawaitfetch(changedRequest);}console.log('fetching through itty-router');returnrouter.fetch(changedRequest,env,ctx);}};
The minimal example just proxies all requests to example.com. If you start this in wrangler and invoke http://localhost:8787?skip=true it works fine. (This skips itty-router and just forwards the request directly). If you do not pass skip=true by just invoking http://localhost:8787 then it will fail with TypeError: Invalid URL: [object Request].
If you switch to the normal Router then it also works fine.
Expected Behavior
Cloudflare forwards the request without issues.
Actual Behavior
TypeError: Invalid URL: [object Request] (In the minimal example, compatibility_date="2024-12-30")
or TypeError: Fetch API cannot load: [object Object] (In my original code, compatibility_date="2023-09-18")
Environment (please complete the following information):
Environment: Cloudflare Workers
itty-router Version: 5.0.18
Other Relevant Libraries and their versions:
Wrangler: 3.99.0
Additional Context
The issue seems to not occur when using Router directly. Tracing the issue this seems to be caused by withParams wrapping the request object in a Proxy, which Cloudflare cannot handle.
As a workaround i can initialize a new request object and copy over relevant properties, however this is a bit of a wack-a-mole as i have to make sure to do it in all places i fall back to just forwarding the original request.
The text was updated successfully, but these errors were encountered:
Describe the Issue
I have a cloudflare worker that intercepts some routes, and just forwards all other routes to the origin. I believe this worked when i wrote the code originally, however it seems to have started failing when i picked up the project again earlier today.
Example Router Code
Request Details
GET http://localhost:8787
GET http://localhost:8787?skip=true
Steps to Reproduce
The minimal example just proxies all requests to
example.com
. If you start this in wrangler and invokehttp://localhost:8787?skip=true
it works fine. (This skips itty-router and just forwards the request directly). If you do not passskip=true
by just invokinghttp://localhost:8787
then it will fail withTypeError: Invalid URL: [object Request]
.If you switch to the normal
Router
then it also works fine.Expected Behavior
Cloudflare forwards the request without issues.
Actual Behavior
TypeError: Invalid URL: [object Request]
(In the minimal example, compatibility_date="2024-12-30")or
TypeError: Fetch API cannot load: [object Object]
(In my original code, compatibility_date="2023-09-18")Environment (please complete the following information):
Additional Context
The issue seems to not occur when using
Router
directly. Tracing the issue this seems to be caused bywithParams
wrapping the request object in aProxy
, which Cloudflare cannot handle.As a workaround i can initialize a new request object and copy over relevant properties, however this is a bit of a wack-a-mole as i have to make sure to do it in all places i fall back to just forwarding the original request.
The text was updated successfully, but these errors were encountered: