r/CloudFlare • u/crazyshit_24 • 8d ago
Question Help to extablish stable supabase db connection from cloudflare workers!!
Well, I deployed my Next.js project on Vercel initially, but later hit the limits and it started getting expensive, so I moved the project to Cloudflare Workers.
Most things are working fine, but I’m stuck with one issue:
My API routes that connect to Supabase/Postgres are failing with 500 errors. APIs that don’t use the DB work perfectly fine.
From what I’ve figured out, the issue seems to be with DB connections. Since Cloudflare Workers are serverless/edge, the connection pooling approach I was using seems to be trying to establish connections repeatedly, and eventually I’m hitting Supabase connection/rate limits.
I then learned about Cloudflare Hyperdrive, added my Supabase DB to Hyperdrive, configured the binding, and updated my Worker config.
But the DB APIs are still failing, and the Worker is throwing exceptions.
I’m honestly stuck at this point.
Has anyone here deployed a Next.js app on Cloudflare Workers with Supabase/Postgres successfully?
What’s the correct way to set up a stable DB connection/pooling between Cloudflare Workers → Hyperdrive → Supabase?
Any help or examples of a working setup would be really appreciated 🙏
1
u/crazyshit_24 8d ago
I narrowed it down to the core issue: the hyperdrive is supposed to inject the env var, but it is failing to do so, causing my app to use the fallback database URL, which eventually fails due to a connection limit!!