I have a React application that is built statically and served by Nginx.
I serve the different version of the application with these 2 location context :
- This one serves the latest version of the application
location / {
root /etc/application_development/latest;
index index.html;
}
- This one serves the different versions of the application
location /version {
root /etc/kosmikpwa_development/$1;
index index.html;
}
It works fine but when an application is on /version
, it tries to access its assets on /static
instead on /version/X.X.X/static
How can I change that in order for the applications on /version
to work as expected ?
CodePudding user response:
For versioned builds, before building the app, in package.json
of your react app, you need to set homepage
like this:
"homepage": "version"
After this change, do not forget to append process.env.PUBLIC_URL
to the assets you use from your public
folder if there exists one. So, these assets will be bundled according to your homepage
defined in package.json
.