Repository navigation
feat(dashboard): run the dashboard as a Cloudflare Worker - #80
Open
RedStar071 wants to merge 3 commits into
Open
RedStar071 wants to merge 3 commits into
RedStar071 wants to merge 3 commits into
Conversation
The managed cloud runs on Cloudflare, and the dashboard is the part that needs a database. A Worker cannot reuse a socket across requests, so the database follows the request through Hyperdrive, task history lives in Workers KV, and the poller stays off. Adds the Cloudflare build target, the Worker configuration, stand-ins for the four packages that cannot run in a Worker, and a manual deploy workflow.
Architecture Inside the changed components — 2 viewsComponent view — Database connection handling Internal routing between per-request Hyperdrive bindings and long-lived Drizzle consumers. Component view — Worker runtime adapters Adapters bridging Cloudflare Workers bindings into the dashboard application. Data flow Tip Run 🪧 More tips
Thanks for using PR Lens! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out on X, Bluesky, Mastodon, Reddit or LinkedIn |
The selection between a client opened for the request and the process-wide pool had no test of its own, so a change that shared one client across requests passed every existing test. It now lives in a module of its own and is tested with overlapping requests.
The unit tests load the database util without Nitro's auto-imports, and the helper is called when the module loads, so it failed with a ReferenceError there.
This branch has not been deployed
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.
Summary
Related to #5. Lets the dashboard run as a Cloudflare Worker, for the managed cloud at
app.code-zero.dev. Self-hosted builds are unchanged.VITEHUB_HOSTING=cloudflare nuxt buildemits a Worker and mergesapps/web/wrangler.jsoncinto.output/server/wrangler.json. Every other target builds as before.database()now returns an object that resolves to a client opened for the request being served, and to the process-wide pool everywhere else. Better Auth keeps what it is given for the life of the process, so it receives that same object when noDATABASE_URLis set. NewcreateScopedDatabasein@code-zero/database, and@code-zero/authacceptsdatabaseas an alternative todatabaseUrl.KV, behind the sameKeyValueStoragecontract. ViteHub's own KV runtime cannot be resolved by the Nitro build that emits a Worker, so on Cloudflarevite-hub/kvis aliased to a small adapter.resendloads, the two subscription providers that drive a local CLI, andsafer-buffer(it throws while the bundle starts undernodejs_compat).reflect-metadatakeeps its side effect, which the passkey verifier needs.Deploy dashboardworkflow builds and deploys, and can apply migrations first.Why
The managed cloud runs on Cloudflare, and the dashboard is the part that needs a database. This does not deploy anything by itself: the workflow runs on demand.
Verification
aube run check:repoaube run lint:ciaube run typecheckaube testaube run buildSafety and compatibility
observemode as read-only, or explained the policy change above.The Hyperdrive configuration has query caching turned off, because sessions and permissions must never be read from a cache. The Worker holds its secrets on Cloudflare; the workflow never reads them. A deployment that sets neither
DATABASE_URLnor a Hyperdrive binding now fails on its first query instead of at boot, with the same message.📝 Migration
Before the first run of
Deploy dashboard:wrangler secret put NUXT_BETTER_AUTH_SECRET, plus the model provider's key and the mail credentials.DATABASE_URL(the origin database, for migrations) and start the workflow withmigrateon.app.code-zero.devhas no conflicting DNS record: a Workers custom domain creates its own.Agent context
wrangler devagainst a disposable Postgres: sign-up and sign-in, repeated session reads, the dashboard, repository and settings procedures, task history in KV, and the passkey options endpoint all answered. It also ran the default Node build.Reviewer notes
wrangler devrewrites theOriginheader to the route's host, so locallyNUXT_PUBLIC_SITE_URLhas to behttp://app.code-zero.devfor Better Auth to accept requests. Deployed, it ishttps://app.code-zero.devfromwrangler.jsonc.

Confidence Score: 5/5
No blocking issues were identified in the reviewed changes.Reviews (3) · Last reviewed commit: "fix(dashboard): import the request datab..." · Reviewed by Greptile