Cloudflare DevelopersCD
Cloudflare Developers2y ago
2 replies
Kevin

Not sure if this is a #wrangler or #

Not sure if this is a #wrangler or #miniflare issue, but the following code will throw in wrangler dev (ignored/safe in production):

Error Reproduction
export default {
  middleware: () => {}, // wrangler dev attempts to iterate this, throwing
}


Why this matters
itty-router routers have a Proxy trap on the prototype chain. If we export our router directly (ideal), a request to "middleware" returns a function, throwing when internal wrangler code tries to iterate it.

import { Router } from 'itty-router'

export default Router() // this should work, and works fine in Bun


Proposed fix
If requesting a hidden exported property (middleware) and iterating over it, there should at least be checks to verify if the item is iterable before attempting to iterate.
Was this page helpful?