404 when serving statics files with an express.js app #7359
-
SummaryI am encountering difficulties deploying static files generated from a React project on Vercel, using Express.js to handle API routes. Despite configuring routes in vercel.json to serve static files from the /public/ directory ({ "src": "/(.*)", "dest": "/public/$1" }), I consistently receive a 404 error when attempting to access these files. When i access to de https://vercel-app-example-api/api/ everithing is fine but in the '/' route i have 404 Setup: My application utilizes Express.js for API handling (api/index.js), and the static files (e.g., index.html, style.css) are generated as part of a React project build process. I verified directory structures and file names to ensure they align with configured routes in vercel.json. This is my vercel.json Examplehttps://fullstack-open-phonebook-api.vercel.app/ Steps to Reproduce |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hey @leodev9911. It looks like your project uses the deprecated There's also a guide available that walks through using Express.js with Vercel. This is a good starter to use if you're not already familiar with adapting Express sites to a serverless environment. The config doesn't look quite right to me, but I don't know the full setup of your repo. If you can share a minimal reproducible example I would be happy to take a closer look |
Beta Was this translation helpful? Give feedback.
-
This discussion was automatically locked because the community moved to a new site. Please join us at vercel.community |
Beta Was this translation helpful? Give feedback.
Hey @leodev9911. It looks like your project uses the deprecated
builds
androutes
config. Node.js runtime will automatically be used for the runtime for JS files in the/api
directory so you can remove thebuilds
part. I also recommend switchingroutes
torewrites
. That isn't likely to solve the whole problem, but should make it a bit easier to debug without the extra config getting in your way.There's also a guide available that walks through using Express.js with Vercel. This is a good starter to use if you're not already familiar with adapting Express sites to a serverless environment.
The config doesn't look quite right to me, but I don't know the full setup of your repo. If you can …