$ ls ./menu

© 2025 ESSA MAMDANI

cd ../blog
11 min read
Web Development

The Definitive Guide: Seamless Migration from Cloudflare to Vercel (Zero Downtime!)

> Unlock superior developer experience and performance for your frontend applications by migrating from Cloudflare Pages or Workers to Vercel. This comprehensive guide, crafted by Essa, ensures a zero-downtime transition covering domains, compute, storage, and more.

Audio version coming soon
The Definitive Guide: Seamless Migration from Cloudflare to Vercel (Zero Downtime!)
Verified by Essa Mamdani

Alright, fellow developers, Essa here. You've been building, deploying, and iterating, perhaps leveraging the formidable power of Cloudflare for its CDN, DNS, and serverless Workers. It's an undeniably robust platform, a workhorse for many. But what if I told you there's a path to an even more refined developer experience, unparalleled performance for your frontend-heavy applications, and a deployment workflow that feels less like a chore and more like pure magic?

That path, my friends, often leads directly to Vercel.

For a long time, I've witnessed teams grapple with fragmented deployment pipelines, complex configurations, and the subtle friction that can accumulate when your platform isn't hyper-optimized for the modern web's demands. Vercel, with its laser focus on the frontend cloud and deep integration with frameworks like Next.js, has fundamentally reshaped how we build and ship web applications. It's not just a hosting platform; it's an end-to-end development and deployment ecosystem designed for speed, scalability, and an almost intuitive developer flow.

This isn't about abandoning a good platform for a bad one. It's about evolving. It's about recognizing when a specialized tool can elevate your craft to the next level. If you're running Cloudflare Pages or Workers and you're ready to experience a deployment pipeline that anticipates your needs, this guide is your definitive blueprint for a smooth, zero-downtime migration to Vercel. Let's dive in.

Why Vercel? The Edge Advantage

Before we get into the "how," let's quickly underscore the "why." Vercel’s platform is built from the ground up to optimize for the modern web, particularly applications leveraging React, Next.js, Svelte, Vue, and others. Key advantages include:

  • Unrivalled Developer Experience (DX): Instant deployments, automatic SSL, preview deployments for every Git commit, and seamless integration with your favorite frameworks.
  • Performance at the Edge: Vercel's global Edge Network, powered by Edge Functions, delivers your content and compute logic closer to your users, drastically reducing latency.
  • Next.js Integration: As the creators of Next.js, Vercel offers unparalleled integration, unlocking features like Image Optimization, Incremental Static Regeneration (ISR), and Server Components with zero configuration.
  • Open Standards & Open Source: Vercel champions open standards, ensuring flexibility and preventing vendor lock-in, which resonates deeply with my philosophy.

Now, let's get your project moved with surgical precision.

1. Project Setup on Vercel: The First Touch

The initial step is remarkably straightforward. Vercel is built around Git-based deployments, which means if your project is already in GitHub, GitLab, or Bitbucket, you're halfway there.

Importing Your Project

  1. Create a Vercel Account: If you don't have one, sign up at vercel.com.
  2. Import Git Repository: From your Vercel Dashboard, click "Add New..." -> "Project". You'll be prompted to import a Git repository. Connect your preferred Git provider.
  3. Select Your Repository: Choose the repository containing your Cloudflare Pages or Workers project.
  4. Configure Project: Vercel will attempt to auto-detect your framework (e.g., Next.js, React, Astro, SvelteKit). It will suggest default build commands and output directories. Review these and adjust if necessary.
    • Pro Tip: For Cloudflare Pages projects, your build command and output directory might be similar to what you had configured. For Workers, this step usually applies to the frontend part of your application.

Once configured, hit "Deploy." Vercel will build and deploy your application, providing you with a unique .vercel.app preview URL. This initial deployment is crucial for testing before you even touch your custom domain.

2. Migrating Custom Domains with Zero Downtime

