Tech11 min read

Migrating an Astro Blog from Vercel to Cloudflare Pages

IkesanContents

Vercel costs had started creeping up, so I decided to move this Astro blog (lilting.ch) over to Cloudflare Pages.
I wanted to finish the migration within two weeks while keeping existing article URLs from returning 404s during the cutover.

When I started, I had neither a Cloudflare account nor its CLI installed. I handled account creation, browser authentication, and registrar changes myself, and had Codex drive the rest through the CLI and API. By November 26, 2026, production delivery from Cloudflare Pages and automatic deploys on GitHub push were both working.

The site serves Japanese and English articles alongside site search, small Lab tools and browser games, and redirects from older URLs. The domain is registered at Gonbei Domain and previously used Vercel’s nameservers.

Separating DNS Migration from Hosting Cutover

Changing a domain’s DNS provider and its hosting destination at the same time can break access for visitors whose resolvers still cache the old records. To avoid that, I moved DNS management to Cloudflare first while keeping the site itself served from Vercel.

StageDNS ProviderSite Hosting
Before migrationVercelVercel
During nameserver propagationMix of old and new depending on resolverVercel from both
After Cloudflare delegation confirmedCloudflareStill Vercel
After Pages setup and checks passedCloudflareCloudflare Pages

First, I backed up all existing DNS records from Vercel (routing records, domain verification records, and so on) and copied them into Cloudflare. Because Cloudflare proxies web traffic through its CDN and WAF by default, I left the web records set to DNS only (proxy disabled, pointing straight to Vercel) so that visitors hitting either the old nameservers or Cloudflare still reached the same Vercel deployment. I also compared DNS responses from both sides to make sure nothing was missing.

Cloudflare API Permissions and GitHub App Authorization

Wrangler, Cloudflare’s official CLI, starts working once you approve a browser OAuth login. However, that OAuth session mainly covers Pages operations and did not allow editing DNS records. To manage DNS from scripts and the CLI, I had to create a separate API token.

Even after adding DNS edit permissions, registering WAF rules and setting up temporary redirects for the cutover failed with permission errors. Because I had not listed every required operation up front, I ended up adding permissions to the token multiple times along the way.

OperationRequired Permission or Auth
Backing up, copying, and switching DNS recordsZone Read, DNS Edit
Registering firewall (WAF) block rulesZone WAF Edit
Temporary redirects and www redirectSingle Redirect Edit
Uploading to Pages and adding custom domainsWrangler browser OAuth
Automatic builds from GitHubAccess approval for the Cloudflare Workers & Pages GitHub App

Connecting a GitHub repository sits on a separate auth layer from Cloudflare API tokens; in addition to Cloudflare permissions, I had to authorize the Cloudflare Workers & Pages app on GitHub so it could access the target repository.

Changing Nameservers at Gonbei Domain

Creating the lilting.ch zone (Cloudflare’s per-domain management unit) assigned two nameservers. In the Gonbei Domain control panel, I submitted a change request from Vercel’s two nameservers to Cloudflare’s.

Before
ns1.vercel-dns.com
ns2.vercel-dns.com

After
keaton.ns.cloudflare.com
rayne.ns.cloudflare.com

The registrar’s form warned that propagation could take anywhere from a few days to a few weeks depending on the registry, and the confirmation email noted that the control panel would keep showing the old nameservers until the update finished.

Rather than relying on email notifications alone, I checked actual DNS responses directly. Later the same day, delegation from the .ch parent zone and lookups against public DNS resolvers (1.1.1.1 and 8.8.8.8) all switched to the two Cloudflare nameservers, and the Cloudflare zone became active.

Adapting the Astro Build for Cloudflare Pages

Because this blog can be exported entirely as static HTML, I did not use Cloudflare Pages Functions. I kept the existing Vercel build intact and added pnpm build:cloudflare for Cloudflare. That script disables the Vercel adapter, writes output to dist-cloudflare, runs tag and Open Graph image generation, builds Astro and the Pagefind search index, and then prepares the Pages redirect rules.

