This guide covers deploying the Tinder-like backend on Vercel and wiring your frontend to it.
- Express app in
src/app.js(auth, profile, requests, users). - MongoDB via Mongoose (
DB_CONNECTION_SECRET). - Vercel serverless:
api/index.js+vercel.jsonso the same app runs as a serverless function.
After deployment, all backend routes are under /api, e.g.:
https://your-backend.vercel.app/api/signuphttps://your-backend.vercel.app/api/loginhttps://your-backend.vercel.app/api/profile/view- etc.
- Vercel account
- Vercel CLI (optional):
npm i -g vercel - MongoDB (e.g. MongoDB Atlas) and a connection string
- Push this backend repo to GitHub / GitLab / Bitbucket.
- Go to vercel.com → Add New → Project.
- Import the backend repo (this folder).
- Root Directory: leave as
.(project root). - Framework Preset: leave as “Other” (no change).
- Build and Output: no build step; leave Build Command and Output Directory empty.
- Click Deploy. Wait for the first deployment to finish.
From the backend folder (this repo):
cd c:\dev-Tinder-Backend
npx vercelFollow the prompts (link to your Vercel account, project name). For production:
npx vercel --prodIn the Vercel project: Settings → Environment Variables. Add:
| Name | Value | Notes |
|---|---|---|
DB_CONNECTION_SECRET |
mongodb+srv://... |
Your MongoDB connection string |
JWT_SECRET |
(your secret string) | Same as in auth/JWT code |
CORS_ORIGIN |
https://your-frontend.vercel.app |
Frontend URL (see below) |
- Enable these for Production (and Preview if you use preview deployments).
- After saving, redeploy the project (Deployments → … → Redeploy) so the new variables are used.
Your frontend must call the deployed backend URL, with all routes under /api.
Backend base URL:
https://<your-backend-project>.vercel.app/api
Examples:
- Login:
POST https://<your-backend>.vercel.app/api/login - Signup:
POST https://<your-backend>.vercel.app/api/signup - Profile:
GET https://<your-backend>.vercel.app/api/profile/view(with credentials/cookies as you use today)
In your frontend app:
- Set the API base URL via env (recommended), e.g.
VITE_API_URL=https://<your-backend>.vercel.app/api(Vite)
orREACT_APP_API_URL=...(Create React App). - Use that base URL for all auth, profile, and user/request APIs (e.g.
fetch(\${API_URL}/login`, ...)`). - Ensure credentials are sent if you use cookies (e.g.
fetch(..., { credentials: 'include' })).
Then set backend CORS_ORIGIN to your frontend origin, e.g.:
https://your-frontend.vercel.app(no trailing slash)- For local dev:
http://localhost:5173(or whatever port you use)
- Create a second Vercel project and import your frontend repo.
- Build command and output directory depend on your stack (e.g. Vite:
npm run build, outputdist). - In the frontend project, set the same env (e.g.
VITE_API_URL=https://<your-backend>.vercel.app/api). - In the backend project, set
CORS_ORIGINto the frontend URL Vercel gives you (e.g.https://your-frontend.vercel.app).
- Backend: from this folder run
npm run dev(ornpm start). UsesPORTand.env(e.g.DB_CONNECTION_SECRET,JWT_SECRET,CORS_ORIGIN=http://localhost:5173). - Frontend: point its API base URL to
http://localhost:3000(or your backend port) without/api(local app serves routes at/).
- Backend repo pushed and deployed on Vercel.
-
DB_CONNECTION_SECRET,JWT_SECRET, andCORS_ORIGINset in backend project. - Frontend uses backend base URL
https://<backend>.vercel.app/api. - Frontend deployed and its URL set as
CORS_ORIGINin backend. - Cookies/credentials sent from frontend if your auth uses them.
If something fails, check Vercel → Project → Deployments → Function logs for the backend and the browser Network tab for CORS or 404 errors.