Menu

Custom Domains for Every Customer in a Next.js SaaS, with Cloudflare for SaaS
📰

Custom Domains for Every Customer in a Next.js SaaS, with Cloudflare for SaaS

DEV Community: nextjs·Muhammad Hassaan Anjum·6 days ago
#3q3VzRRC
#devtonextjs#devto#dev#cloudflare#hostname
Long article (1262 words) — no AI summary yet.
Reading 0:00
15s threshold

Many SaaS products eventually get the same request: "Can we use our own domain?" In EventsIQ it is not a nice-to-have. Customers put tracking links in their ads, and those links should say track.theirsite.com , not our name.

This post is how I built it with Next.js and Cloudflare for SaaS. The customer adds one DNS record and never touches a certificate.

The plan in one picture

There are two halves:

The Next.js app does the slow, careful work once: it registers the hostname with Cloudflare, watches the certificate, and writes each campaign's route into Cloudflare KV.

A Cloudflare Worker answers clicks. For each request it reads one KV key, replies with a 302, and queues the click to be saved afterwards.

The Next.js app is never in the path of a click.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.