Support Cloudflare Workers #777
bensenescu
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Support Cloudflare Workers by Default
Hello, just writing down this CF workers bug. @KyleAMathews said that this was likely best as a standalone package, but I wanted to share this draft PR fixing it within TanStack DB itself just in case. Hopefully, this could prevent some headaches for Cloudflare users moving forwards.
Happy to chat more about improving my PR / alternative approaches like exporting the
lazyInitForCFWorkersfrom TanStack DB itself instead of my janky package.bensenescu#2
Problem
When you deploy a code using TanStackDB to Cloudflare Workers, it results in a 500 error due to:
Work Arounds
Singleton Pattern
https://discord.com/channels/719702312431386674/1369767025723052134/1418222870752133201
Proxy Pattern
I've made a very small npm package implementing this lazyInit function: https://www.npmjs.com/package/lazy-init-for-cf-workers
Here is the code (60 lines): https://github.com/bensenescu/lazy-init-for-cf-workers/blob/main/src/index.ts
Potential Solution
navigator.userAgentto detect if we're in the CF RuntimeHere is a draft PR implementing this: bensenescu#2
Unknowns
Beta Was this translation helpful? Give feedback.
All reactions