kwhitley / itty-router

A little router.
MIT License
1.71k stars 77 forks source link

v3.x #131

Closed kwhitley closed 1 year ago

kwhitley commented 1 year ago

What is this?

This brings itty-router to a full TS conversion, staged for the inclusion of itty-router-extras as in-house additions, rather than an external library.

This modification comes with a couple caveats:

Increase in bundle size (~250 bytes)

This was sadly overdue (and perhaps can be golfed down a bit), but as a result we've fixed the following issues:

1 . Routes can now capture complex/unknown paths using the trailing + modifier. As a result, this is now possible:

  router.handle('/get-file/:path+', ({ params }) => params)

  // GET /get-file/with/a/long/path.png => { path: "with/a/long/path.png" }
  1. Query params with multiple same-name values now operate as you would expect (previously, they overwrote each other)

    router.handle('/foo', ({ query }) => query)
    
    // GET /foo?pets=mittens&pets=fluffy&pets=rex&bar=baz => { bar: "baz", pets: ["mittens", "fluffy", "rex"] }

Breaking TS changes

I've been forced to rewrite the TS types. This will need a bit of documentation...

cloudflare-pages[bot] commented 1 year ago

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: c774f84
Status: ✅  Deploy successful!
Preview URL: https://7b15fad5.itty-router-y9b5.pages.dev
Branch Preview URL: https://ts.itty-router-y9b5.pages.dev

View logs

kwhitley commented 1 year ago

I encourage everyone to test drive itty-router@next and give feedback in Discord!