timostamm / protobuf-ts

Protobuf and RPC for TypeScript
Apache License 2.0
1.07k stars 127 forks source link

Allow GrpcWebFetchTransport to receive a fetch function #504

Open jaysonsantos opened 1 year ago

jaysonsantos commented 1 year ago

Hey there first, thanks for this project! I'd like to ask for the ability to construct GrpcWebFetchTransport with a fetch function. The use case here would be when using svelte for example where the load (https://kit.svelte.dev/docs/load#making-fetch-requests) function receives an implementation, and it is safer to use it on SSR and on browser. Is it something viable or, should I have been using another option for that? Thanks in advance!

jcready commented 1 year ago

Even if there were an option to allow you to pass in your own fetch function I don't think it would help you with your svelte/SSR goal. In your link it says:

During server-side rendering, the response will be captured and inlined into the rendered HTML by hooking into the text and json methods of the Response object.

But the GrpcWebFetchTransport uses neither of those methods. Instead it reads from the Response.body which is a ReadableStream.