URL formatting also needed an adjustment for Pages. Existing article URLs do not have trailing slashes, so Astro still renders pages in the traditional directory format (slug/index.html) to preserve canonical and bilingual hreflang URLs, and a post-build step moves each index.html to slug.html. That lets Cloudflare Pages serve clean slash-free URLs directly. Browser game HTML files under public/ were excluded from this move so their relative asset paths would not break.

Redirects from vercel.json were converted into Cloudflare Pages _redirects. To keep the preview pages.dev hostname out of search engines, I added an X-Robots-Tag: noindex header to pages.dev responses while keeping it off the production lilting.ch domain.

Dropping a Large WASM Lab Tool

The Lab animation editor relied on an FFmpeg WASM binary that was too large to upload to Cloudflare Pages. Smaller WASM files such as sql.js and libarchive were well under 25 MiB and worked without issues.

Cloudflare Pages’ Free plan limits cap a site at 20,000 files and a single file at 25 MiB (about 26 MB). Since the FFmpeg WASM binary exceeds that single-file limit, I dropped the editor from the migration, archived its source inside the repository, and excluded FFmpeg-specific files from the build output.

To avoid breaking links from existing articles, /lab/animation-editor still returns HTTP 200 with a discontinuation notice, marked noindex and removed from the Lab index and sitemap.

Keeping Old Hashed CSS for Open Tabs

Browsers that already had an article open before the cutover still hold the HTML served by Vercel. Since Astro attaches a content hash to built CSS filenames, those filenames change between builds; if an open tab still references an older hashed CSS file after the host switch, CSS requests can start returning 404 even though the page URL itself has not changed.

I extracted all JS and CSS references from pre-cutover HTML and checked them against the new build, which turned up several missing legacy CSS files. I saved those old CSS files in the repository and added a build step that verifies them against recorded SHA-256 hashes and copies them into the Cloudflare output. Future builds now stay self-contained inside the repository without needing to fetch anything from the old Vercel deployment.

Porting Vercel Firewall Rules to Cloudflare WAF

I backed up 27 active custom deny rules and 5 IP restrictions from Vercel Firewall and ported them to Cloudflare WAF. Because Vercel’s rule file cannot be imported directly, I rewrote the conditions to fit within the 5 custom rules allowed on the Cloudflare Free plan.

The ported rules cover common scanner paths, blocked IPs, specific malformed article path patterns, and Referer header blocks.

Converting Vercel’s regex conditions into Cloudflare expressions ran into available field limits and restrictions on concat. To work around that, I split the Referer matching into separate HTTP and HTTPS rules and tested the converted logic against the original regex across 2,013 test cases. The only difference was that the Cloudflare rule also blocked malformed hostnames containing consecutive dots; since that does not affect legitimate traffic, I recorded the difference and kept it.

Live requests confirmed that normal articles and similar unrelated referrers returned HTTP 200, while blocked paths and referrers returned HTTP 403. Certificate validation paths were also left unblocked.

For IP restrictions, I verified the saved rules by reading them back from the Cloudflare API, without sending test traffic from the blocked source IPs. Because Vercel’s internal reputation history and logs cannot be migrated, this only reproduces the matching rules themselves.

Hitting HTTP 522 During Cutover Testing

After confirming that the blog worked on the temporary pages.dev URL, I registered the custom domains on Pages and tried pointing www to Cloudflare while the custom domain status was still pending. That immediately returned HTTP 522 (connection timed out), so I reverted www back to Vercel.

At the time of that test, the domain was already registered on Pages and TLS certificates were valid, yet the Pages hostname status was still pending. Cloudflare’s custom domain documentation mentions that pointing a CNAME without registering the domain causes 522 errors, and in practice the same 522 happened even after registration while validation remained pending.

