[Vuejs]-Cannot call api route from client app loaded by distant browser

1๐Ÿ‘

I found the solution, to make the address generic, I need to use the global variable:

window.location.hostname

That contains the hostname of the machine that runs the Vue app server.

Now when I try to make a request from distant computer, my browser is correctly using the machine hostname, not its own localhost.

This is the new Axios configuration :

const apo = axios.create({
  baseURL: `http://${window.location.hostname}:8081/api/route`,
  headers: {
    'Content-Type': 'text/plain',
  },
});
๐Ÿ‘คNibor Foo

Leave a comment