Cloudflare Pages Deployment
Overview
Novaqy Care Connect is deployed on Cloudflare Pages with edge workers for optimal global performance and low latency.
Prerequisites
- Cloudflare account
- Cloudflare Pages API token
- Wrangler CLI installed
Initial Setup
1. Install Wrangler
2. Authenticate
3. Create Project
Deployment Process
Build Application
This creates optimized static output in .vercel/output/static/
Deploy to Staging
Equivalent to:
Deploy to Production
Equivalent to:
Environment Variables
Configure via CLI
# Set individual secret
npx wrangler pages secret put SUPABASE_SERVICE_ROLE_KEY \
--project-name novaqy-staging
# Bulk import from .env.local
cat .env.local | grep -v "^#" | grep "=" | while IFS='=' read -r key value; do
echo "Setting $key..."
npx wrangler pages secret put "$key" \
--project-name novaqy-staging <<< "$value"
done
Required Environment Variables
Supabase (Both Regions)
NEXT_PUBLIC_SUPABASE_URL
NEXT_PUBLIC_SUPABASE_ANON_KEY
SUPABASE_SERVICE_ROLE_KEY
SUPABASE_PROJECT_ID
NEXT_PUBLIC_SUPABASE_US_URL
NEXT_PUBLIC_SUPABASE_US_ANON_KEY
SUPABASE_US_SERVICE_ROLE_KEY
SUPABASE_US_PROJECT_ID
Payment Gateway
Analytics
Integrations
NEXT_PUBLIC_SALESIQ_WIDGET_CODE
ZOHO_CLIENT_ID
ZOHO_CLIENT_SECRET
N8N_PAYMENT_WEBHOOK_URL
N8N_LEAD_WEBHOOK_URL
Custom Domains
Add Domain
Add Subdomain
Configure DNS
Add CNAME record:
Deployment Environments
Staging
- URL: https://staging.novaqy-staging.pages.dev
- Branch: staging
- Purpose: Testing before production
- Auto-deploy: On push to staging branch
Production
- URL: https://novaqy.com
- Branch: main
- Purpose: Live customer-facing site
- Auto-deploy: On push to main branch
CI/CD Integration
GitHub Actions Workflow
Create .github/workflows/deploy-staging.yml:
name: Deploy to Staging
on:
push:
branches: [staging]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Deploy to Cloudflare Pages
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
run: npm run cf:deploy:staging
Edge Functions
Compatibility Flags
Add to wrangler.toml:
name = "novaqy-production"
compatibility_flags = ["nodejs_compat"]
[build]
command = "npm run build"
[env.production]
name = "novaqy-production"
[env.staging]
name = "novaqy-staging"
Node.js Compatibility
Enable in Cloudflare Dashboard: 1. Go to Pages project 2. Settings → Functions 3. Enable "nodejs_compat" compatibility flag
Performance Optimization
Edge Caching
Configure _headers file:
/*
Cache-Control: public, max-age=31536000, immutable
/_next/static/*
Cache-Control: public, max-age=31536000, immutable
/api/*
Cache-Control: no-store, no-cache, must-revalidate
Image Optimization
Use Cloudflare Images:
Monitoring
View Deployments
View Logs
Analytics
Access via Cloudflare Dashboard: - Real-time traffic - Bandwidth usage - Request errors - Geographic distribution
Rollback Strategy
Rollback to Previous Deployment
-
List deployments:
-
Promote specific deployment:
Git-based Rollback
This triggers auto-deployment of previous working commit.
Troubleshooting
Issue: 503 Service Unavailable
Cause: Deployment still propagating Solution: Wait 2-5 minutes for global edge deployment
Issue: Environment variables not working
Cause: Not set in Cloudflare Pages Solution:
npx wrangler pages secret list --project-name novaqy-production
npx wrangler pages secret put MISSING_VAR --project-name novaqy-production
Issue: Build errors
Cause: Missing dependencies or incompatible Node version Solution:
Issue: Functions not working
Cause: Missing nodejs_compat flag Solution: Enable in Cloudflare Dashboard → Functions settings
Security Best Practices
- Use Secrets for Sensitive Data
- Never commit API keys to git
-
Use wrangler secrets management
-
Enable HTTPS Only
- Force HTTPS redirects in Cloudflare
-
Configure HSTS headers
-
Rate Limiting
- Configure Cloudflare rate limiting rules
-
Protect API endpoints
-
DDoS Protection
- Enable Cloudflare DDoS protection
- Configure firewall rules
Cost Optimization
Free Tier Limits
- 500 builds per month
- Unlimited requests
- Unlimited bandwidth
- 100 custom domains