Skip to main content
DelightBridge is designed to deploy seamlessly on Vercel with minimal configuration. This guide covers deployment, environment setup, and cron job configuration for automatic Gmail synchronization.

Prerequisites


Step 1: Import Project to Vercel

1

Connect GitHub repository

Go to vercel.com and click Add New Project.Select your DelightBridge repository from GitHub.
2

Configure project settings

Vercel auto-detects Next.js. Verify these settings:
  • Framework Preset: Next.js
  • Root Directory: ./ (leave default)
  • Build Command: pnpm build (auto-detected)
  • Output Directory: .next (auto-detected)
  • Install Command: pnpm install (auto-detected)
DelightBridge uses pnpm. Vercel automatically detects this from pnpm-lock.yaml.
3

Configure environment variables

Before deploying, add all required environment variables. Click Environment Variables section and add:
ANTHROPIC_API_KEY=sk-ant-api03-...
DATABASE_URL=postgresql://user:[email protected]/delightbridge?sslmode=require
GOOGLE_CLIENT_ID=123456789-xxx.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=GOCSPX-xxx
AUTH_SECRET=your-production-secret-min-32-chars
ADMIN_EMAILS=[email protected]
CRON_SECRET=your-production-cron-secret
CRON_SYNC_MAX_ACCOUNTS=20
Use different AUTH_SECRET and CRON_SECRET values for production than development.
Select All Environments (Production, Preview, Development) or configure separately.
4

Deploy

Click Deploy. Vercel will:
  1. Clone your repository
  2. Install dependencies with pnpm
  3. Build the Next.js app
  4. Deploy to a production URL
First deployment takes 2-3 minutes.

Step 2: Configure OAuth Redirect URIs

After deployment, update your Google Cloud Console OAuth settings with production URLs.

Add production redirect URIs

Go to Google Cloud ConsoleAPIs & ServicesCredentials → Your OAuth 2.0 Client ID. Add these Authorized redirect URIs:
https://your-project.vercel.app/api/auth/callback/google
https://your-project.vercel.app/api/services/oauth/callback
Replace your-project.vercel.app with your actual Vercel domain.
You need both redirect URIs:
  • /api/auth/callback/google - for user authentication (NextAuth)
  • /api/services/oauth/callback - for Gmail service connections
If using a custom domain, add those URLs too:
https://bridge.delightroom.com/api/auth/callback/google
https://bridge.delightroom.com/api/services/oauth/callback

Step 3: Push Database Schema

Vercel deployments need the database schema pushed separately.

Option A: Push from local machine

With production DATABASE_URL in .env.local:
pnpm db:push
Ensure you’re pushing to the production database, not development.

Option B: Use Vercel CLI

Install Vercel CLI:
npm i -g vercel
Link to your project:
vercel link
Pull environment variables:
vercel env pull .env.local
Push schema:
pnpm db:push

Step 4: Configure Cron Jobs

DelightBridge uses Vercel Cron to automatically sync Gmail messages every 5 minutes.

Cron configuration file

The repository includes vercel.json with cron configuration:
{
  "crons": [
    {
      "path": "/api/cron/sync-gmail",
      "schedule": "*/5 * * * *"
    }
  ]
}
  • path: API route to call (/api/cron/sync-gmail)
  • schedule: Cron expression (every 5 minutes)
Vercel Cron is only available on Pro and Enterprise plans. On the free Hobby plan, crons won’t run automatically.

Cron schedule format

The schedule */5 * * * * means:
┌───────────── minute (0-59)
│ ┌───────────── hour (0-23)
│ │ ┌───────────── day of month (1-31)
│ │ │ ┌───────────── month (1-12)
│ │ │ │ ┌───────────── day of week (0-6, Sunday=0)
│ │ │ │ │
* * * * *
Examples:
  • */5 * * * * - Every 5 minutes
  • */15 * * * * - Every 15 minutes
  • 0 * * * * - Every hour at minute 0
  • 0 0 * * * - Daily at midnight

Verify cron is running

After deployment:
  1. Go to Vercel dashboard → Your project → Cron Jobs tab
  2. Verify /api/cron/sync-gmail is listed
  3. Check Last Run timestamp (may take 5 minutes for first run)
  4. Click on a run to see logs and status

Manually trigger cron (testing)

You can test the cron endpoint manually:
curl -X GET https://your-project.vercel.app/api/cron/sync-gmail \
  -H "Authorization: Bearer your-cron-secret"
Replace:
  • your-project.vercel.app with your Vercel domain
  • your-cron-secret with your CRON_SECRET value
Expected response:
{
  "ok": true,
  "durationMs": 1234,
  "scannedConnectedAccounts": 3,
  "targetedAccounts": 3,
  "maxAccountsPerRun": 20,
  "succeeded": 3,
  "failed": 0,
  "skipped": 0,
  "results": [...]
}

