Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

withParams doesn't allow to modify request on Cloudflare #255

Open
istarkov opened this issue Jul 7, 2024 · 0 comments
Open

withParams doesn't allow to modify request on Cloudflare #255

istarkov opened this issue Jul 7, 2024 · 0 comments
Labels
BUG Something isn't working

Comments

@istarkov
Copy link
Contributor

istarkov commented Jul 7, 2024

Describe the Issue

This typical Cloudflare code to modify a request (such as changing the url) fails when withParams is used
with the error Incorrect type for the 'fetcher' field on 'RequestInitializerDict': the provided value is not of type 'Fetcher'

import { Router, type IRequest, withParams } from 'itty-router';

const router = Router<IRequest, CFArgs>({
  before: [withParams],
});

router.get('*', (request) => {
  const req = new Request('https://example.com', request); // <-- fails with Incorrect type for the 'fetcher' field on 'RequestInitializerDict': the provided value is not of type 'Fetcher'.
  // ... change req headers etc  
});

export default { ...router };

The issue is this line https://github.com/kwhitley/itty-router/blob/v5.x/src/withParams.ts#L6
as seems like workerd is already wrapping request with rpc object and it has RPCBlabla type with bind method of the same type.

If bind is really needed better to check that obj[prop] instanceof Function ? obj[prop].bind ....

Fails in dev and production (when published to cloudflare)

@kwhitley kwhitley added the BUG Something isn't working label Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BUG Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants