Cloudflare
This page shows how to move your domain to Cloudflare and configure DNS, CDN caching, and SSL/TLS so traffic reaches your Refract backend safely.
📖 See also: Cloudflare R2 CDN for user-upload object storage (profile pictures) — R2 bucket setup, S3-compatible credentials, and custom-domain publicUrl configuration are separate from app-origin DNS on this page.
How it works
Cloudflare sits at the edge in front of your origin deployment, resolves your DNS records, serves cached static assets when possible, and handles certificate management for inbound HTTPS.Extending this system
Use this recipe to onboard or migrate a production domain to Cloudflare for Refract.-
Prepare the current DNS zone
Export your current DNS records from your existing registrar/DNS host. Reduce TTL on critical records (for example
A,CNAME, andMX) to speed up cutover. -
Transfer or delegate your domain to Cloudflare
In Cloudflare, add the domain and choose either full registrar transfer or nameserver delegation. Confirm all imported DNS records are complete before switching traffic.
-
Point app hostnames to origin
Create proxied DNS records for your production hostnames (orange cloud enabled). Point these at your hosting provider target (for example Railway-generated domain).
-
Configure SSL/TLS and edge behavior
Set SSL/TLS mode to
Full (strict)and enable automatic HTTPS rewrites. Add cache rules for static assets and keep API/GraphQL routes uncached. -
Validate and monitor
Verify certificate status, DNS resolution, and app behavior from multiple networks. Keep a rollback plan ready for mail/DNS misconfiguration during the first hour.
- Optional: create email aliases with Cloudflare Email Routing
[email protected] that forward to your real mailbox, you can use Cloudflare Email Routing.
- In the Cloudflare dashboard, open Email Routing and enable it.
- Review the records Cloudflare wants to add (it will add the required
MXandTXTrecords to your DNS zone). - Create a Custom address (for example
[email protected]). - Add your Destination address (the mailbox you want to forward to), then verify the destination email Cloudflare sends for.
- Activate and test by sending an email to your new alias.
- When Email Routing is enabled, no other email services can be active for the domain. Cloudflare will prompt you to delete existing
MXrecords if they conflict. - Email Routing forwarding supports a single destination email per custom address. If you need multiple destinations, create a Workers redirect (Cloudflare describes this flow in their Email Routing docs).
⚠️ Watch out: MX/mail records must stay correct. This overlaps with the anti-pattern below: keep mail-related DNS records unproxied.
-
Verify in project workflow
Run the normal project build checks after domain/env updates.
What not to do
❌ Never useFlexibleSSL in production. It can create redirect loops and weak origin security. ❌ Never proxy mail records (MX, most mail-relatedTXT/CNAME) through Cloudflare CDN. ❌ Never enable Email Routing while the domain still has competingMXrecords from another email provider. ❌ Never cache authenticated or mutation API routes such as GraphQL POST operations. ❌ Never change DNS and SSL settings during an active incident without a rollback owner.
File conventions
Infrastructure docs for deployment providers live inapps/documentation/deployment/ and use lowercase provider filenames like cloudflare.mdx, railway.mdx, and fly.mdx (if added later).
For domain or DNS docs updates:
- put provider-specific operational guidance in
apps/documentation/deployment/cloudflare.mdx - keep quality/process guidance in
apps/documentation/quality/documentation.mdx - add or update navigation entries in
apps/documentation/docs.json
What’s next?
- Railway for origin deployment configuration behind Cloudflare.
- Configuration for
APP_URL,PORT, and production env setup. - Documentation for style and publishing rules.
