In my project, we use Nuxt and the Axios module, and we have different environments (local, staging, prod…). We would like to build once the application, and deploy it everywhere, on any environment.
Today we cannot build only once because we have different
API_URL_BROWSER values, depending on the environment, and necessary for the
nuxt build phase.
So, on each server, we have to build and start, instead of just starting the same application everywhere.
For example, today we have to do:
API_URL=http://staging.api.url/ API_URL_BROWSER=http//staging.api.url.browser/ npm run build && npm start on staging environment, and
API_URL=http://prod.api.url/ API_URL_BROWSER=http//prod.api.url.browser/ npm run build && npm start on prod environment.
Is there a way to build the application only once, and use the
API_URL_BROWSER variables when starting the application?
For example, we would like to do:
npm run build only once, without any variable, and just
API_URL=http://staging.api.url/ API_URL_BROWSER=http//staging.api.url.browser npm start on staging environment, and
API_URL=http://prod.api.url/ API_URL_BROWSER=http//prod.api.url.browser npm start on prod environment.
I saw the Dynamic API Backend documentation, which use the
@nuxtjs/proxy module, but I was wondering if there is another way.