Runtimes
Runtimes > Cloudflare Workers - itty-router
Itty-router was originally designed for Cloudflare Workers, and remains its optimization target to this day.
js
import { AutoRouter } from 'itty-router'
const router = AutoRouter()
router.get('/', () => 'Success!')
export default router // see note below
Currently, there's an issue with wrangler dev
that doesn't play nice with our default export. While this doesn't affect production code, it's a pain to develop locally. We're working with the Cloudflare folks to get this fixed ASAP.
In the meantime, destructure your root router like this in local dev (also works in production):
ts
export default { ...router } // this looks pointless, but trust us