Vercel deployment (recommended)
Vercel is the easiest and most optimized platform for Next.js applications.Initial setup
- Create a Vercel account at vercel.com
- Install Vercel CLI (optional):
Deploy from Git
Connect repository
- Go to vercel.com/new
- Click Import Git Repository
- Select your Contafy repository
- Click Import
Configure project
Vercel will auto-detect Next.js settings:- Framework Preset: Next.js
- Build Command:
pnpm build - Output Directory:
.next - Install Command:
pnpm install - Development Command:
pnpm dev
Set environment variables
Add your production environment variables: Required variables:Deploy
- Click Deploy
- Wait for build to complete (2-5 minutes)
- Your site is live at
https://your-project.vercel.app
Automatic deployments
Vercel automatically deploys:- Production: Deploys from
mainbranch - Preview: Deploys from pull requests and other branches
- Push to
main→ Production deployment - Create pull request → Preview deployment
- Each commit → Updated preview
Custom domain
- Go to your project settings
- Navigate to Domains
- Add your custom domain (e.g.,
contafy.com) - Configure DNS records:
- Wait for DNS propagation (5 minutes - 48 hours)
Deploy from CLI
Alternatively, deploy using Vercel CLI:Environment variable management
Production vs Preview vs Development
Vercel supports environment-specific variables:| Environment | When used |
|---|---|
| Production | main branch deploys |
| Preview | Pull request and branch deploys |
| Development | Local development |
Updating environment variables
- Go to project Settings → Environment Variables
- Add or edit variables
- Important: Redeploy for changes to take effect
Sensitive variables
Never commit sensitive data:- API keys
- Database credentials
- Auth secrets
- Firebase config
Build process
Local build test
Test production build locally:Build output
Next.js generates:Build optimization
Next.js automatically:- Code splits: Each route is a separate bundle
- Tree shakes: Removes unused code
- Minifies: Compresses JavaScript and CSS
- Optimizes images: Converts to WebP/AVIF
- Static generates: Pre-renders static pages
Build errors
Common build errors and fixes:TypeScript errors
ESLint errors
Missing environment variables
Ensure all requiredNEXT_PUBLIC_* variables are set in Vercel.
Alternative deployment options
While Vercel is recommended, Contafy can be deployed to other platforms.Netlify
Setup:- Connect repository to Netlify
- Configure build settings:
- Build command:
pnpm build - Publish directory:
.next - Install command:
pnpm install
- Build command:
- Add environment variables
- Deploy
Railway
Setup:- Connect repository to Railway
- Railway auto-detects Next.js
- Add environment variables
- Deploy
railway.toml):
DigitalOcean App Platform
Setup:- Create new app in DigitalOcean
- Connect repository
- Configure app:
- Build Command:
pnpm build - Run Command:
pnpm start
- Build Command:
- Add environment variables
- Deploy
AWS Amplify
Setup:- Connect repository to AWS Amplify
- Configure build settings:
- Add environment variables
- Deploy
Docker deployment
For containerized deployments: Dockerfile:Performance optimization
CDN and edge caching
Vercel automatically provides:- Global CDN: Content served from nearest edge location
- Edge caching: Static assets cached globally
- Automatic HTTPS: Free SSL certificates
Image optimization
Next.js Image component automatically:- Serves WebP/AVIF formats
- Generates responsive images
- Lazy loads images
- Optimizes on-demand
Bundle analysis
Analyze bundle size:http://localhost:8888 to view bundle analysis.
Monitoring and analytics
Vercel Analytics
Enable Vercel Analytics:- Go to project settings
- Navigate to Analytics
- Enable Web Analytics
- Page views
- Performance metrics
- User sessions
Error tracking
Consider integrating:- Sentry: Error tracking and monitoring
- LogRocket: Session replay and debugging
- Datadog: Full-stack observability
Rollback and versioning
Rollback deployment
In Vercel:- Go to Deployments
- Find previous successful deployment
- Click ⋯ → Promote to Production
Deployment history
Vercel keeps all deployments:- View past deployments
- Access preview URLs
- Compare builds
- Instant rollback
Security considerations
HTTPS
Always use HTTPS in production:- Vercel provides automatic HTTPS
- Use
https://in all URLs - Enable HSTS headers
Environment variables
Never expose sensitive data:NEXT_PUBLIC_* variables are exposed to the browser.
Security headers
Add security headers innext.config.ts:
Troubleshooting
Build fails
- Check build logs in Vercel dashboard
- Run build locally:
pnpm build - Fix errors and push changes
Environment variables not working
- Verify variables are set in Vercel
- Check variable names (especially
NEXT_PUBLIC_prefix) - Redeploy after changing variables
API requests failing
- Verify
NEXT_PUBLIC_API_URLis correct - Check backend CORS configuration
- Verify backend is accessible from Vercel IPs
404 errors
- Check Next.js routing configuration
- Verify
next.config.tsrewrites - Check file names (must be
page.tsx)
Deployment checklist
Before deploying to production:- All TypeScript errors fixed (
pnpm typecheck) - All ESLint errors fixed (
pnpm lint) - Production build succeeds (
pnpm build) - Environment variables configured
- Backend API accessible
- Database migrations run
- Custom domain configured
- HTTPS enabled
- Security headers configured
- Analytics enabled
- Error tracking configured