title: Dynamic host in axios
body: <p>How can I create a dynamic host in <code>axios</code>?</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code> const host = location.hostname;
   // axios.defaults.baseURL = 'http://hastore.local';
   axios.defaults.baseURL = host;
   axios.defaults.port = 8080;
   axios.get('api/categories')
   .then((res) =&gt; {
        this.categories = res.data;
        console.log(res);
   })
   .catch((err) =&gt; {
        console.warn('error during http call', err);
   });
  </code></pre>
  
  <p>String <code>axios.defaults.baseURL = 'http://hastore.local';</code> does not fit, because on prodaction don't be work.</p>
  
  <p>String <code>const host = location.hostname;</code> also not a solution, because I get incorrect port and dublicate host.</p>
  
  <p><a href="https://i.stack.imgur.com/ay1ZT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ay1ZT.png" alt="enter image description here"></a></p>
  
  <p>The goal is to get the right host depending on the environment.
  I read a lot of articles about this, but I did not find a solution.
  Thanks for help!</p>
  
  <ul>
  <li>axios version: e.g.: v0.16.2</li>
  <li>Environment: e.g.: node v8.9.4, chrome 64.0.3282.119, Ubuntu 16.04</li>
  <li>Symfony 4.0.4</li>
  <li>Vue.js 2.4.2</li>
  <li>vue-axios 2.0.2</li>
  </ul>