Axios-module: [Question] Using localhost for development and domain name in production

Created on 5 Feb 2018  路  4Comments  路  Source: nuxt-community/axios-module

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?

This question is available on Nuxt.js community (#c83)
question

Most helpful comment

Hi. If you are running both on the same server, you have two ways:

  1. Just set proxy: true option. (This won't actually use proxy but makes requests going to a relative path)

  2. During production build, set environment variable API_URL something like this:

API_URL=http://mydomain.com yarn build

All 4 comments

Hi. If you are running both on the same server, you have two ways:

  1. Just set proxy: true option. (This won't actually use proxy but makes requests going to a relative path)

  2. 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
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ruudboon picture ruudboon  路  5Comments

artmarydotir picture artmarydotir  路  4Comments

lyzs90 picture lyzs90  路  4Comments

seanwash picture seanwash  路  6Comments

WtekSupport picture WtekSupport  路  6Comments