For the actual cutover, I added a temporary HTTP 307 redirect during the pending window. Regular visitors were redirected—preserving both path and query string—to the still-running Vercel deployment, while I verified Pages directly using a test request that bypassed the redirect. Once the custom domain turned active, I removed the temporary 307 redirect. The permanent HTTP 308 redirect from www to lilting.ch stayed in place, excluding certificate validation paths.

Recreating the Project from Direct Upload to Git Integration

At first I used Direct Upload via Wrangler—building the static site locally and uploading the generated files manually—under a project named lilting-channel-web. Because Astro writes intermediate build state into .astro, running a migration build in the same checkout would conflict with my running local dev server, so I ran local builds in a separate git worktree (an independent checkout directory of the same repository). Direct Upload worked fine for staging checks, but pushing new articles to GitHub would not trigger automatic updates.

I wanted to keep publishing via normal git commit and git push, so I moved to Cloudflare Pages’ native Git integration, where Cloudflare automatically builds and deploys on every push. According to the Direct Upload documentation, an existing Direct Upload project cannot be converted into a Git-integrated project, so I had to create a new one.

I created lilting-channel-web-git and connected it to the same GitHub repository. The first API attempt returned HTTP 401 until I authorized the Cloudflare app on GitHub for the repository. At one point the browser also showed a “Configure your Worker project” screen; since Workers is a separate runtime from Pages, I skipped creating a Worker and configured Pages Git integration instead.

I did not set up GitHub Actions and relied solely on Pages Git integration with the following settings:

SettingValue
Production branchmain
Build commandpnpm install --frozen-lockfile && pnpm build:cloudflare
Output directorydist-cloudflare
Node.js24.22.1
pnpm10.27.0
Additional build env varsSHARP_IGNORE_GLOBAL_LIBVIPS=1, SKIP_DEPENDENCY_INSTALL=1
Preview builds on other branchesDisabled

SHARP_IGNORE_GLOBAL_LIBVIPS=1 tells Sharp to use its bundled binary instead of a mismatched system libvips in the build image, and SKIP_DEPENDENCY_INSTALL=1 turns off Cloudflare’s automatic package install so the build command runs pnpm install --frozen-lockfile directly.

After pushing to main, Cloudflare triggered a github:push build and the GitHub Cloudflare Pages check passed. I then switched the custom domains from the old Pages project to the new one, again using a temporary 307 redirect—this time pointing to the old Pages project, which already had the latest articles. Once both lilting.ch and www.lilting.ch became active, I removed the temporary redirect and kept the old Direct Upload project around as a rollback option.

Draft filtering still uses Astro’s existing check (import.meta.env.PROD && entry.data.draft excludes drafts from production builds). Pushing a draft: true article to main does not generate a page; changing it to draft: false and pushing publishes it. Since this happens at build time, the Markdown files themselves remain visible in the GitHub repository.

Post-Migration Checks and Leaving Vercel Running Briefly

On the Git-integrated staging domain, I checked all 2,127 URLs in the sitemap, 68 JS and CSS references, and 27 legacy redirects, along with 404 handling for unknown URLs, HTTP 200 on the Lab discontinuation page, and downloads for the games and small WASM files. In a real browser, I checked Japanese and English article pages, canonical URLs, dates, math rendering, and opening articles from search.

After switching the production domain, I ran 15 checks covering normal pages, 404s, and WAF blocks, and confirmed that the pages.dev noindex header was not leaking onto production articles.

Vercel’s Git integration is now disconnected, so future pushes will not trigger Vercel builds. Still, accounting for cached DNS responses and open browser tabs, I plan to keep the old Vercel deployment and Pro subscription running for two or three days until November 28–29 before shutting them down.

As a side note, I also cleaned up two other small projects on Vercel: a sample page referenced by an article was moved to Cloudflare Pages (with links updated in both the Japanese and English posts), and an unused editor project was paused.