unjs / h3

⚡️ Minimal H(TTP) framework built for high performance and portability
https://h3.unjs.io/
MIT License
3.71k stars 221 forks source link

Support `ReadableStream` responses (cloudflare) #144

Closed Achrou closed 1 year ago

Achrou commented 2 years ago

In Cloudflare Workers , ReadableStream does not have pipe and on functions; resulting in a response type of json

https://github.com/unjs/h3/blob/f09ce91911cf5657a66a3a69a88a512c931d2be0/src/utils/response.ts#L47

For more information about Cloudflare Workers ReadableStream, please see:https://developers.cloudflare.com/workers/runtime-apis/streams/readablestream/#methods

altryne commented 1 year ago

Could this be why I'm not able to use readBody via cloudflare workers but can via npm run? https://github.com/nuxt-modules/supabase/issues/133#issuecomment-1361868398

altryne commented 1 year ago

I think his broke useBody in cloudflare workers @danielroe since the update

altryne commented 1 year ago

For what it's worth, this still breaks for me. One example is, autogenerated routes like the one I just installed with nuxt/turnstile. Another is still, nuxt/supabase that tries to store cookies (again, with an auto generated route that I had to fake with a redirect)

For anyone arriving here before this is fixed (I would love to send a PR, just not sure where) here's my workaround:

https://gist.github.com/altryne/54747e1a7b6d4adecc490f60dd0f636a

altryne commented 1 year ago

@pi0 would you welcome a fix here? (my override above works, but it's def. not the best way around this)

It seems that all the pieces are there, it just needs a proper detection that an readabaleStream in the form of one that is cloudflare is incoming.

altryne commented 1 year ago

I think this is now closed here: https://github.com/unjs/h3/issues/363

pi0 commented 1 year ago

Support for readable stream responses added via #457. Please check readme about nightly channel if you like to early test before release.