Let's preface this by admitting that the title is a little farcical - the fact that Vercel and other similar sites give you preview domains out of the box with no setup is a lovely feature. This blog is purely to show you that it's actually possible to configure these yourself, and furthermore, it's way easier than you might think!
To give you some context, my site pert.dev is built on Zola - a static site which I serve on my $5 VPS from Linode, using Caddy. I use Cloudflare as my domain registrar and for DNS. While my setup (which I'll link to at the end if you want to skip ahead) is specific to these tools, my goal for this blog is to demonstrate that the core technologies for setting this up yourself are actually easy-peasy, regardless of your stack.PR-Previews: The Big Picture
At their heart, PR previews are surprisingly simple and can be broken down into three main components. We'll dive deep into each one, but here's the overview:DNS Management: Creating a new A record for our preview subdomainFile Deployment: Getting our PR changes somewhere they can be servedWeb Server Config: Telling our web server how to serve these files