Step-by-step guide to deploy Roost’s frontend on Vercel. The backend must be deployed separately.
Prerequisites
- A Vercel account
- A GitHub/GitLab repository with your Roost project
- Backend deployed separately (VPS, Railway, Render, etc.)
- Database configured (Supabase Cloud recommended for Vercel)
Architecture
[Users] --> [Vercel - Frontend (React SPA)]
|
+--> [Backend Server (Express.js)]
| |
| +--> [Database (Supabase)]
| +--> [S3 Storage]
| +--> [Redis (optional)]
|
+--> [Supabase (direct client calls)]
Vercel serves the static frontend. API calls go to your separately hosted backend.
Step 1: Push to Git
# Initialize git if not already
git init
git add .
git commit -m "Initial Roost setup"
# Push to GitHub
git remote add origin https://github.com/your-org/roost.git
git push -u origin main
Step 2: Import to Vercel
- Go to vercel.com/new
- Click Import Git Repository
- Select your
roostrepository - Configure the project:
- Framework Preset: Vite
- Root Directory:
.(leave as project root) - Build Command:
npm run build - Output Directory:
dist
Step 3: Configure Environment Variables
In Vercel project settings > Environment Variables, add:
| Variable | Value | Environment |
|---|---|---|
VITE_DB_PROVIDER |
supabase-cloud |
Production, Preview |
VITE_SUPABASE_URL |
https://your-project.supabase.co |
Production, Preview |
VITE_SUPABASE_PUBLISHABLE_KEY |
your-anon-key |
Production, Preview |
VITE_APP_NAME |
Your Community |
Production, Preview |
VITE_APP_URL |
https://your-vercel-domain.vercel.app |
Production |
VITE_API_URL |
https://your-backend-url.com |
Production, Preview |
VITE_ENABLE_SIGNUP |
true |
Production |
Step 4: Deploy
Click Deploy. Vercel will:
- Clone your repo
- Run
npm install - Run
npm run build(with your env vars injected) - Deploy the
dist/folder to their CDN
Step 5: Configure Custom Domain (Optional)
- Vercel project > Settings > Domains
- Add your custom domain (e.g.,
roost.your-domain.com) - Update DNS:
- A Record:
76.76.21.21 - CNAME:
cname.vercel-dns.com
- A Record:
- SSL is automatic
After adding the domain, update your env vars:
VITE_APP_URL=https://roost.your-domain.com
Step 6: Deploy the Backend
The Express.js backend needs a separate host. Options:
Option A: Railway
# Install Railway CLI
npm install -g @railway/cli
# Login and deploy
cd server
railway login
railway init
railway up
Set environment variables in Railway dashboard.
Option B: Render
- Go to render.com
- New > Web Service
- Connect your repo
- Settings:
- Root Directory:
server - Build Command:
npm install && npm run build - Start Command:
npm start
- Root Directory:
- Add environment variables
Option C: Your Own VPS
# On your server
cd roost/server
npm install
npm run build
# Use PM2 for process management
npm install -g pm2
pm2 start dist/index.js --name roost-backend
pm2 save
pm2 startup
Option D: Vercel Serverless Functions (Advanced)
You can adapt the Express backend to Vercel serverless functions, but this requires restructuring the routes. Not recommended unless you’re familiar with serverless patterns.
Step 7: Update CORS
Make sure your backend allows requests from Vercel:
In server/.env:
ALLOWED_ORIGINS=https://your-vercel-domain.vercel.app,https://roost.your-domain.com
FRONTEND_URL=https://roost.your-domain.com
Preview Deployments
Vercel automatically creates preview deployments for every pull request. To use them:
- Set Preview environment variables in Vercel
- Use a different
VITE_APP_URLfor previews or leave it as the preview URL
Vercel Configuration
The vercel.json file is already configured:
{
"buildCommand": "npm run build",
"outputDirectory": "dist",
"framework": "vite",
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
The rewrite rule ensures client-side routing works (all paths serve index.html).
Troubleshooting
Build fails with “missing env vars”
- Make sure all
VITE_*variables are set in Vercel dashboard - Check the build logs for specific errors
API calls fail (CORS)
- Verify
ALLOWED_ORIGINSon your backend includes the Vercel URL - Check browser console for specific CORS error messages
Routes return 404
- Ensure
vercel.jsonhas the rewrite rule - Clear Vercel cache: Settings > Functions > Purge Cache
Environment variables not taking effect
- Vercel requires a redeploy after changing env vars
- Go to Deployments > latest > Redeploy