How to deploy project in subdirectory instead of root directory?

Viewed 180

After the operation and maintenance helped me deploy it, I found that it was deployed in the root directory (for example: https://www.example.com), but the requirement was to deploy it in a subdirectory (for example: https://www.example.com/aaa) .

How does the front end set a subdirectory when packaging configuration? Similar to the base property configuration in vite.config.js of the Vite project. Does the calling interface also need to be changed accordingly?

1 Answers

How does the front end set a subdirectory when packaging configuration?

If you just need to deploy the front-end code to a subdirectory, the first thing I recommend is that you use Nginx as a proxy instead of modifying the configuration within the project;

Of course, the front end can also be modified.For the create-react-app used in our front-end project, you can refer to here. After modifying the configuration, you need to package and build it yourself.

Does the calling interface also need to be changed accordingly?

If your backend code is deployed in the same subdirectory as the front-end code, you need to modify the two environment variables REACT_APP_API_URL PUBLIC_URL in .env.production. If they are not in the same directory, it is best to use nginx as a proxy.