Skip to main content

Deploy with Vercel

Recommended for: Fastest deployment, zero server management


Architecture​

┌─────────────────────────────────────────────────────────────┐
│ Vercel Edge │
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ Edge Network │ │ Serverless Fns │ │
│ │ (CDN + SSL) │ │ (API Routes) │ │
│ └────────┬─────────┘ └────────┬─────────┘ │
│ │ │ │
│ └───────────┬───────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────┐ │
│ │ Next.js App │ │
│ │ (Auto-deployed) │ │
│ └──────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│ │
▼ ▼
┌─────────────┐ ┌─────────────┐
│ PostgreSQL │ │ Redis │
│ (Neon) │ │ (Upstash) │
└─────────────┘ └─────────────┘

Prerequisites​

  • GitHub/GitLab/Bitbucket account
  • Vercel account (free tier available)
  • Repository with your Next.js project

Step-by-Step Deployment​

1. Connect Repository​

  1. Go to vercel.com and sign in
  2. Click "Add New Project"
  3. Import your Git repository
  4. Select the repository containing Mountify

2. Configure Project​

Framework Preset: Next.js (auto-detected)

Build Settings:

Build Command: npm run build
Output Directory: .next
Install Command: npm ci

3. Environment Variables​

Add all environment variables in Vercel dashboard:

VariableValue
DATABASE_URLpostgresql://...
AUTH_SECRETyour-secret-key
NEXTAUTH_URLhttps://your-project.vercel.app
STRIPE_SECRET_KEYsk_live_...
STRIPE_WEBHOOK_SECRETwhsec_...
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEYpk_live_...
UPSTASH_REDIS_REST_URLhttps://...
UPSTASH_REDIS_REST_TOKEN...
GOOGLE_CLIENT_ID...
GOOGLE_CLIENT_SECRET...
RESEND_API_KEYre_...
CLOUDINARY_CLOUD_NAME...
CLOUDINARY_API_KEY...
CLOUDINARY_API_SECRET...

Tip: Use "Add from .env" button to paste your entire .env.production file

4. Deploy​

Click "Deploy" and wait for build to complete.

Your app is now live at: https://your-project.vercel.app


Custom Domain​

1. Add Domain in Vercel​

  1. Go to Project Settings → Domains
  2. Add your domain: yourdomain.com
  3. Vercel will show DNS records to configure

2. Configure DNS​

Add these records at your domain registrar:

TypeNameValue
A@76.76.21.21
CNAMEwwwcname.vercel-dns.com

3. Update Environment Variable​

Update NEXTAUTH_URL to your custom domain:

NEXTAUTH_URL=https://yourdomain.com

4. Update OAuth Redirect URIs​

In Google Cloud Console, add:

  • https://yourdomain.com/api/auth/callback/google

5. Update Stripe Webhook​

In Stripe Dashboard, update webhook endpoint:

  • https://yourdomain.com/api/webhooks/stripe

Vercel Configuration​

vercel.json (Optional)​

{
"framework": "nextjs",
"regions": ["sfo1"],
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
}
]
}
],
"redirects": [
{
"source": "/home",
"destination": "/",
"permanent": true
}
]
}

next.config.js​

/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
{
protocol: "https",
hostname: "res.cloudinary.com",
},
],
},
// Optional: Reduce cold start time
experimental: {
serverComponentsExternalPackages: ["pg"],
},
};

module.exports = nextConfig;

Automatic Deployments​

Vercel automatically deploys:

TriggerEnvironment
Push to mainProduction
Push to other branchesPreview
Pull RequestPreview

Preview Deployments​

Every PR gets a unique preview URL:

https://mountify-git-feature-branch-username.vercel.app

Environment Variables per Branch​

Set different variables for different environments:

VariableProductionPreviewDevelopment
NEXTAUTH_URLhttps://yourdomain.comhttps://preview.vercel.apphttp://localhost:3000
STRIPE_SECRET_KEYsk_live_...sk_test_...sk_test_...

Vercel CLI (Optional)​

Installation​

npm i -g vercel

Commands​

# Login
vercel login

# Deploy preview
vercel

# Deploy production
vercel --prod

# Pull environment variables to local
vercel env pull .env.local

# View logs
vercel logs your-project.vercel.app

Monitoring​

Built-in Analytics​

Enable in Project Settings → Analytics

Tracks:

  • Web Vitals (LCP, FID, CLS)
  • Page views
  • Unique visitors

Logs​

View real-time logs:

  1. Go to Project → Deployments
  2. Click on deployment
  3. View "Functions" tab for API logs

Serverless Function Limits​

ResourceHobby (Free)Pro
Execution timeout10s60s
Memory1024 MB3008 MB
Deployments/day100Unlimited
Bandwidth100 GB1 TB

Handling Long Operations​

For operations exceeding timeout:

// Use streaming for long responses
export async function GET() {
const encoder = new TextEncoder();
const stream = new ReadableStream({
async start(controller) {
// Process in chunks
for (const chunk of data) {
controller.enqueue(encoder.encode(JSON.stringify(chunk)));
}
controller.close();
},
});

return new Response(stream);
}

Troubleshooting​

Build Failures​

# Check build logs in Vercel dashboard
# Common issues:

# 1. Missing environment variables
Error: DATABASE_URL is not defined

# 2. TypeScript errors
Type error: Property 'x' does not exist

# 3. ESLint errors
npm run lint -- --fix

Function Errors​

# Check function logs
# Common issues:

# 1. Timeout (increase or optimize)
# 2. Memory exceeded
# 3. Cold start delays (use edge runtime if possible)

Database Connection Issues​

// Use connection pooling for serverless
// Neon supports this natively with ?sslmode=require
DATABASE_URL = "postgresql://...?sslmode=require&pgbouncer=true";

Pros & Cons​

ProsCons
✅ Zero configuration❌ Vendor lock-in
✅ Automatic SSL❌ Function timeout limits
✅ Global CDN❌ Cold starts
✅ Preview deployments❌ Pricing at scale
✅ Built-in analytics❌ Less control
✅ Auto-scaling❌ No persistent storage

Cost Comparison​

TierPriceBest For
HobbyFreePersonal projects
Pro$20/monthProduction apps
EnterpriseCustomLarge teams

What's Included in Free Tier​

  • Unlimited deployments
  • 100 GB bandwidth/month
  • SSL certificates
  • Preview deployments
  • Basic analytics

Vercel vs Self-Hosted​

AspectVercelSelf-Hosted (Docker/PM2)
Setup time5 minutes1-2 hours
MaintenanceNoneRegular updates
ScalingAutomaticManual
Cost (low traffic)Free~$5-10/month
Cost (high traffic)$20+/monthFixed server cost
ControlLimitedFull
Cold startsYesNo