Skip to content

feat: migrate hosting back to Cloudflare Workers - #83

Closed
legions-developer wants to merge 4 commits into
mainfrom
gurbinder/migrate-back-to-cloudflare
Closed

legions-developer wants to merge 4 commits into
mainfrom
gurbinder/migrate-back-to-cloudflare

Conversation

@legions-developer

@legions-developer legions-developer commented Sep 30, 2026 •

Copy link
Copy Markdown
Owner

This restores Cloudflare hosting using the current OpenNext Workers adapter, while preserving Neon, Better Auth, existing S3-compatible R2 assets, and browser PDF/local-invoice flows. It retains the storage changes from #41 instead of reverting that PR and discarding later application changes.

Changes:

  • Add OpenNext/Wrangler, production and staging Worker configurations, R2 incremental cache, a Durable Object revalidation queue, and Cloudflare Images integration.
  • Add root/workspace build, preview, and deployment commands with the required Turbo environment handling. Update Next.js and its ESLint configuration from 15.5.18 to 15.5.26 to satisfy the adapter's supported versions, and require Node 22 for Wrangler.
  • Remove Vercel Analytics/monitor configuration, preserve PostHog and Sentry, and respect explicitly configured Sentry build tokens.
  • Add CI validation for the Cloudflare build and production/staging dry-run bundles. Document resource provisioning, build/runtime secrets, staging, cutover, and rollback in docs/cloudflare.md.

Validation:

  • GitHub's Cloudflare build and runtime checks passed for the application changes. The Vercel preview deployment also passed.
  • Immutable Yarn install, production OpenNext build (including Next.js lint/type validation), standalone TypeScript check, targeted ESLint, formatting, and diff checks passed.
  • Wrangler dry-run bundling passed for production and staging; Worker size is approximately 24.3 MiB uncompressed and 5.5 MiB compressed.
  • Local Worker checks passed for public pages, all five generated blogs, missing pages and stale 404s, logged-out Better Auth, protected tRPC APIs, immutable static assets, optimized images, and dynamic OG images.
  • Browser checks passed for a three-page invoice preview, PDF download, and IndexedDB save/reload. PostHog's /ingest/static/array.js rewrite returned JavaScript successfully.

Deployment requirements:

  • The measured bundle fits Cloudflare's current 64 MiB uncompressed limit on both Free and Paid plans. Bundle size alone does not require Paid; verify production CPU usage and request volume against the selected plan, and assess R2/Images usage separately. Provision the cache buckets, enable Cloudflare Images, and configure both build-time and runtime values before deployment.
  • Google OAuth/session lifecycle and authenticated Neon/R2 CRUD need staging verification with real staging credentials. Sentry reporting/source maps also need that check.
  • Keep the production origin and Better Auth secret consistent. No domain route is attached by this PR, and no production deployment or traffic switch has been performed.

Existing issue found during validation: CJK strings are preserved in PDF text extraction but do not appear visually in the PDF. This was reproduced from the unchanged main PDF source at fc14a4a with the same PDF dependencies/fonts, without Next.js or Cloudflare involved. PDF source, dependencies, and fonts are unchanged by this migration; this finding should be addressed separately before claiming complete CJK rendering support.

@vercel

vercel Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
invoicely-web Ready Ready Preview Sep 30, 2026 6:17pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: fb3aa9a5-0dd3-419d-bd15-eb2ff2df8cdf

📥 Commits

Reviewing files that changed from the base of the PR and between a792843 and 4db0c93.

📒 Files selected for processing (1)
  • docs/cloudflare.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The web app now has Cloudflare Worker configuration, build and deployment tasks, automated smoke checks, and deployment documentation. The README and Node.js requirement reflect the Cloudflare hosting setup.

Changes

Cloudflare deployment

