I am working on an ecommerce app using mern stack.
I tried deploying it on vercel but for some reason the homepage shows the index js code and no other routes work, neither the api routes nor the react router routes.
I am pretty sure there is something wrong in the vercel.json. I didn’t find any tutorial on vercel.json
Here is the repo link : https://github.com/ishanjarwal/mern-sneaker-store
Folder Structure : in the root, there are two folders : api and client. the api folder contains a dist for react’s build. the api folder is what I want to be deployed and I don’t want a seperate repo with api as the root folder.
Please give a solution along with explaination.
I tried changing vercel.json several times without any knowledge about it. I did not find a resource to learn more about it.
Any request to /api/(*) is being redirected to api/index.js.
To fix you’ll need to configure the “src” with your route and the “dest” with the file you want it to load.
E.g. { “src”: “/api”, “dest”: “/my-api.js” }
Link for more info: https://vercel.com/docs/projects/project-configuration#routes
nicolasrobinson118 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I found out. The problem was that I selected api as the root folder instead of the root folder of the repo itself.
It solved the issue