Deployment Guide
JCV Fitness uses a multi-component deployment strategy with Cloudflare Pages for the frontend, Cloudflare Workers for payment processing, and Supabase for the database.Prerequisites
Before deploying, ensure you have:- Node.js 20+ installed
- Git repository access
- Cloudflare account with Pages and Workers access
- Supabase project created
- MercadoPago account with API credentials
Environment Setup
1. Frontend Environment Variables
Create.env.local in project root:
- Go to Supabase Dashboard
- Select your project
- Settings > API
- Copy
URLandanon/publickey
2. Worker Secrets
Set secrets via Cloudflare Dashboard or CLI:- Go to MercadoPago Developers
- Your Applications > Your App
- Production credentials > Access Token
- Copy token (starts with
APP-)
Database Deployment
1. Create Supabase Project
2. Run Migrations
Apply schema migrations:3. Configure Row Level Security
Verify RLS is enabled:4. Set Up Cron Jobs (Optional)
Create Edge Function for subscription expiration:Frontend Deployment (Cloudflare Pages)
Initial Setup
Option A: GitHub Integration (Recommended)- Connect Repository:
- Go to Cloudflare Dashboard
- Pages > Create a project
- Connect to Git
- Select repository:
felixagl/jcv-fitness - Configure build settings:
- Configure Staging:
- Settings > Builds & deployments
- Preview deployments: Enable for
stagingbranch - Environment variables (staging):
- Use staging Supabase project URL/key
Deployment Workflow
Git Branch Strategy:- Work on staging:
-
Test on staging:
- Visit
https://staging.jcv-fitness.pages.dev - Verify changes work correctly
- Test payment flow with MercadoPago sandbox
- Visit
- Promote to production:
Custom Domain Setup
Configure jcv24fitness.com:-
Add custom domain:
- Cloudflare Pages > jcv-fitness > Custom domains
- Add domain:
jcv24fitness.com - Add domain:
www.jcv24fitness.com
- DNS Configuration (if not using Cloudflare DNS):
- SSL Certificate:
- Cloudflare automatically provisions SSL
- Verify HTTPS works:
https://jcv24fitness.com
Worker Deployment (Cloudflare Workers)
Initial Setup
Deploy Worker
Production:Verify Worker Deployment
Test health endpoint:Update Worker Code
MercadoPago Configuration
Set Notification URL
Option A: Via MercadoPago Dashboard- Go to MercadoPago Developers
- Your Applications > Your App
- Webhooks
- Add URL:
- Production:
https://mercadopago-jcv.fagal142010.workers.dev/webhook - Events:
payment.updated,payment.created
- Production:
notification_url when creating preferences:
Test Payment Flow
Staging (Sandbox):- Use test credentials in worker
- Create preference via frontend
- Use test card:
- Card:
5031 7557 3453 0604 - CVV:
123 - Expiry:
11/25
- Card:
- Verify webhook received in Supabase
webhook_logs - Verify subscription created
- Use real card with small amount
- Complete payment
- Verify subscription activated
- Check webhook logs
Monitoring & Logging
Frontend Monitoring
Cloudflare Web Analytics:- Cloudflare Dashboard > Analytics
- Enable Web Analytics
- View traffic, performance, errors
Worker Monitoring
Real-time logs:- Workers & Pages > mercadopago-jcv
- Metrics: Requests, errors, CPU time
- Logs: Recent invocations
Database Monitoring
Supabase Dashboard:- Project > Database
- Metrics: Connections, queries, storage
- Query performance
Rollback Procedures
Frontend Rollback
Cloudflare Pages:- Dashboard > Pages > jcv-fitness
- Deployments tab
- Find previous working deployment
- Click ”…” > Rollback to this deployment
Worker Rollback
Database Rollback
Restore from backup (Supabase):- Dashboard > Database > Backups
- Select backup date
- Click “Restore”
Health Checks
Automated Health Check Script
Troubleshooting
Build Fails
Error:Type error: ...
Module not found
Worker Not Receiving Webhooks
-
Check MercadoPago notification URL:
- Verify URL is correct
- Check URL is reachable:
curl https://worker-url/webhook
-
Check worker logs:
-
Test webhook manually:
Database Connection Issues
Check Supabase status: https://status.supabase.com Verify credentials:CI/CD (Future Enhancement)
GitHub Actions Workflow
Security Checklist
Before Production Deployment:- All secrets stored securely (no commits)
- RLS enabled on all Supabase tables
- CORS configured with specific origins (no wildcards)
- MercadoPago webhook URL uses HTTPS
- Service role key only in worker (not client)
- Environment variables set in Cloudflare (not in code)
- Test payment flow end-to-end
- Verify subscription activation works
- Check webhook logs for errors
Related Documentation
- System Architecture - Overall system design
- Database Schema - Database structure
- Payment Integration - Payment flow details