Overview
Vercel is the recommended platform for deploying DevAurva. It provides seamless deployment for both the React frontend and serverless API functions with zero configuration.Why Vercel?
- Automatic CI/CD: Deploy on every push to your repository
- Serverless Functions: Native support for API routes
- Edge Network: Global CDN for fast content delivery
- Preview Deployments: Automatic preview URLs for pull requests
- Environment Variables: Secure management of secrets
- Zero Configuration: Works out of the box with Vite
Prerequisites
Before deploying to Vercel:- Vercel account (sign up at vercel.com)
- Git repository (GitHub, GitLab, or Bitbucket)
- MongoDB database (MongoDB Atlas recommended)
- Gmail account with app-specific password
- Vercel CLI (optional, for command-line deployment)
Vercel Configuration
DevAurva includes avercel.json configuration file:
Configuration Breakdown
Builds:- Static Build: Builds the React frontend using Vite
- Output directory:
dist/ - Build command:
npm run build
- Output directory:
- Serverless Functions: Deploys all
api/*.jsfiles as serverless functions
- API routes (
/api/*) map to serverless functions - Asset files are served directly
- All other routes fall back to
index.htmlfor client-side routing
The configuration enables Single Page Application (SPA) routing by redirecting all non-asset routes to
index.html, allowing React Router to handle navigation.Deployment Methods
Method 1: Deploy via Vercel Dashboard (Recommended)
Create Vercel Account
- Visit vercel.com
- Sign up with GitHub, GitLab, or Bitbucket
- Authorize Vercel to access your repositories
Configure Project
Vercel will automatically detect the project settings:
- Framework Preset: Vite
- Build Command:
npm run build - Output Directory:
dist - Install Command:
npm install
Add Environment Variables
Before deploying, add required environment variables:
- Click “Environment Variables”
- Add each variable:
MONGODB_URI: Your MongoDB connection stringEMAIL_USER: Gmail address for SMTPEMAIL_PASS: Gmail app-specific passwordEMAIL_RECIPIENT: Email to receive form submissions
- Select environment: Production, Preview, or Development
Deploy
- Click “Deploy”
- Wait for build to complete (usually 1-3 minutes)
- Vercel will provide a deployment URL
Method 2: Deploy via Vercel CLI
For developers who prefer command-line deployment:The first time you run
vercel, it will ask questions about project setup. You can accept the defaults, as vercel.json already contains the configuration.Method 3: Deploy via Git Integration (Automatic)
Once connected, Vercel automatically deploys:- Production: Every push to
mainbranch - Preview: Every push to other branches or pull requests
Environment Variables Management
Adding Variables via Dashboard
- Navigate to your project in Vercel
- Go to Settings → Environment Variables
- Add new variable:
- Key: Variable name (e.g.,
MONGODB_URI) - Value: Variable value
- Environment: Select Production, Preview, or Development
- Key: Variable name (e.g.,
- Click Save
Adding Variables via CLI
Required Environment Variables
| Variable | Description | Required For |
|---|---|---|
MONGODB_URI | MongoDB connection string | Custom plans, card plans |
EMAIL_USER | Gmail SMTP username | All email notifications |
EMAIL_PASS | Gmail app password | All email notifications |
EMAIL_RECIPIENT | Notification recipient | All email notifications |
Environment-Specific Variables
- Production: Used for live site (
yoursite.vercel.appor custom domain) - Preview: Used for branch and PR deployments
- Development: Used locally with
vercel dev
Set variables for all environments you plan to use. Preview environments are useful for testing with production-like settings.
Testing API Functions
Vercel provides serverless function logs for debugging:View Function Logs
- Go to your project dashboard
- Click Deployments
- Select a deployment
- Click Functions tab
- Select a function to view logs
Test API Endpoints
Local Development with Vercel
Test serverless functions locally:http://localhost:3000 with serverless functions.
vercel dev simulates the Vercel production environment locally, including serverless functions and routing.Custom Domain Setup
Configure DNS
Vercel provides DNS configuration instructions:Option A: Vercel Nameservers (Recommended)
- Update nameservers at your domain registrar
- Vercel manages all DNS records
- Add A record pointing to Vercel’s IP
- Add CNAME record for
wwwsubdomain
Automatic HTTPS
Vercel automatically provides:- SSL certificate for your domain
- Automatic HTTPS redirect
- Certificate renewal
Preview Deployments
What are Preview Deployments?
Every branch and pull request gets a unique preview URL:- Test changes before merging
- Share work with team members
- Verify features in production-like environment
Using Preview Deployments
Get Preview URL
- Vercel automatically deploys the branch
- Check GitHub PR for Vercel bot comment with preview URL
- Or view in Vercel dashboard under Deployments
Preview deployments use Preview environment variables. Ensure sensitive data is protected and test databases are used for previews.
Rollback and Redeploy
Rollback to Previous Deployment
Redeploy Current Version
Monitoring and Analytics
Built-in Analytics
Vercel provides:- Page views and unique visitors
- Top pages and referrers
- Device and browser statistics
- Geographic distribution
- Go to Analytics in project settings
- Click Enable
Function Logs
Monitor serverless functions:- Go to Deployments
- Select a deployment
- Click Functions tab
- View real-time logs and errors
Runtime Logs
View console logs from your API functions:Performance Optimization
Edge Caching
Vercel automatically caches static assets at the edge. No configuration needed.Custom Cache Headers
For API responses, add cache headers:Image Optimization
Use Vercel’s Image Optimization:Image optimization is available for Next.js projects. For Vite projects, optimize images before deployment.
Troubleshooting
Build Fails
Error: “Build failed” Solutions:- Check build logs in deployment details
- Verify
package.jsonscripts are correct - Ensure all dependencies are in
dependencies, notdevDependencies - Test build locally:
npm run build
Serverless Function Errors
Error: “Function error 500” Solutions:- Check function logs for detailed error
- Verify environment variables are set
- Test function locally with
vercel dev - Check MongoDB connection and credentials
CORS Issues
Error: “CORS policy blocked” Solutions:- Verify CORS headers in API functions
- Check that OPTIONS method is handled
- Test with curl to isolate frontend issues
- Review browser console for exact error
Environment Variables Not Working
Issue: API functions can’t access environment variables Solutions:- Verify variables are set for correct environment (Production/Preview)
- Redeploy after adding variables
- Check variable names match exactly (case-sensitive)
- Use
vercel env lsto list all variables
Database Connection Fails
Error: “MongoError: connection timeout” Solutions:- Verify MongoDB connection string is correct
- Whitelist Vercel’s IP addresses in MongoDB Atlas
- Check database user has correct permissions
- Test connection string locally
Vercel-Specific Features
Environment Variable Secrets
Sensitive variables (likeEMAIL_PASS) are automatically encrypted by Vercel and never exposed in logs.
Zero-Downtime Deployments
Vercel routes traffic to new deployment only after successful build:- Old version continues serving requests
- New version is built and tested
- Traffic switches atomically
- Zero downtime for users
Automatic Compression
Vercel automatically compresses:- HTML, CSS, JavaScript
- JSON responses
- SVG images
DDoS Protection
Vercel provides built-in DDoS protection and rate limiting at the edge.Cost Considerations
Vercel’s free (Hobby) plan includes:- Unlimited deployments
- 100GB bandwidth per month
- 100GB-hours serverless function execution
- Automatic HTTPS
- Preview deployments
- More bandwidth and function execution time
- Team collaboration features
- Advanced analytics
- Faster builds
Monitor usage in Settings → Usage to avoid unexpected charges.
Best Practices
- Use Preview Environments: Test all changes in preview before merging
- Monitor Function Logs: Regularly check for errors and warnings
- Set Up Alerts: Use Vercel integrations for Slack/Discord notifications
- Optimize Bundle Size: Keep dependencies minimal to reduce cold start time
- Use Edge Caching: Configure cache headers appropriately
- Secure Environment Variables: Never expose secrets in frontend code
- Test Locally: Use
vercel devto catch issues before deployment - Regular Backups: Back up MongoDB data regularly
Next Steps
After deploying to Vercel:- Set up custom domain
- Enable Vercel Analytics
- Configure Web Vitals monitoring
- Set up error tracking (Sentry integration)
- Add Slack/Discord notifications for deployments
- Implement automated testing in CI/CD