Production setup
Learn how to prepare and deploy your application to production using Vercel.
This guide outlines the steps needed to prepare and deploy your application to production using Vercel.
Pre-deployment Checklist
Complete this checklist before deploying to ensure a smooth production launch.
Essential Steps
- Dependencies: Ensure all dependencies are properly listed in
package.json
- Build Testing: Test the production build locally
- Environment Variables: Set up required environment variables
- Database Access: Configure proper database access and connection strings
- Authentication: Test authentication flows with production settings
- API Endpoints: Verify all API endpoints work correctly
- Error Handling: Check error boundaries and fallbacks
- Performance: Verify bundle sizes and load times
Local Build Testing
Before deploying, it's crucial to test your production build locally to catch any potential issues:
Build Commands
Choose the appropriate command based on your package manager:
If the build fails locally, it will also fail during deployment. Always fix local build issues before deploying.
Common Local Build Issues
- Missing dependencies in
package.json
- Incorrect import paths (case sensitivity)
- Missing environment variables
- Type errors that only appear in production builds
- Browser API usage in server components
Vercel Deployment
Fast & Simple
Vercel offers the simplest deployment experience for Next.js applications
CI/CD Integration
Automatic deployments on git push with preview environments
Edge Network
Global CDN with edge caching for optimal performance
Monitoring
Deployment Process
-
Create Vercel Account
- Sign up for a free account at vercel.com
-
Connect Repository
- Link your GitHub, GitLab, or Bitbucket repository to Vercel
- Grant necessary permissions for repository access
-
Configure Project
- Set up build settings
- Configure environment variables
- Set custom domains (if needed)
-
Deploy
- Trigger deployment manually or via git push
- Monitor the build logs for any issues
Automatic Deployments
Vercel automatically deploys your application when you push to your default branch. It also creates preview deployments for pull requests.
Preview deployments are perfect for testing changes before merging to your main branch. Each PR gets its own unique URL for isolated testing.
Environment Variables
Never commit sensitive environment variables to your repository. Always use the Vercel dashboard or CLI to set production environment variables.
Configuration Process
- Navigate to your project in the Vercel dashboard
- Go to the "Settings" tab
- Select "Environment Variables"
- Add each required variable with its production value
- Specify which environments (production, preview, development) should use each variable
Required Variables
Essential environment variables for production:
Environment Separation
You can configure different environment variables for:
- Production: Your live application
- Preview: Deployment previews from pull requests
- Development: Local development environment
Post-deployment Checks
After deploying, verify that your application works correctly in production:
Functionality Testing
Authentication
Test sign-up, login, password reset, and session management
API Endpoints
Verify all API routes return expected responses
Database
File Uploads
Test file upload functionality with production S3 bucket
Email Sending
Verify transactional emails are delivered correctly
Performance Monitoring
Use Vercel Analytics to monitor your application's performance and identify areas for improvement.
Key metrics to check:
- Page Load Times: Check initial and subsequent page loads
- API Response Times: Verify API endpoints respond quickly
- Error Rates: Monitor for unexpected errors
- Core Web Vitals: Check LCP, FID, and CLS scores
- Memory Usage: Watch for memory leaks and high usage
Troubleshooting
If you encounter issues during or after deployment:
Common Deployment Issues
-
Build Failures
- Check build logs for specific errors
- Verify all dependencies are correctly installed
- Check for environment variables that might be missing
-
Runtime Errors
- Check browser console for client-side errors
- Review server logs for server-side issues
- Verify environment variables are correctly set and accessible
-
Database Connection Issues
- Ensure database credentials are correct
- Check network access rules and IP allowlists
- Verify connection string format
-
Authentication Problems
- Confirm authentication environment variables are set correctly
- Check for domain mismatches in callback URLs
- Verify cookie settings for secure environments
Vercel Logs
Access detailed logs from the Vercel dashboard:
- Navigate to your project
- Go to the "Deployments" tab
- Select the specific deployment
- Click "View Functions Logs" or "Build Logs"
Custom Domains
To use a custom domain with your Vercel deployment:
- Navigate to your project in the Vercel dashboard
- Go to the "Domains" tab
- Add your domain
- Follow the instructions to configure DNS settings
- Verify domain ownership
Vercel automatically provisions and renews SSL certificates for your custom domains.
Production Best Practices
Caching Strategy
Implement proper caching headers for static assets
Error Monitoring
Set up error tracking with Sentry or similar tools
Database Backups
Rate Limiting
Security Headers
Security Considerations
- Enable CORS: Configure proper CORS settings for API routes
- Content Security Policy: Set up CSP headers
- API Rate Limiting: Prevent abuse with rate limiting
- Input Validation: Validate all user input server-side
- Authentication Timeouts: Set reasonable session timeouts
Continuous Integration
For a robust CI/CD pipeline:
- GitHub Actions: Set up tests to run on pull requests
- Automated Testing: Configure unit and integration tests
- Linting: Enforce code quality standards
- Type Checking: Verify TypeScript types during CI
- Branch Protection: Require passing checks before merging
Example GitHub Action workflow:
Additional Resources
Explore these resources for more information on optimizing your production deployment.