I am running nuxt programmatically on an express server. My local dev environment and api is running on localhost:3000. I have the typical nginx reverse proxy setup pointing to this port in production.
In production, on inital page load, everything loads fine since its rendered server side. If I click on another page that requires an api request, I see the request going to localhost:3000/api/** instead of mydomain.com/api/**
What would be the proper way to set this up in nuxt.config.js file so that the local dev build points to localhost and when I run build in production it sets the baseUrl to my domain name?
Hi. If you are running both on the same server, you have two ways:
Just set proxy: true option. (This won't actually use proxy but makes requests going to a relative path)
During production build, set environment variable API_URL something like this:
API_URL=http://mydomain.com yarn build
@pi0 Thank you! Option 1 works great.
@pi0 thank you. Where do I have to set proxy to true? In the axios module?
@jfcmoeller in your nuxt.config.js file.. just add this (i put mine after modules)
axios: {
proxy: true
}
Most helpful comment
Hi. If you are running both on the same server, you have two ways:
Just set
proxy: trueoption. (This won't actually use proxy but makes requests going to a relative path)During production build, set environment variable
API_URLsomething like this: