Overview
DevAurva is a full-stack application built with React (Vite) for the frontend and serverless Node.js functions for the backend API. This guide covers the complete production deployment process.Architecture
The application consists of:- Frontend: React SPA built with Vite
- Backend: Serverless API functions (
/apiroutes) - Database: MongoDB for data persistence
- Email Service: Nodemailer with Gmail SMTP
Pre-Deployment Checklist
Before deploying to production, ensure you have:Environment Variables
Prepare all required environment variables:
MONGODB_URI- MongoDB connection stringEMAIL_USER- Gmail account for sending emailsEMAIL_PASS- Gmail app-specific passwordEMAIL_RECIPIENT- Email address to receive form submissions
Database Setup
Set up your production MongoDB database:
- Create a MongoDB Atlas cluster or use your preferred MongoDB hosting
- Whitelist your deployment platform’s IP addresses
- Create a database user with appropriate permissions
- Test the connection string
Email Configuration
Configure Gmail for sending emails:
- Enable 2-factor authentication on your Gmail account
- Generate an app-specific password
- Test email sending in development environment
Build Process
Frontend Build
The frontend is built using Vite:- Compiles React components
- Bundles JavaScript and CSS
- Optimizes assets for production
- Outputs to the
dist/directory
Build Configuration
The Vite configuration (vite.config.js) includes:
The build output directory is
dist/ with assets in the assets/ subdirectory. Ensure your hosting platform serves static files from the correct directory.Environment Variables Setup
Required Variables
Configure these environment variables in your production environment:| Variable | Description | Example |
|---|---|---|
MONGODB_URI | MongoDB connection string | mongodb+srv://user:[email protected]/devaurva |
EMAIL_USER | Gmail account for SMTP | [email protected] |
EMAIL_PASS | Gmail app password | xxxx xxxx xxxx xxxx |
EMAIL_RECIPIENT | Email to receive notifications | [email protected] |
Setting Environment Variables
The method depends on your hosting platform: Vercel:- Navigate to your project settings
- Find Environment Variables section
- Add each variable with its value
- Save and redeploy if necessary
CORS Configuration
Production CORS Setup
All API endpoints include CORS headers for cross-origin requests:API Endpoints
The application includes three serverless API endpoints:Contact Form API
Endpoint:/api/contact.js
- Handles contact form submissions
- Sends email notifications via Nodemailer
- No database persistence
Custom Plan API
Endpoint:/api/custom-plan.js
- Saves custom plan requests to MongoDB
- Sends email notifications
- Includes error recovery for partial failures
Card Plan API
Endpoint:/api/card-plan.js
- Processes pricing card selections
- Saves to MongoDB
- Sends confirmation emails
All API endpoints handle OPTIONS requests for CORS preflight and return appropriate error messages for unsupported HTTP methods.
Deployment Steps
Configure Environment Variables
Set all required environment variables in your hosting platform’s dashboard or CLI.
Deploy Frontend and Backend
Deploy both the static frontend and serverless API functions. The method varies by platform (see platform-specific guides).
Test Deployment
After deployment:
- Visit your production URL
- Test form submissions
- Verify emails are received
- Check browser console for errors
- Test API endpoints directly
Post-Deployment Verification
Frontend Checks
- Website loads without errors
- All pages are accessible
- Assets (images, fonts) load correctly
- Routing works for all pages
- Mobile responsiveness is maintained
Backend Checks
- API endpoints respond correctly
- Contact form submissions work
- Custom plan submissions are saved to database
- Email notifications are delivered
- Error messages are appropriate and user-friendly
Database Checks
- MongoDB connection is stable
- Data is being saved correctly
- Connection pool is configured appropriately
- Database credentials are secure
Troubleshooting
Build Failures
Issue:npm run build fails
Solutions:
- Run
npm installto ensure all dependencies are installed - Check Node.js version (requires Node 16+)
- Review build errors for missing imports or syntax errors
API Errors
Issue: API endpoints return 500 errors Solutions:- Verify environment variables are set correctly
- Check serverless function logs for detailed errors
- Ensure MongoDB connection string is valid
- Verify Gmail credentials and app password
CORS Errors
Issue: Browser console shows CORS errors Solutions:- Verify CORS headers are set in API functions
- Check that OPTIONS requests are handled
- Ensure your domain is allowed in CORS configuration
Email Not Sending
Issue: Emails are not being delivered Solutions:- Verify Gmail app password is correct
- Check Gmail account has 2FA enabled
- Review serverless function logs for email errors
- Test with a different email service if needed
Performance Optimization
Frontend
- Enable compression on your hosting platform
- Use CDN for static assets
- Implement caching headers
- Optimize images before deployment
Backend
- Reuse MongoDB connections across function invocations
- Implement connection pooling
- Set appropriate function timeout limits
- Monitor cold start times
Database
- Create indexes on frequently queried fields
- Monitor connection count
- Use MongoDB Atlas performance advisor
- Set up automated backups
Security Best Practices
Continuous Deployment
For automated deployments:- Connect Git Repository: Link your GitHub/GitLab repository to your hosting platform
- Configure Build Settings: Set build command to
npm run build - Set Environment Variables: Add all required variables
- Enable Auto-Deploy: Configure automatic deployments on push to main branch
Most platforms support preview deployments for pull requests, allowing you to test changes before merging to production.
Next Steps
- Vercel Deployment Guide - Step-by-step Vercel deployment
- Set up custom domain
- Configure SSL certificate
- Implement monitoring and analytics
- Set up automated backups