Repository navigation
Conversation
- Add @opennextjs/cloudflare and wrangler config (Smart Placement, Hyperdrive binding, observability). - Replace the global `db` with `getDb()`: one Hyperdrive-backed client per request on Workers (sockets can't cross requests), the DATABASE_URL client everywhere else. next-auth now builds its config per request. - Set `trustHost` so Auth.js accepts the Worker's hostname. - Pin Next to 16.3.x: the adapter 500s on 16.4 until opennextjs/opennextjs-cloudflare#1356 ships; Dependabot ignores 16.4+. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LcV53ESAdFnYAbNewkMuUD
`wrangler types` inlined ~16k lines of runtime types and, once the Worker had been built, referenced `.open-next/worker` (absent in CI). The only binding we add is HYPERDRIVE, so declare it by hand on top of the published types. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LcV53ESAdFnYAbNewkMuUD
alecf
force-pushed
the
cloudflare-deploy
branch
from
October 6, 2026 23:50
b35b028 to
78c0c70
Compare
- getDb() checks for the Workers runtime explicitly: Hyperdrive per request there (errors now surface instead of silently falling back), DATABASE_URL everywhere else, including `next dev`. - Drop initOpenNextCloudflareForDev: nothing reads bindings under `next dev` any more, which also removes its startup race. - Local Hyperdrive reads CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_HYPERDRIVE from .env rather than a hard-coded connection string. - postgres.js: fetch_types: false (skip a round trip per request client). - Typed global for the dev client instead of an `as` cast; fetch the client once in getStravaAccessToken. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LcV53ESAdFnYAbNewkMuUD
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sets the app up to run on Cloudflare Workers, with Postgres (Neon, for PostGIS later) behind Hyperdrive.
Why OpenNext and not vinext
npx vinext checkreports next-auth as incompatible (it relies on Next API route internals). Moving to better-auth is its own project, so this uses the@opennextjs/cloudflareadapter, which supports next-auth.Changes
wrangler.jsonc/open-next.config.ts: OpenNext Worker, Hyperdrive binding (HYPERDRIVE), Smart Placement (pages make several queries, so run near the DB), observability on.npm run preview/npm run deploy.getDb()replaces the globaldb: Workers can't reuse a socket from another request, so on Cloudflare each request gets its own client (keyed on itsExecutionContext). Tests, scripts and plainnext devkeep a singleDATABASE_URLclient.DATABASE_URLis now optional, since production uses the Hyperdrive binding.NextAuth(createAuthConfig)), so the Drizzle adapter uses the request's client.trustHost: true, because Auth.js otherwise rejects any non-Vercel host.~16.3.8: on 16.4, every dynamic route 500s withUnexpected loadManifest(/.next/server/preview-props.json)([BUG] UnexpectedloadManifest(/.next/server/preview-props.json)call on Next.js 16.4 canary opennextjs/opennextjs-cloudflare#1355, fix in #1356). Dependabot ignoresnext >= 16.4until then.@cloudflare/workers-types; the one binding we add (HYPERDRIVE) is declared insrc/types/cloudflare-env.d.ts. Update it ifwrangler.jsoncgains bindings.Not done yet (needs accounts)
wrangler hyperdrive create, replacing the placeholder id inwrangler.jsoncAUTH_SECRET,STRAVA_CLIENT_ID,STRAVA_CLIENT_SECRETTest plan
next buildopennextjs-cloudflare build, thenwrangler devagainst local Postgres:/,/recentmap,/api/auth/providers,/api/auth/sessionreturn 200; tRPC returns 401 without a session🤖 Generated with Claude Code
https://claude.ai/code/session_01LcV53ESAdFnYAbNewkMuUD