Skip to main content

Overview

RLink is optimized for deployment on Vercel, with built-in support for:
  • Automatic deployments from Git
  • Environment variable management
  • Serverless functions for API routes
  • Cron jobs for scheduled tasks
  • Edge network for global performance

Prerequisites

Sign up for a free account at vercel.com
Create a PostgreSQL database at neon.tech
  • Note your connection string
  • Ensure database is accessible from Vercel
Create an account at resend.com
  • Get your API key
  • Verify your sending domain
Ensure your code is pushed to GitHub, GitLab, or Bitbucket

Deployment Steps

1. Connect Repository to Vercel

1

Import Project

  1. Go to Vercel Dashboard
  2. Click “Add New…” → “Project”
  3. Select your Git provider (GitHub)
  4. Import the rlink repository
2

Configure Build Settings

Vercel auto-detects Next.js:
  • Framework Preset: Next.js
  • Build Command: next build
  • Output Directory: .next
  • Install Command: npm install
No changes needed - Vercel uses these defaults automatically
3

Set Root Directory

If your Next.js app is in a subdirectory, set the root directory. Otherwise, leave as .

2. Configure Environment Variables

In your Vercel project settings, add all environment variables:
DATABASE_URL="postgresql://user:pass@host.neon.tech/database?sslmode=require"
Get this from your Neon dashboard → Connection String
NEXT_PUBLIC_APP_URL="https://your-domain.vercel.app"
BETTER_AUTH_URL="https://your-domain.vercel.app"
SITE_URL="https://your-domain.vercel.app"
Replace your-domain with your actual Vercel domain
ALLOWED_ORIGIN="https://your-domain.vercel.app"
Important: Set this to your actual production domain for proper CORS configuration
RESEND_API_KEY="re_xxxxxxxxxxxxxxxxxxxxx"
RESEND_FROM="RLink <noreply@yourdomain.com>"
Get your API key from Resend dashboard → API Keys
BETTER_AUTH_SECRET="your-random-32-char-secret-here"
Generate a secure random string (minimum 32 characters):
openssl rand -base64 32
CRON_SECRET="your-cron-secret-here"
REVALIDATION_SECRET="your-revalidation-secret-here"
Generate these similarly to the auth secret
Never commit these secrets to Git! Always use Vercel’s environment variable system.

3. Deploy Database Schema

Before your first deployment, apply database migrations:
1

Local Setup

# Set your production DATABASE_URL locally
export DATABASE_URL="postgresql://..."

# Apply migrations
npx drizzle-kit migrate
2

Verify Schema

Connect to your Neon database and verify tables exist:
  • Better Auth tables (users, sessions, etc.)
  • Application tables (projects, leads, etc.)
Alternatively, you can run migrations from Vercel by adding a custom build script, but local migration is recommended for first deployment.

4. Configure Cron Jobs

RLink uses Vercel Cron for scheduled tasks.
1

Verify vercel.json

Ensure vercel.json exists in your project root:
{
  "crons": [
    {
      "path": "/api/cron/activity-logs-retention",
      "schedule": "0 0 * * *"
    }
  ]
}
This runs daily at midnight UTC to clean up old activity logs.
2

Set Cron Secret

In Vercel dashboard:
  1. Go to Settings → Environment Variables
  2. Ensure CRON_SECRET is set
  3. Vercel will automatically add this as Authorization: Bearer {CRON_SECRET} header
3

Test Cron

After deployment, manually trigger:
curl -X POST https://your-domain.vercel.app/api/cron/activity-logs-retention \
  -H "Authorization: Bearer YOUR_CRON_SECRET"

5. Deploy Application

1

Trigger Deployment

Click “Deploy” in Vercel dashboard, or push to your main branch to trigger automatic deployment.
2

Monitor Build

Watch the build logs in Vercel dashboard. Common issues:
  • Environment variable typos
  • Database connection errors
  • Missing dependencies
3

Check Deployment

Once deployed, visit your Vercel URL:
https://your-project.vercel.app
You should see the RLink login page.

Post-Deployment Checklist

Custom Domain Setup

1. Add Domain to Vercel

1

Add Domain

  1. Go to Project Settings → Domains
  2. Click “Add Domain”
  3. Enter your domain (e.g., rlink.rlanddevelopment.com)
2

Configure DNS

Add the following DNS records at your domain registrar:A Record:
Type: A
Name: @ (or subdomain)
Value: 76.76.21.21
AAAA Record (for IPv6):
Type: AAAA
Name: @ (or subdomain)
Value: 2606:4700:4700::1111
Or use CNAME for subdomains:
Type: CNAME
Name: rlink
Value: cname.vercel-dns.com
3

Verify Domain

Vercel will automatically verify DNS propagation. This can take 24-48 hours.
4

Update Environment Variables

Update all URL-related environment variables to use your custom domain:
NEXT_PUBLIC_APP_URL="https://rlink.rlanddevelopment.com"
BETTER_AUTH_URL="https://rlink.rlanddevelopment.com"
SITE_URL="https://rlink.rlanddevelopment.com"
ALLOWED_ORIGIN="https://rlink.rlanddevelopment.com"

Environment-Specific Configuration

Production Environment

# Production database
DATABASE_URL="postgresql://prod-user:pass@prod-host.neon.tech/rlink?sslmode=require"

# Production URLs
NEXT_PUBLIC_APP_URL="https://rlink.rlanddevelopment.com"
ALLOWED_ORIGIN="https://rlink.rlanddevelopment.com"

# Production email
RESEND_FROM="RLink <noreply@rlanddevelopment.com>"

