- Oct 24, 2026
- 4 min read
Shipping a Landing Page Fully as Code: From an Empty Folder to a Live Domain
I needed a credible landing page on a separate domain: what we do, a sample report, two packages, real client work, a privacy notice. I wanted every part of it to be a file in a repository or a command I could repeat, including the domain and the DNS.
1. Snapshot the domain before touching it
Record what DNS says today, so you can prove nothing broke later:
D=example.com
for t in A AAAA MX TXT CAA; do dig +short $t $D; done
dig +short TXT _dmarc.$D
dig +short TXT google._domainkey.$D # DKIM: your mail provider's selector
dig +short NS $D # who serves DNS today
curl -s -o /dev/null -w "%{http_code}\n" https://$D/ # 000 = nothing there
My domain had a complete email setup (MX, SPF, DKIM, DMARC with
p=quarantine) and no website. For a domain that sends email to
strangers, that looks disposable, to people and to spam filters.
2. A static build whose rules live in files
| File | Job |
|---|---|
astro.config.mjs | site, trailingSlash: 'always', sitemap |
public/_headers | HSTS, frame and content-type protection, referrer and permissions policy, a strict CSP, long caching for hashed assets |
public/robots.txt | The Sitemap: line |
src/pages/404.astro | A real 404 page |
src/config.ts | Contact email, data controller, prices: everything the copy and the privacy notice repeat |
scripts/sample-report.mjs | Renders the sample PDF from example data, never from a real prospect |
With self-hosted fonts and no analytics, nothing comes from a third party, so
the Content Security Policy can be default-src 'self'.
3. Host it, and check what your tools changed
I created the project with Cloudflare’s CLI. It turned out to create a
Worker with static assets rather than a classic Pages project, and to
quietly add a server adapter to my static site
(what changed and what I kept).
Lesson: after any scaffolding command, git status and git diff before
committing.
4. One canonical host
www.example.com is canonical; the bare domain must redirect, not serve a
second copy. Path-based _redirects can’t match on hostname, so eight lines
of worker code sit in front of the static files:
export default {
async fetch(request, env) {
const url = new URL(request.url);
if (url.hostname === 'example.com') {
url.hostname = 'www.example.com'; url.protocol = 'https:'; url.port = '';
return Response.redirect(url.toString(), 301);
}
return env.ASSETS.fetch(request);
},
};
5. The domain: move DNS without breaking email
Custom domains on Cloudflare’s Workers need the domain’s DNS on Cloudflare. The safe order:
- Add the domain in Cloudflare (Free).
- Check the import kept MX, SPF, DKIM and DMARC before anything else.
- Switch the nameservers at the registrar.
- Declare the hostnames in the config; deploying creates the DNS records and the certificate:
"routes": [
{ "pattern": "www.example.com", "custom_domain": true },
{ "pattern": "example.com", "custom_domain": true }
]
- Re-run the snapshot from step 1: the same four email records.
6. “Not live yet” may be your own DNS cache
After the deploy, my laptop insisted the domain didn’t exist. It had cached
the negative answers from my earlier dig checks, while Cloudflare’s
resolver already returned the new addresses. Test through the real address
instead of waiting:
dig +short A www.example.com @1.1.1.1
curl --resolve www.example.com:443:<that address> -sI https://www.example.com/
7. Verify like a visitor, then like a crawler
- Pages return 200, unknown paths 404, the bare domain 301 to
https://wwwwith path and query kept. - Security headers present, certificate valid.
- In a headless browser: no CSP violations, no horizontal scroll at 390 px, fonts loaded.
The checklist
DNS snapshot → static build with headers, robots, sitemap, 404 and a config
file → deploy to the platform’s test address and check it → domain on
Cloudflare with email records verified → custom domains in config →
canonical-host redirect → re-check email DNS, test through --resolve →
commit everything, including generated config, after reading it.
Takeaways
- Snapshot DNS first and compare after; email is what breaks silently.
- Rules in files: headers, redirects, routes, the sample report.
- Read what your tools changed before committing it.
- Your resolver can lie; test through the real address.