Cron Endpoint Details

How cron sync works

Every 5 minutes, Vercel calls GET /api/cron/sync-gmail, which:
  1. Authenticates using CRON_SECRET from headers
  2. Fetches all connected Gmail accounts from database
  3. Selects up to CRON_SYNC_MAX_ACCOUNTS accounts (round-robin)
  4. Syncs each account incrementally using Gmail API History
  5. Updates last_history_id for next incremental sync
  6. Returns sync results (succeeded/failed/skipped counts)

Round-robin scheduling

If you have more Gmail accounts than CRON_SYNC_MAX_ACCOUNTS, the cron job processes them in batches: Example: 50 accounts, CRON_SYNC_MAX_ACCOUNTS=20
  • Run 1 (0:00): Accounts 1-20
  • Run 2 (0:05): Accounts 21-40
  • Run 3 (0:10): Accounts 41-50
  • Run 4 (0:15): Accounts 1-20 (cycle repeats)
This ensures all accounts sync regularly without hitting timeouts.

Security

The cron endpoint requires authentication via CRON_SECRET:
  • Vercel Cron automatically includes this in request headers
  • Manual requests must include:
    • Authorization: Bearer <CRON_SECRET>, OR
    • x-cron-secret: <CRON_SECRET>
Without valid secret, endpoint returns 401 Unauthorized.

Environment Variables in Vercel

View and edit variables

  1. Go to Vercel dashboard → Your project → SettingsEnvironment Variables
  2. Edit or add variables as needed
  3. Click Save
After changing environment variables, you must redeploy for changes to take effect.

Redeploy after variable changes

Go to Deployments tab → Click ••• on latest deployment → Redeploy. Or trigger a new deployment by pushing to your GitHub repository.

Environment-specific variables

You can set different values for:
  • Production - Live deployment
  • Preview - Pull request deployments
  • Development - Local development (via vercel env pull)

Custom Domains

Add custom domain

1

Go to Domains settings

Vercel dashboard → Your project → SettingsDomains
2

Add domain

Enter your domain (e.g., bridge.delightroom.com) and click Add.
3

Configure DNS

Vercel provides DNS instructions:
  • Subdomain (recommended): Add CNAME record pointing to cname.vercel-dns.com
  • Apex domain: Add A record pointing to Vercel’s IP
DNS changes may take up to 48 hours to propagate.
4

Update OAuth redirect URIs

Add custom domain URLs to Google Cloud Console:
https://bridge.delightroom.com/api/auth/callback/google
https://bridge.delightroom.com/api/services/oauth/callback

Deployment Checklist

Before going live:
  • All environment variables set in Vercel
  • Production database schema pushed (pnpm db:push)
  • OAuth redirect URIs updated with production domain
  • Cron jobs configured and running (Pro plan required)
  • CRON_SECRET set and matches in environment variables
  • ADMIN_EMAILS contains production admin emails
  • Test login flow works
  • Test Gmail service connection flow
  • Verify cron sync runs successfully

Monitoring and Logs

View application logs

Vercel dashboard → Your project → Deployments → Click deployment → Runtime Logs Filter by:
  • Source: Edge, Serverless, etc.
  • Status: Errors, Warnings, All

View cron logs

Vercel dashboard → Your project → Cron Jobs → Click a run Shows:
  • Execution time
  • Duration
  • Status code
  • Response body
  • Runtime logs

Monitor Gmail API usage

Go to Google Cloud ConsoleAPIs & ServicesDashboard Check quotas for:
  • Gmail API - Daily quota (usually 1 billion quota units/day)
  • Monitor requests/day to avoid hitting limits

Troubleshooting

Build fails with “pnpm not found”

Vercel should auto-detect pnpm from pnpm-lock.yaml. If not:
  1. Go to SettingsGeneral
  2. Set Install Command to pnpm install
  3. Redeploy

”Database connection failed” error

Verify:
  • DATABASE_URL is set correctly in Vercel environment variables
  • Connection string includes ?sslmode=require
  • Neon project is not paused (free tier auto-pauses after inactivity)

Cron jobs not running

Verify:
  • You’re on Vercel Pro or Enterprise plan (Hobby plan doesn’t support cron)
  • vercel.json is committed to repository
  • Redeploy after adding vercel.json

”Unauthorized cron request” in logs

Verify:
  • CRON_SECRET is set in Vercel environment variables
  • Value matches exactly (no extra spaces/newlines)

OAuth redirect mismatch

Verify all redirect URIs are added to Google Cloud Console:
https://your-project.vercel.app/api/auth/callback/google
https://your-project.vercel.app/api/services/oauth/callback
And custom domain if applicable:
https://bridge.delightroom.com/api/auth/callback/google
https://bridge.delightroom.com/api/services/oauth/callback

Build docs developers (and LLMs) love