- Backend is not Vercel-compatible as-is: the app starts an HTTP server in
bin/www, which is not used by Vercel serverless functions. A serverless entrypoint is required. - Frontend build/output is not configured for Vercel: the project has a React client under
client/but no Vercel build/output config. - Database connectivity is undefined in production: MongoDB credentials are only loaded from
config.env(gitignored). Missing env vars will crash the server. - File uploads were writing to local disk (
client/public/uploads/...), which is read-only/ephemeral on Vercel, so uploads would fail in production. - Default Vercel Node runtime is newer than this project expects: the client depended on
node-sass, which is not compatible with modern Node versions. - Firebase authentication is not present in the codebase. Auth is implemented with JWT cookies and MongoDB users.
-
No serverless handler for Vercel
- Where:
bin/wwwstarts an HTTP server and connects to MongoDB directly. - Impact: Vercel ignores long-lived servers; requests would never hit the Express app.
- Fix applied: Added
api/index.jsserverless entrypoint and centralized DB connection (utils/db.js).
- Where:
-
Missing Vercel build/routing configuration
- Where: No
vercel.jsonand no build command at repo root. - Impact: Vercel won’t build the React app or route API requests to the backend.
- Fix applied: Added
vercel.jsonwith separate static build (React) and Node serverless function routes.
- Where: No
-
Database env variables not defined for production
- Where:
bin/wwwusesprocess.env.DATABASE_ATLASandprocess.env.PASSWORDbutconfig.envis not in repo. - Impact: Mongo connection throws at runtime; deployment fails.
- Fix applied: Centralized MongoDB connection with explicit env validation in
utils/db.js.
- Where:
-
File uploads were writing to local disk
- Where:
controllers/uploadController.jswrites to./client/public/uploads/.... - Impact: Vercel’s filesystem is read-only/ephemeral, so uploads fail in production.
- Fix applied: Switched uploads to MongoDB GridFS and added download route
GET /uploads/:slug/images/:category/:filename.
- Where:
-
Client build dependency incompatible with modern Node
- Where:
client/package.jsondepends onnode-sass@4.x. - Impact: Build fails on Vercel default Node runtime.
- Fix applied: Replaced
node-sasswithsassand pinned Node to20.x.
- Where:
- Email requires SMTP credentials:
Emailhelper will fail on signup ifEMAIL_*vars are missing. - Uploads now depend on MongoDB permissions: the MongoDB user must allow GridFS collections (
uploads.files,uploads.chunks). - JWT cookies are set as
securewhen HTTPS: works on Vercel, but local testing over HTTP will not setsecurecookies.
Set these in Vercel Project → Settings → Environment Variables:
DATABASE_ATLAS– MongoDB connection string containing<PASSWORD>placeholder.PASSWORD– MongoDB password inserted intoDATABASE_ATLAS.JWT_SECRET– secret for signing JWTs.JWT_EXPIRES_TIME– e.g.90d.JWT_COOKIE_EXPIRES_IN– number of days for the cookie (e.g.90).EMAIL_FROM– from address for system emails.EMAIL_HOST– SMTP host.EMAIL_PORT– SMTP port.EMAIL_USER– SMTP username.EMAIL_PASSWORD– SMTP password.
- Add healthcheck endpoint (e.g.,
/api/health) to verify DB connectivity. - Add image size limits/validation per route (profile vs product) for better UX.
- Add error logging/observability (Vercel log drains or external logging).
- MongoDB Atlas (or compatible) is used and supports GridFS.
- The app’s image URLs remain
/uploads/:slug/images/:category/:filenameand are now backed by GridFS. - Vercel runtime is pinned to Node 20 via
enginesto avoid Node 24 incompatibilities.
vercel buildsucceeds (client builds + API function bundles).vercel deploysucceeds with env vars configured.- API requests to
/account,/farmers,/users, and/uploads/*route correctly. - Uploads persist and are retrievable from MongoDB GridFS.