I have a Vite app built and I want to deploy it with my Tomcat, but it throws the following error:
Failed to load resource: the server responded with a status of 404 ()
for index.js
file
When I run my app locally with npm run preview
it works fine
My deploying procedure:
- run
npm run build
to build my app - Transfer the contents of
dist
directory intoTomcat 9.0\webapps\my-app
- Go to
http://localhost:8080/my-app/
Result is empty webpage with a singular console error mentioned above.
React config files' contents:
vite.config.ts
***
base: '/',
***
package.json
***
"homepage": "/",
***
What is the correct procedure to deploy React/Vite apps using Tomcat?
Answer
Solution provided by @Phil in the comment section. Update base config as well as router's basename with my app name, then update Tomcat config as mentioned in this post