Search code examples
vue.jsaxiosnuxt.js

Axios BaseURL not working on certain hosts


Below is how I configured Axios based on the example given on Nuxt.js' website:

.env:

BASE_URL=https://path.to.endpoint

nuxt.config.js:

publicRuntimeConfig: {
  axios: {
    baseURL: process.env.BASE_URL
  }
},

On page load I make this call:

this.$axios.get(`/endpoint`)

Once I deploy my app as a static site it works both on my personal host and on GitHub pages. But on my employer's host, the path to endpoint specified in .env becomes https://localhost:3000 so the API call fails.

Why is the most likely cause of this behaviour?


Solution

  • Alright, from the comments, it looks like you configuration is totally fine from what you've provided and that the team on the other side does have an incorrect setup of the environment variables.

    You need to ask where they do host your code and what are the actual values of their env variables. Actually, you will probably need to give it to them since they (usually) cannot guess it by themselves.

    Human communication is the next step. ^^