Staging Environment

For a staging deployment:
# Staging database (separate from production)
DATABASE_URL="postgresql://staging-user:pass@staging-host.neon.tech/rlink-staging?sslmode=require"

# Staging URLs
NEXT_PUBLIC_APP_URL="https://rlink-staging.vercel.app"
ALLOWED_ORIGIN="https://rlink-staging.vercel.app"

# Staging email (use test domain)
RESEND_FROM="RLink Staging <noreply@staging.rlanddevelopment.com>"
Create a separate Vercel project for staging linked to a staging or develop branch.

Continuous Deployment

Automatic Deployments

Vercel automatically deploys when you push to connected branches:
  • Production: Pushes to main → Production deployment
  • Preview: Pushes to other branches → Preview deployment

Branch Protection

Configure branch protection in GitHub:
# .github/workflows/ci.yml (example)
name: CI
on: [pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: npm install
      - name: Run tests
        run: npm test
      - name: Run linter
        run: npm run lint

Performance Optimization

1. Enable Edge Functions

For routes that benefit from running at the edge, you can opt in explicitly (validate compatibility with your dependencies first):
// app/api/some-route/route.ts
export const runtime = 'edge';

2. Configure Caching

Set proper cache headers in next.config.ts:
async headers() {
  return [
    {
      source: '/uploads/:path*',
      headers: [
        {
          key: 'Cache-Control',
          value: 'public, max-age=31536000, immutable',
        },
      ],
    },
  ];
}

3. Optimize Images

Images are automatically optimized by Next.js Image component. Ensure you’re using it:
import Image from 'next/image';

<Image 
  src="/uploads/projects/cover.jpg"
  alt="Project cover"
  width={800}
  height={600}
  priority // For above-the-fold images
/>

Monitoring & Logging

Vercel Analytics

Enable Vercel Analytics for production insights:
  1. Go to Project Settings → Analytics
  2. Enable Web Analytics
  3. View metrics in dashboard

Error Tracking

Consider integrating error tracking for production:
  • Sentry: For comprehensive error monitoring
  • LogRocket: For session replay
  • Vercel Logs: Built-in log streaming

Rollback Strategy

If a deployment causes issues:
1

Instant Rollback

In Vercel dashboard:
  1. Go to Deployments
  2. Find last working deployment
  3. Click ”…” → “Promote to Production”
2

Git Revert

Revert the problematic commit:
git revert HEAD
git push origin main

Security Hardening

Verify security headers are set in next.config.ts:
async headers() {
  return [
    {
      source: '/:path*',
      headers: [
        { key: 'X-DNS-Prefetch-Control', value: 'on' },
        { key: 'X-Frame-Options', value: 'DENY' },
        { key: 'X-Content-Type-Options', value: 'nosniff' },
        { key: 'Referrer-Policy', value: 'origin-when-cross-origin' },
      ],
    },
  ];
}
Apply rate limits at the application or edge layer for sensitive routes (login, public APIs). Tune limits for legitimate traffic spikes.
  • Enable SSL mode in connection string (?sslmode=require)
  • Use Neon’s IP allowlist if needed
  • Rotate database passwords regularly
Rotate secrets periodically:
  1. Generate new secret
  2. Update in Vercel environment variables
  3. Redeploy application
  4. Invalidate old sessions (users will need to re-login)

Troubleshooting

Error: Connection timeout or Connection refusedSolutions:
  • Verify DATABASE_URL is correct
  • Check Neon database is active
  • Ensure SSL mode is set: ?sslmode=require
  • Verify Neon’s IP allowlist includes Vercel IPs
Error: Build failed with exit code 1Solutions:
  • Check build logs in Vercel dashboard
  • Verify all environment variables are set
  • Run npm run build locally to reproduce
  • Check for TypeScript errors
Error: Emails not being deliveredSolutions:
  • Verify RESEND_API_KEY is correct
  • Check Resend dashboard for API usage/errors
  • Ensure sending domain is verified
  • Check spam folder for test emails
Error: CORS policy: No 'Access-Control-Allow-Origin' headerSolutions:
  • Verify ALLOWED_ORIGIN matches your actual domain
  • Check next.config.ts CORS configuration
  • Ensure cookies are being sent with requests
Error: Session expired or Not authenticatedSolutions:
  • Verify BETTER_AUTH_SECRET is set
  • Check NEXT_PUBLIC_APP_URL matches deployment URL
  • Clear browser cookies and try again
  • Verify Better Auth tables exist in database

Scaling Considerations

Database Scaling

Neon PostgreSQL auto-scales. For high traffic:
  1. Enable connection pooling in Neon dashboard
  2. Use read replicas for heavy read operations
  3. Optimize queries with proper indexes

Vercel Plan Limits

Free Tier Limits

  • 100 GB bandwidth/month
  • 100 hours function execution/month
  • Serverless function timeout: 10 seconds
For production, consider Vercel Pro or Enterprise for:
  • Increased bandwidth
  • Longer function timeouts
  • Team collaboration features
  • Advanced analytics

Backup Strategy

1

Database Backups

Neon provides automatic backups. Verify:
  1. Go to Neon dashboard → Backups
  2. Ensure daily backups are enabled
  3. Configure retention period (7-30 days recommended)
2

Code Backups

Git provides version control. Additional backups:
  • Clone repository locally periodically
  • Mirror to a private backup repository
3

Environment Backups

Document all environment variables securely:
  • Store in password manager (1Password, LastPass)
  • Keep offline encrypted backup

Next Steps

Troubleshooting

Production issues and edge cases

Maintenance

Routine tasks and workflows