This is often the most critical and anxiety-inducing step, but with the right approach, it can be entirely seamless. The key is to add your domain to Vercel before changing your DNS records.

  1. Add Your Domain to Vercel:

    • Navigate to your project in the Vercel Dashboard.
    • Go to "Settings" -> "Domains".
    • Enter your custom domain (e.g., yourdomain.com) and click "Add".
    • Vercel will then provide you with the necessary DNS records (typically an A record for the root domain and a CNAME record for www). Do NOT change your DNS records yet. Vercel will automatically provision an SSL certificate for your domain in the background.
  2. Verify SSL Provisioning: Wait a few minutes (sometimes up to 15-20) until Vercel indicates that the SSL certificate has been successfully issued for your domain. You'll see a green checkmark next to your domain in the Vercel dashboard. This is the green light.

  3. Update DNS Records at Cloudflare:

    • Go to your Cloudflare dashboard and navigate to the DNS section for your domain.
    • Crucial Step: Identify the existing A record for your root domain (@) and the CNAME record for www.
    • Change A record: Update the A record for @ to point to Vercel's IP address (typically 76.76.21.21).
    • Change CNAME record: Update the CNAME record for www to point to cname.vercel-dns.com.
    • Cloudflare Proxy (Orange Cloud): For zero downtime during this transition, ensure the Cloudflare proxy (orange cloud) is disabled for these specific records during the DNS change. This allows DNS changes to propagate directly. Once Vercel is fully serving traffic, you can re-enable Cloudflare's proxy features if you still intend to use Cloudflare as a CDN/WAF in front of Vercel (though Vercel's own Edge Network often negates the need for this for static assets).
    • Pro Tip: If you're using Cloudflare as your primary DNS provider and want to simplify, you can fully migrate your nameservers to Vercel DNS. However, if you rely on advanced Cloudflare DNS features or other Cloudflare services for the same domain, keeping Cloudflare as your DNS provider and just updating the A/CNAME records is perfectly valid.
  4. Monitor Propagation: DNS changes can take a few minutes to several hours to propagate globally. You can use tools like dnschecker.org to monitor propagation. During this time, traffic will gradually shift from Cloudflare Pages/Workers to Vercel without interruption, as both platforms will have your domain's SSL certificate provisioned.

3. Converting Build & Deployment Configuration

Cloudflare Pages uses a _headers and _redirects file, or a wrangler.toml for Workers configuration. Vercel centralizes much of this configuration into a vercel.json file at your project's root.

Build Commands and Output Directories

Vercel usually auto-detects these, but you can explicitly define them in vercel.json or through the Vercel Dashboard project settings.

json
1// vercel.json
2{
3  "buildCommand": "npm run build",
4  "outputDirectory": "dist",
5  "framework": "nextjs" // Optional, but good practice
6}

Redirects and Headers

Instead of _redirects or _headers files, Vercel uses the redirects and headers properties within vercel.json.

Cloudflare _redirects example:

