Closed leaysgur closed 7 months ago
One other thing I noticed. 👀
Currently, createCors.spec.ts
does not pass on the v4.x
branch.
This is because new Response(null, { status: 101 })
will result in a RangeError
.
The error seems to occur when using v18 or later Node.js(w/ undici
), and will eventually occur in the near future even when using isomorphic-fetch
with earlier versions.
But this code does not throw
acutualy in Edge workers like Cloudflare Workers... 😅
One other thing I noticed. 👀
Currently,
createCors.spec.ts
does not pass on thev4.x
branch. This is becausenew Response(null, { status: 101 })
will result in aRangeError
.The error seems to occur when using v18 or later Node.js(w/
undici
), and will eventually occur in the near future even when usingisomorphic-fetch
with earlier versions.But this code does not
throw
acutualy in Edge workers like Cloudflare Workers... 😅
Great catch, thanks for the investigation! Since I'm trying to launch v4 in the next day or two (if enough folks test out the new typings), I'll def want to sort this ASAP.
Yeah, @leader22 - this looks clean, and adds very little size for the added support. Love it!
Would you mind making a pass at updating the v4.x docs?
CORS page https://github.com/kwhitley/itty.dev/blob/main/src/routes/itty-router/cors/%2Bpage.md
API page (at the createCors entry) https://github.com/kwhitley/itty.dev/blob/main/src/routes/itty-router/api/%2Bpage.md
Thanks!
@kwhitley Thanks for the review!
updating the v4.x docs?
Like this? 👉🏻 https://github.com/kwhitley/itty.dev/pull/1
Exactly! I'm not feeling great at the moment, so this will wait till tomorrow or so, but I think this is a great addition, and def adds to the flexibility (one of the core principles of itty)!
@leader22 - createCors underwent a GPT refactor to save bytes, causing a collision with this PR.
This one I'm not super worried about timing on, as it's a minor release/feature add on core - so happy to add it after v4.x goes out.
I see.
In that sense, I think I can resolve the conflict now, but should I wait for the v4.x release? 👀
And now fixed, let me know if there is anything else I can help. 😉
Honestly, I'd say we wait at this point - that way you get some dedicated credit in the changelog, haha. Right now, there are so many changes, with help from so many folks, that a lot of well-deserved credit will already be lost! 😭
I'd say as soon as 4.x goes out and we patch any immediate issues (hopefully none), we roll this out in 4.1.0
👍🏻 , looking forward to it~!
The
createCors({ origins })
now accepts functions as well.This makes it easy to support dynamically changing subdomains, as in the Cloudflare Pages branch preview.
While it's possible to achieve this by accepting
RegExp
, but functions are more flexible and often more readable. Of courseRegExp
can be used by(origin) => re.test(origin)
.For backwards compatibility, the signature is a union with
string[]
. (IMO: It's fine with just functions.)What do you think?