[Vuejs]-Axio Request return Network error if url 'localhost" and okay if use IP Address on VPS only(digital ocean)?

0👍

If you open a remotely hosted App (e.g. on Digital Ocean) from your machine, “localhost” and “127.0.0.1” refer to your local machine and not the remote HTTP Server. That local machine is not listening for connections and hence the client connection is being refused.

As far as I understand your setup, the API is hosted at the same location as your WebApp. Therefore you don’t need to set any baseURL for Axios.

Removing the line

axios.defaults.baseURL = 'http://localhost:'+window.location.port+'/';

should solve your problem.

Leave a comment