-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Cloudflare Workers #759
Comments
This is blocked by Connect RPC's requirement to construct a client with a baseUrl. We want to avoid reconstructing a client on each request to the worker. |
Related: Connect doesn't work well on Cloudflare, see connectrpc/connect-es#577 |
Someone suggested dynamic baseUrl in connectrpc/connect-es#678 but it was closed as wontfix. |
I spent a bit of time researching where we're at with support for Cloudflare workers.
Seems there's a few reasons for this:
With Cloudflare's move from Service Workers to ES Modules, environment variables are no longer provided in the global scope. Instead, they're passed as a binding to the handler. Trying to access them as a global will error. Also, creating the connect client requires a base URL, which we configure dynamically based on the environment variables. Loading WASM Cloudflare officially supports WASM in workers. They have some history with slow worker startup, but it seems they've implemented a fix for this. From 2020:
It would be interesting to test the startup time of our WASM Module. They must be instantiated in the global scope outside of the handler, which implies some optimization may be going on. There is also a worker size limit of 1MB for free plans, 10MB for paid plans. Persistent connections Cloudflare doesn't support persistent outbound connections so we don't get any benefit here. You can see in the examples for databases, they create a new connection within the workers handler, then it closes after the request ends. Given this, we could avoid our usage of the dynamic I assume we'd use the fetch client from Connect: connectrpc/connect-es#577 (comment) Did I miss anything or get anything wrong? |
Allow us to support applications built on Cloudflare workers. There's a lot of useful data in the request context
cf
property we could make use of.The text was updated successfully, but these errors were encountered: