This guide covers deploying the Design Pattern Visualizer to Cloudflare Pages, a platform perfect for static sites with excellent performance and DDoS protection.
✅ Perfect for Static Sites
- Next.js static export support
- Global CDN with 200+ data centers
- Automatic HTTPS and SSL certificates
- Built-in DDoS protection
✅ Performance
- Edge caching worldwide
- HTTP/3 support
- Image optimization
- Instant cache purging
✅ Developer Experience
- Git integration (GitHub, GitLab)
- Automatic deployments on push
- Preview deployments for PRs
- Rollback to any previous deployment
✅ Cost
- Free tier: Unlimited requests, 500 builds/month
- No bandwidth limits
- No additional costs for traffic spikes
-
Cloudflare Account
- Sign up at https://dash.cloudflare.com/sign-up
- Free tier is sufficient
-
GitHub Account
- Repository pushed to GitHub
- Admin access to the repository
-
Local Setup
- Node.js 18+ installed
- Project building successfully locally
The project is already configured for static export in next.config.ts:
export default {
output: "export",
images: {
unoptimized: true,
},
};Test the static build locally:
npm run buildThis creates an out directory with static files.
If not already done:
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/yourusername/design-pattern-visualizer.git
git push -u origin main-
Log in to Cloudflare Dashboard
-
Navigate to Pages
- Click "Workers & Pages" in the sidebar
- Click "Create application"
- Choose "Pages"
- Click "Connect to Git"
-
Authorize GitHub
- Select your GitHub account
- Grant access to the repository
- Select the
design-pattern-visualizerrepository
Use these exact settings:
Production branch: main
Build command: npm run build
Build output directory: out
Root directory: /
Environment variables: (none required)Build Configuration Details:
- Framework preset: Next.js (Static HTML Export)
- Build command:
npm run build - Build output directory:
out - Node.js version: 18.x (default)
-
Click "Save and Deploy"
-
Cloudflare Pages will:
- Clone your repository
- Install dependencies (
npm install) - Run build command (
npm run build) - Deploy the
outdirectory - Assign a
*.pages.devURL
-
Wait for deployment (usually 2-5 minutes)
After deployment completes:
- Production URL:
https://design-pattern-visualizer.pages.dev - Custom Domain: Can be configured in Pages settings
If your domain is already on Cloudflare:
- Go to your Pages project
- Click "Custom domains"
- Click "Set up a custom domain"
- Enter your domain (e.g.,
patterns.yourdomain.com) - Click "Activate domain"
- Cloudflare automatically configures DNS
If your domain is elsewhere:
- Add custom domain in Pages settings
- Cloudflare provides CNAME record
- Add CNAME to your DNS provider:
CNAME patterns design-pattern-visualizer.pages.dev - Wait for DNS propagation (up to 48 hours)
Cloudflare Pages automatically deploys:
✅ Production Deployments
- Triggered by pushes to
mainbranch - URL:
design-pattern-visualizer.pages.dev - Also deploys to custom domain if configured
✅ Preview Deployments
- Triggered by PRs and other branches
- Unique URL for each deployment
- Perfect for testing before merging
To trigger a manual deployment:
- Go to Cloudflare Dashboard > Pages
- Select your project
- Click "Create deployment"
- Choose branch or upload files
This project doesn't require environment variables, but if needed:
- Go to Pages project settings
- Click "Environment variables"
- Add variables for:
- Production: Used for
mainbranch - Preview: Used for preview deployments
- Production: Used for
Create .node-version file for specific Node version:
18.17.0
Cloudflare Pages caches:
node_modules.next/cache- Build outputs
To clear cache:
- Go to project settings
- Click "Clear build cache"
- Trigger new deployment
Cloudflare automatically caches:
- Static assets (JS, CSS, images)
- HTML pages
- API responses (if applicable)
Cache Headers (already configured in next.config.ts):
headers: [
{
key: "Cache-Control",
value: "public, max-age=31536000, immutable",
},
];✅ Implemented:
- Static HTML generation
- Optimized bundle size
- Code splitting
- Font optimization
- Security headers
✅ Cloudflare Provides:
- Global CDN distribution
- HTTP/3 and QUIC support
- Brotli compression
- Early Hints
- Edge caching
Access via Dashboard:
- Go to your Pages project
- Click "Analytics" tab
Available Metrics:
- Total requests
- Bandwidth usage
- Cache hit ratio
- Response time
- Geographic distribution
Enable Cloudflare Web Analytics:
- Go to Analytics > Web Analytics
- Add site
- Copy tracking code
- Add to
app/layout.tsx(optional)
- Go to Pages project
- Click "Deployments" tab
- Find previous successful deployment
- Click "•••" menu
- Select "Rollback to this deployment"
- View all deployments
- See build logs
- Check deployment status
- Compare versions
Issue: Build fails with "Module not found"
Solution: Ensure all dependencies in package.json
Run locally: npm install && npm run buildIssue: Out of memory during build
Solution: Increase Node memory
Add to package.json: "build": "NODE_OPTIONS='--max_old_space_size=4096' next build"Issue: Build timeout
Solution: Optimize build process
- Remove unnecessary dependencies
- Use build cache
- Contact Cloudflare support for limit increaseIssue: 404 on all pages except home
Solution: Check output directory is "out" not ".next"
Verify next.config.ts has output: "export"Issue: Assets not loading
Solution: Check basePath configuration
Ensure all assets use relative pathsIssue: Preview deployments not working
Solution: Check branch permissions
Ensure GitHub integration is active
Verify build settingsIssue: Slow initial load
Solution:
- Check bundle size (should be < 300KB)
- Enable compression
- Use code splitting
- Check Cloudflare cache settingsIssue: High cache miss rate
Solution:
- Review cache headers
- Check Cloudflare cache rules
- Enable Cloudflare Argo (premium)Already configured in next.config.ts:
- Content Security Policy (CSP)
- X-Frame-Options
- X-Content-Type-Options
- Referrer-Policy
- Permissions-Policy
Enable in Cloudflare Dashboard:
-
Firewall Rules
- Block malicious IPs
- Rate limiting
- Geographic restrictions
-
Bot Management (Pro plan)
- Block bad bots
- Verify human users
- Challenge suspicious traffic
-
DDoS Protection (Automatic)
- Always on
- No configuration needed
- Handles large attacks
✅ Included:
- Unlimited requests
- Unlimited bandwidth
- 500 builds per month
- 1 concurrent build
- 100 custom domains per project
💰 Limits:
- Max 20,000 files per deployment
- Max 25 MB per file
- 20 MB max upload size
Consider paid plans for:
- More than 500 builds/month
- Multiple concurrent builds
- Advanced analytics
- Priority support
Create .github/workflows/deploy.yml:
name: Deploy to Cloudflare Pages
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
cache: "npm"
- run: npm ci
- run: npm run build
- run: npm test
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: design-pattern-visualizer
directory: out
gitHubToken: ${{ secrets.GITHUB_TOKEN }}- ✅ Test build locally:
npm run build - ✅ Run tests:
npm test - ✅ Check bundle size
- ✅ Test in multiple browsers
- ✅ Verify security headers
- ✅ Review dependencies
- ✅ Test production URL
- ✅ Verify all pages load
- ✅ Check console for errors
- ✅ Test theme toggle
- ✅ Test code playground
- ✅ Verify mobile responsiveness
- ✅ Check performance metrics
- 🔄 Update dependencies monthly
- 🔄 Review analytics weekly
- 🔄 Monitor error rates
- 🔄 Check security advisories
- 🔄 Optimize based on metrics
- Documentation: https://developers.cloudflare.com/pages/
- Community: https://community.cloudflare.com/
- Status: https://www.cloudflarestatus.com/
- Support: https://dash.cloudflare.com/?to=/:account/support
- Documentation: https://nextjs.org/docs/app/building-your-application/deploying/static-exports
- GitHub: https://github.com/vercel/next.js/
- Code pushed to GitHub
- Local build successful
- Tests passing
- Security review complete
- README updated
- Cloudflare account created
- Repository connected
- Build settings configured
- First deployment successful
- Production URL accessible
- Custom domain configured (optional)
- Analytics enabled
- Performance verified
- Security headers checked
- Mobile testing complete
- Documentation updated
- Deploy the site following this guide
- Test thoroughly in production
- Configure custom domain (optional)
- Enable analytics for monitoring
- Set up alerts for downtime
- Plan maintenance schedule
Last Updated: January 17, 2026
Questions? Open an issue on GitHub or contact the maintainers.