GithubHelp home page GithubHelp logo

Comments (4)

kwhitley avatar kwhitley commented on June 10, 2024 3

What is it?

You’re seeing the wrangler dev issue, described here:
https://itty.dev/itty-router/guides/cloudflare-workers.

What you can do to fix

In your root/index file, destructure your router as part of your export. This strips the Proxy prototype that is intercepting Wrangler/Miniflare's request.

export default { ...router }

What you can do to help

Here's the issue filed with Wrangler team. Please go thumbs up or comment on this thread to spur things along.

What's happening (for the curious)

In local development, Wrangler has introduced a middleware property on the default export. The problem is, if they find it, they assume it's an array (of middleware) and immediately iterate it without any safety checks/validation.

In itty-router, we use a Proxy on the prototype chain to intercept unknown properties of routers and map them to route handlers with the given HTTP method. For instance, router.get maps to GET, router.foo to FOO, etc. So when we export the router directly (perfectly fine in most environments), and Wrangler asks for a middleware property, itty returns a route handler (a function). When you try to iterate a function, you get the error you've found.

from itty-router.

kwhitley avatar kwhitley commented on June 10, 2024 1

Perfectly happy to, because I certainly doubt you'll be the last to discover it (until the Wrangler team sorts things out on their end).

from itty-router.

kwhitley avatar kwhitley commented on June 10, 2024 1

The PR for this has been merged into main on Wrangler... just need to find the release that includes it:
cloudflare/workers-sdk#5420

from itty-router.

wqcstrong avatar wqcstrong commented on June 10, 2024

You’re seeing the wrangler dev issue, described here https://itty.dev/itty-router/guides/cloudflare-workers.

Good news is, this works fine in production as-is, or likely more helpful to you, you can destructure your export to solve this in local dev.

export default { ...router }

Thanks, the export default { ...router } is ok , maybe you can keep the issue opened for other user.

from itty-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.