2026-06-04backend
Local dev DB connection (Hyperdrive→Neon override + dev pool path)
- Change: Two fixes so
next devcan reach Postgres:- Local Hyperdrive points at Neon. Added
CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE(Neon pooled URL) to the gitignored.env.initOpenNextCloudflareForDev()makesgetCloudflareContext()expose theHYPERDRIVEbinding undernext dev, andlib/db.tsprefershyperdrive.connectionString— which otherwise resolves to thelocalConnectionString(postgresql://user:password@localhost:5432/personal) inwrangler.jsonc. With no local Postgres listening that producedECONNREFUSED. The env-var override keeps the secret out of the git-trackedwrangler.jsonc. - Per-request pool path gated to production.
lib/db.tsresolveDb()now guards the ctx-keyed per-request pool withprocess.env.NODE_ENV !== "development". Undernext devthe OpenNext dev proxy reuses a singlecf.ctxobject across requests (and setsnavigator.userAgentto"Cloudflare-Workers"), so theafter(() => pool.end())from the 2026-06-02 change closed the pool and the next request reused the dead pool →Cannot use a pool after calling end on the pool. Dev now falls through to the cachedglobalThissingleton pool;opennextjs-cloudflare previewand the deployed Worker run asNODE_ENV=productionwith a genuinely fresh ctx per request and keep the per-request path.
- Local Hyperdrive points at Neon. Added
- Why: App failed to initialize in local dev — every DB query threw (
ECONNREFUSED, thenCannot use a pool after calling end on the pool). - Affected Modules:
lib/db.ts,.env(gitignored),wrangler.jsonc(unchanged; documented). - Trade-offs:
- Pro:
next devworks against the real Neon DB with a stable singleton pool; production per-request teardown behavior is unchanged; no DB credentials added to tracked files. - Con: Local dev reads/writes the production Neon database (no isolated dev DB);
NODE_ENVis the discriminator betweennext devand localpreview, so a non-standardNODE_ENVin dev would mis-route the pool path.
- Pro: