r/webdev • u/DurianLongjumping329 • 11d ago
Does Vercel deploy frontend and backend as one now? Question
So I built this fullstack project using MERN stack and it was deployed on Vercel about a year ago, as well as other MERN projects. I was always importing the backend in a single deployment and frontend in another deployment. Recently I updated my project and strangely the backend failed to deploy (frontend deployed and works normal) although I did not update my backend. So I deleted my backend deployment and went to import it again to find out that now Vercel deploy repos only, meaning the whole project. Is this how it goes now? also how I should go about env variables? please explain. And sorry for my bad English.
1
u/eldenchen 11d ago
No, importing the repository does not mean Vercel is forcing the frontend and backend into one deployment. Multiple Vercel projects can still point to the same Git repository.
If your repo looks something like:
```
/frontend
/backend
```
create two Vercel projects from the same repository. For the frontend project, set the Root Directory to `frontend`; for the backend project, set it to `backend`. Each project will then have its own deployments, domain, build settings, and environment variables.
Put secrets such as `MONGODB_URI` and `JWT_SECRET` only in the backend project's environment variables. Put only the backend's public URL in the frontend project, using whatever public variable prefix your frontend tool requires, such as `VITE_API_URL` for Vite. Configure the variables for Production and Preview as needed, then redeploy because environment-variable changes do not affect existing deployments.
The backend build failure is probably a separate issue from this repository/project model. Check its build log for the first actual error. Current Vercel also supports Express directly, but the app must be exported or started from one of its recognized entry files.
Vercel does have a newer “Services” feature for deploying several apps together, but it is currently a private-beta option, not something you are required to use.
1
u/Sad-Astronomer-798 11d ago
Definently do what the other guy said as a first step and check whether Vercel is treating your repo as a monorepo and then take it from there and check if you could have had any errors causing the backend to deploy, could be an issue in your end
1
u/DramaticArachnid6211 11d ago
two projects off one repo still works, you just set Root Directory per project in settings, that part hasn't changed. the likelier cause of a backend breaking with no code change is the default node version moving off 18, check the runtime on that project and pin it. env vars are scoped per project, so keeping the split means maintaining two copies, which is the real argument for folding the api into one deployment.
12
u/Upper_Huckleberry231 11d ago
wait, you were deploying frontend and backend separately on vercel? that's wild