Layer / File(s) Summary
Worker runtime configuration
apps/web/wrangler.jsonc, apps/web/open-next.config.ts, apps/web/next.config.ts, apps/web/.dev.vars.example, apps/web/.gitignore, apps/web/tsconfig.json, apps/web/public/_headers
Adds production and staging Worker bindings, OpenNext cache and queue overrides, a development initializer, local preview settings, and static asset cache headers. The TypeScript configuration excludes .open-next.
Cloudflare build and deployment tasks
apps/web/package.json, package.json, turbo.json
Adds Cloudflare build, preview, deploy, and smoke-test scripts, plus the OpenNext and Wrangler dependencies. Adds Turbo tasks and updates build inputs, outputs, and environment variables. Raises the minimum Node.js version to 22.
Cloudflare smoke validation
apps/web/scripts/smoke-cloudflare.mjs, .github/workflows/cloudflare-checks.yml
Adds local preview startup and checks for pages, authorization responses, static assets, image endpoints, delayed 404 behavior, and runtime errors. The workflow builds the Cloudflare target, runs a Wrangler dry run, writes local environment values, and runs the smoke check.
Hosting documentation and Vercel integration removal
README.md, docs/cloudflare.md, apps/web/package.json, apps/web/next.config.ts, apps/web/src/app/layout.tsx
Documents Cloudflare setup, environment variables, staging, production cutover, and rollback. Removes Vercel Analytics and automatic Vercel monitor configuration.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Merge Risk: ⚪ Minimal · up to 4db0c

The Cloudflare deployment path is ready to merge. The size guidance is corrected, and staging requires separately configured database and asset-storage values; no confirmed issue blocks the change.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 4db0c

The migration preserves the existing authentication and data-storage model, separates staging cache resources, and keeps production cutover explicit with Vercel available for rollback. No introduced security vulnerability was established. Deployment permissions, actual environment isolation, and authenticated cache behavior still require verification.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — A compromised Worker or privileged deployment configuration could reach the configured application database and asset storage, plus the new cache, queue, and image services. Exact credential scope and account-wide deployment authority are not established by the repository.

Trust Boundaries and Controls

  • observed — Selected protected asset procedures use middleware that resolves a session from request headers and rejects missing sessions. Asset listing derives its storage lookup identity from the authenticated user rather than a caller-supplied user identifier.
  • observed — The inspected auth and tRPC entrypoints contain no explicit static-cache opt-in. The added public cache header applies only to immutable Next.js static assets. These controls do not establish the adapter's authenticated-response cache semantics.

Resilience and Maintainability Implications

  • inferred — Preserving the origin, authentication secret, database, and asset storage reduces rollback discontinuity and avoids a separate application-data migration. The documented routing rollback does not prove atomic handling of in-flight traffic or recovery and cleanup of Cloudflare cache and queue state.

Hardening Proposals

  • proposed — Before cutover, verify environment-specific runtime values, least-privilege deployment credentials, and every reachable Worker endpoint, including any workers.dev address. Treat intended staging isolation as a deployment check, not a guarantee supplied by distinct cache bindings.
  • proposed — Extend staging validation to alternate authenticated users and logged-out requests against cacheable paths, and rehearse interrupted cutover and rollback. Record ownership and retention of residual Worker, cache, and queue resources rather than assuming routing restoration also cleans them up.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the primary change: restoring hosting on Cloudflare Workers.
Description check ✅ Passed The description directly explains the Cloudflare Workers migration, its supporting configuration, validation, deployment requirements, and known limitation.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 4e2432f2-e681-457f-ad8f-b1aaba75f4b3

📥 Commits

Reviewing files that changed from the base of the PR and between fc14a4a and a792843.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (15)
  • .github/workflows/cloudflare-checks.yml
  • README.md
  • apps/web/.dev.vars.example
  • apps/web/.gitignore
  • apps/web/next.config.ts
  • apps/web/open-next.config.ts
  • apps/web/package.json
  • apps/web/public/_headers
  • apps/web/scripts/smoke-cloudflare.mjs
  • apps/web/src/app/layout.tsx
  • apps/web/tsconfig.json
  • apps/web/wrangler.jsonc
  • docs/cloudflare.md
  • package.json
  • turbo.json
💤 Files with no reviewable changes (1)
  • apps/web/src/app/layout.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Comment thread docs/cloudflare.md Resolved
@legions-developer
legions-developer deleted the gurbinder/migrate-back-to-cloudflare branch October 3, 2026 12:42

This branch was successfully deployed

1 active deployment
Preview — 266e44fe Deployed Sep 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant