Skip to content

Deploy to Cloudflare Pages (free hosting)#22

Open
chanind wants to merge 3 commits into
mainfrom
cloudflare-pages
Open

Deploy to Cloudflare Pages (free hosting)#22
chanind wants to merge 3 commits into
mainfrom
cloudflare-pages

Conversation

@chanind

@chanind chanind commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds support for deploying to Cloudflare Pages using @cloudflare/next-on-pages
  • Free tier: unlimited requests, unlimited bandwidth, 500 builds/month
  • No cold starts (unlike Render free tier)
  • All existing functionality works: SSR, fallback: "blocking", <Link>, redirects

How it works

The main challenge is that Cloudflare Workers don't have a filesystem, so readFileSync doesn't work at runtime. The solution:

  1. scripts/buildStaticData.ts pre-chunks the large CHANGELOG JSON files into ~256 small JSON files per version, served as static assets
  2. data/edgeDatabase.ts fetches the specific chunk needed via fetch() at runtime (same-origin, fast)
  3. Changelog pages pre-render all paths at build time using Node.js (no edge runtime needed)
  4. Commit/item pages use experimental-edge runtime and fetch data from static chunks on-demand

Test plan

  • yarn pages:build completes successfully (~30s)
  • Deployed and tested: https://068063ca.mathlib-changelog.pages.dev
  • Index/search pages work
  • Changelog pagination works (pre-rendered)
  • Commit detail pages work (edge SSR)
  • Item detail pages work (edge SSR)
  • Verify search autocomplete and navigation
  • Test with custom domain

To deploy

cd website && yarn install && yarn pages:build
npx wrangler pages deploy .vercel/output/static --project-name=mathlib-changelog

Or connect the repo to Cloudflare Pages with build command:
cd website && yarn install && yarn pages:build

🤖 Generated with Claude Code

chanind and others added 3 commits April 1, 2026 17:57
Run the existing Next.js app on Cloudflare's edge network using
@cloudflare/next-on-pages. Free tier: unlimited requests and bandwidth.

Key changes:
- Add @cloudflare/next-on-pages for building
- Add buildStaticData.ts to pre-chunk commit/item data into small
  JSON files served as static assets
- Add edgeDatabase.ts that fetches data chunks via HTTP instead of
  readFileSync (which isn't available on edge)
- Dynamic pages (commit/item) use experimental-edge runtime and
  fetch data from chunked static assets
- Changelog pages pre-render all paths at build time (Node.js)

Build: yarn pages:build
Deploy: npx wrangler pages deploy .vercel/output/static

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The vercel package (dependency of @cloudflare/next-on-pages) requires
Node >= 18. Also update checkout and setup-node actions to v4.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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