/old-path /new-path 301
/blog/* /articles/:splat 302

Equivalent vercel.json:

json
1// vercel.json
2{
3  "redirects": [
4    {
5      "source": "/old-path",
6      "destination": "/new-path",
7      "permanent": true // 301 redirect
8    },
9    {
10      "source": "/blog/:path*",
11      "destination": "/articles/:path*",
12      "permanent": false // 302 redirect
13    }
14  ],
15  "headers": [
16    {
17      "source": "/_next/static/(.*)",
18      "headers": [
19        {
20          "key": "Cache-Control",
21          "value": "public, max-age=31536000, immutable"
22        }
23      ]
24    }
25  ]
26}

Pro Tip: Vercel's redirects and headers are incredibly powerful, supporting regular expressions and more. Review the Vercel documentation for advanced patterns.

4. Moving Environment Variables and Secrets

Both platforms handle environment variables, but the interface and scope differ.

Vercel Environment Variables

Vercel allows you to set environment variables with different scopes: Production, Preview, and Development.

  1. Vercel Dashboard: Navigate to your project -> "Settings" -> "Environment Variables". Add your variables here.
  2. Vercel CLI: For local development and managing variables via script, use the Vercel CLI:
    bash
    1vercel env add MY_API_KEY production
    2# Enter value when prompted
    3vercel env add MY_API_KEY preview
    4vercel env pull .env.development # Pulls variables for development

Pro Tip: Always define secrets and API keys via the Vercel Dashboard or CLI, never commit them to your Git repository. Vercel automatically encrypts and secures these variables.

5. Migrating Compute: Cloudflare Workers to Vercel Edge Functions

This is where a significant architectural shift might occur, especially if you have complex logic in Cloudflare Workers.

Cloudflare Workers vs. Vercel Edge Functions

Both leverage a global network of servers to execute code close to the user, offering low latency. However, their primary use cases and integration points differ:

  • Cloudflare Workers: Often standalone, general-purpose serverless functions, frequently used for API gateways, routing, or transforming requests at the edge. They have a distinct wrangler.toml configuration and often their own deployment pipeline.
  • Vercel Edge Functions: Primarily designed to be part of your application. They integrate seamlessly with Next.js (as API Routes or Middleware) or can be deployed as standalone functions via the functions property in vercel.json. They are optimized for frontend-driven workloads like A/B testing, authentication, localization, or data fetching for your UI.

Conversion Strategy

  1. Identify Worker Logic: Analyze your Cloudflare Workers. What are they doing?

    • Are they simple API endpoints?
    • Are they performing request rewrites or header modifications?
    • Are they handling authentication or authorization?
    • Are they serving static assets? (Vercel handles this natively)
  2. Re-implement as Vercel Edge Functions/API Routes:

    • API Endpoints: Most Worker API logic can be directly translated into Vercel Edge Functions (if you need minimal latency and smaller bundles) or Serverless Functions (Node.js runtime, suitable for heavier computation or complex integrations). For Next.js applications, these become API Routes within your pages/api or app/api directory, automatically deployed as Edge or Serverless Functions.

    • Middleware/Rewrites: Vercel's Middleware (for Next.js) or vercel.json redirects/rewrites can handle most request manipulation tasks that Workers might have performed.

Simple Cloudflare Worker Example:

javascript
1// worker.js
2export default {
3  async fetch(request, env, ctx) {
4    const url = new URL(request.url);
5    if (url.pathname === '/api/hello') {
6      return new Response('Hello from Cloudflare Worker!', { status: 200 });
7    }
8    return fetch(request);
9  },
10};

Equivalent Vercel Edge Function (Next.js API Route):

javascript
1// pages/api/hello.ts or app/api/hello/route.ts
2import type { NextRequest } from 'next/server';
3
4export const config = {
5  runtime: 'edge', // This makes it an Edge Function
6};
7
8export default async function handler(req: NextRequest) {
9  return new Response('Hello from Vercel Edge Function!', { status: 200 });
10}

Pro Tip: If your Worker logic is very complex or performs tasks unrelated to your main frontend application, consider keeping it as a standalone Cloudflare Worker (or even migrating it to another serverless provider) and consuming it as an external API from your Vercel-deployed frontend. This maintains separation of concerns.

6. Migrating Storage: Cloudflare R2/D1/KV to Vercel Storage/Integrations

Vercel doesn't offer a direct 1:1 mapping for Cloudflare's specific storage solutions (R2, D1, KV). Instead, it provides its own native options and a rich ecosystem of integrations.

Vercel's Storage Offerings

  • Vercel KV (Redis-compatible): For simple key-value storage, often replacing Cloudflare KV. Ideal for caching, session management, or feature flags.
  • Vercel Blob (S3-compatible): For storing large files, images, videos, etc. Can be a direct replacement for Cloudflare R2 if you're comfortable with the Vercel-native S3 API.
  • Vercel Postgres: A managed Postgres database, perfect for relational data. Can replace D1 for many use cases, offering more mature tooling and ecosystem.

Integration with Third-Party Databases

Vercel shines with its marketplace of integrations. If you're using D1 or R2, you might consider:

  • Relational Databases: Migrate D1 data to a fully managed PostgreSQL (e.g., Neon, Supabase, PlanetScale) or a serverless option like FaunaDB. Vercel has direct integrations and excellent documentation for all of these.
  • Object Storage: For R2, you can use Vercel Blob, or continue using R2 by connecting to it via its S3-compatible API from your Vercel Edge Functions/Serverless Functions. Alternatively, use AWS S3, DigitalOcean Spaces, or similar S3-compatible services with Vercel integrations.
  • Key-Value Stores: Vercel KV is the natural choice. Alternatively, Upstash (Redis) has a strong Vercel integration.

Migration Strategy:

  1. Assess Current Storage: Understand the data structure and access patterns of your R2, D1, or KV stores.
  2. Choose Vercel Equivalent/Integration: Select the Vercel-native storage solution or a suitable third-party integration based on your needs.
  3. Data Migration: This is the most labor-intensive part.
    • KV: Write a script to fetch data from Cloudflare KV and insert it into Vercel KV or Upstash.
    • R2: Use an S3 migration tool or script to copy objects from R2 to Vercel Blob or another S3-compatible service.
    • D1: Export your D1 SQLite database (or use D1's built-in export tools) and import it into a PostgreSQL database (e.g., Neon, Supabase, Vercel Postgres). You'll likely need to adjust your application code to use a PostgreSQL ORM (e.g., Prisma, Drizzle ORM) instead of a D1-specific client.
  4. Update Application Code: Modify your application to use the new storage client libraries (e.g., @vercel/kv, @vercel/blob, drizzle-orm for Postgres).

7. Post-Migration & Optimization

Once your domain is pointing to Vercel and your application is live, the work isn't over.

  • Thorough Testing: Conduct extensive testing of all features, especially API endpoints, forms, and dynamic content.
  • Monitor Performance: Leverage Vercel Analytics and Speed Insights to gain deep insights into your application's performance. Identify bottlenecks and areas for optimization.
  • Leverage Vercel Features: Explore features like:
    • Preview Deployments: Every Git push to a branch automatically gets a preview URL.
    • Vercel Cron Jobs: Schedule serverless functions to run at specific intervals.
    • Deployment Protection: Password-protect preview deployments.
    • Monitoring & Logging: Integrate with external logging services or use Vercel's built-in logs.
  • Cleanup Cloudflare: Once you are 100% confident your application is stable on Vercel, you can safely remove your project from Cloudflare Pages/Workers.

Conclusion: A New Era of Development

Migrating from Cloudflare to Vercel is more than just switching providers; it's an upgrade to a development workflow that prioritizes speed, performance, and an unmatched developer experience. While Cloudflare offers robust infrastructure, Vercel provides a frontend cloud specifically engineered to make building and deploying modern web applications a joy.

By following this guide, you've not only moved your application but positioned yourself to leverage the cutting-edge features and optimizations that Vercel continuously rolls out. Welcome to a more seamless, performant, and delightful development journey. Now go forth and build something incredible!