Vercel Deployment
Reportr is optimized for deployment on Vercel with special configurations for serverless functions, cron jobs, and performance optimization.Prerequisites
- Vercel account (free or paid)
- PostgreSQL database (Vercel Postgres, Neon, Supabase, or other provider)
- GitHub/GitLab/Bitbucket repository with Reportr source code
Quick Deploy
1. Import Project
- Go to vercel.com/new
- Import your Git repository
- Select the repository containing Reportr
2. Configure Environment Variables
Add all required environment variables in the Vercel dashboard under Settings → Environment Variables. See the Environment Variables page for the complete list.3. Deploy
Vercel will automatically:- Install dependencies (
npm install) - Run Prisma client generation (
npm run postinstall) - Build the Next.js application (
npm run build) - Deploy to production
Vercel Configuration
vercel.json
Thevercel.json file in the repository root configures Vercel-specific settings:
Function Configuration
PDF Generation Function (app/api/generate-pdf/route.ts)
- maxDuration: 60 seconds
- Reason: PDF generation can take up to 30-60 seconds for comprehensive reports with AI insights
- Note: Requires Vercel Pro plan for functions longer than 10 seconds
Cron Jobs
Reportr uses Vercel Cron Jobs for automated tasks:Process Cancellations
Process Cancellations
Path:
/api/cron/process-cancellationsSchedule: 0 2 * * * (Daily at 2:00 AM UTC)Purpose: Processes subscription cancellations and updates user access based on billing cycle end datesSecurity: Requires CRON_SECRET environment variableProcess Email Sequences
Process Email Sequences
Path:
/api/cron/process-email-sequencesSchedule: 0 9 * * * (Daily at 9:00 AM UTC)Purpose: Sends scheduled onboarding and trial reminder emails to usersSecurity: Requires CRON_SECRET environment variableVercel Cron Jobs are only available on Pro and Enterprise plans. For Hobby plans, consider using external cron services like cron-job.org or EasyCron.
Securing Cron Endpoints
Cron endpoints validate requests using a shared secret:CRON_SECRET in your environment variables.
Next.js Configuration
next.config.js
Key settings optimized for Vercel deployment:Build Configuration
Build Command
npm install- Install dependenciesprisma generate- Generate Prisma client (via postinstall hook)next build- Build Next.js application
Output Configuration
Vercel automatically detects Next.js and configures:- Framework: Next.js
- Build Command:
npm run buildornext build - Output Directory:
.next - Install Command:
npm install
Database Setup
Vercel does not include a database by default. Choose a PostgreSQL provider:Recommended Providers
Vercel Postgres
Integrated PostgreSQL with automatic connection pooling
Neon
Serverless PostgreSQL with autoscaling and branching
Supabase
PostgreSQL with real-time features and generous free tier
Railway
Simple PostgreSQL hosting with automatic backups
Database Environment Variables
Set these in Vercel:Use
PRISMA_DATABASE_URL with connection pooling (pgbouncer) for better performance in serverless environments.Performance Optimization
Edge Runtime (Optional)
For maximum performance, consider moving API routes to Edge Runtime:Image Optimization
Vercel automatically optimizes images using Next.js Image Optimization:Caching Strategy
Implement ISR (Incremental Static Regeneration) for reports list:Monitoring & Analytics
Vercel Analytics
Enable in the Vercel dashboard:- Go to Settings → Analytics
- Enable Web Analytics
- Enable Speed Insights (recommended)
Error Tracking
Vercel provides automatic error tracking:- Runtime Logs: View in Deployments → Functions
- Build Logs: View in Deployments → Build Logs
Third-Party Monitoring
Consider integrating:- Sentry - Error tracking and performance monitoring
- LogRocket - Session replay and debugging
- PostHog - Product analytics and feature flags
Deployment Workflow
Automatic Deployments
Vercel automatically deploys:- Production: Commits to
mainormasterbranch - Preview: Pull requests and other branches
Preview Deployments
Every pull request gets a unique preview URL:- Testing features before merging
- Sharing work with stakeholders
- Running E2E tests
Custom Domains
- Go to Settings → Domains
- Add your custom domain
- Configure DNS records as instructed
- Vercel automatically provisions SSL certificates
Environment-Specific Variables
Set different values for production and preview:Troubleshooting
Build Failures
Prisma generation fails
Prisma generation fails
Solution: Ensure
DATABASE_URL is set in environment variables and accessible during build.Add to package.json:TypeScript errors
TypeScript errors
Solution: Run
npm run build locally first to catch type errors before deploying.Environment variables not found
Environment variables not found
Solution: Ensure all required variables are set in Vercel dashboard and redeploy.Check with:
Runtime Errors
Database connection timeout
Database connection timeout
Solution: Use connection pooling with
PRISMA_DATABASE_URL.Function timeout
Function timeout
Solution: Increase
maxDuration in vercel.json for slow endpoints.Requires Vercel Pro plan for > 10 seconds.API rate limits
API rate limits
Solution: Implement caching and rate limiting in your API routes.Use Vercel Edge Config or Upstash Redis for distributed rate limiting.
Security Best Practices
Use environment variables for secrets
Never commit secrets to Git. Use Vercel environment variables for:
- API keys
- Database credentials
- OAuth secrets
Enable Vercel Authentication
Protect preview deployments:
- Go to Settings → Deployment Protection
- Enable Vercel Authentication
Cost Optimization
Vercel Pricing
- Hobby: Free (100GB bandwidth, 100 hours function execution)
- Pro: $20/month (1TB bandwidth, 1000 hours function execution)
- Enterprise: Custom pricing
Reducing Costs
- Optimize function execution time - Faster functions cost less
- Use ISR for static content - Reduce serverless function calls
- Implement caching - Reduce API calls and database queries
- Compress responses - Reduce bandwidth usage (enabled by default)
Next Steps
Database Setup
Configure PostgreSQL and run migrations
Environment Variables
Set all required production variables