<p dir="auto">Hello everyone!<br>
How I can doing dynamic host in axios?</p>
<p dir="auto">Example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="      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);
        });"><pre class="notranslate"><code class="notranslate">      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></div>
<p dir="auto">String <code class="notranslate">axios.defaults.baseURL = 'http://hastore.local';</code> does not fit, because on prodaction don't be work.</p>
<p dir="auto">String <code class="notranslate"> const host = location.hostname;</code> also not a solution, because I get incorrect port and dublicate host.</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/6662917/35751304-05751ace-0869-11e8-9202-f66fdae5f0e5.png"><img src="https://user-images.githubusercontent.com/6662917/35751304-05751ace-0869-11e8-9202-f66fdae5f0e5.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">The goal is to get the right host depending on the environment.<br>
I read a lot of articles about this, but I did not find a solution.<br>
Thanks for help!</p>
<ul dir="auto">
<li>axios version: <em>e.g.: v0.16.2</em></li>
<li>Environment: <em>e.g.: node v8.9.4, chrome 64.0.3282.119, Ubuntu 16.04</em></li>
</ul>
<h4 dir="auto">Summary</h4>
<p dir="auto">try</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="let url = '/dsk',
let data = {
    dsk: ['a1', 'a2']
}
let config = {
    baseURL: 'http://8.8.8.8',
    data
}

axios.post(url, data, {config}).then(resp =&gt; { console.log(resp.config.data) })"><pre class="notranslate"><span class="pl-k">let</span> <span class="pl-s1">url</span> <span class="pl-c1">=</span> <span class="pl-s">'/dsk'</span><span class="pl-kos">,</span>
<span class="pl-s1">let</span> <span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-c1">dsk</span>: <span class="pl-kos">[</span><span class="pl-s">'a1'</span><span class="pl-kos">,</span> <span class="pl-s">'a2'</span><span class="pl-kos">]</span>
<span class="pl-kos">}</span>
<span class="pl-k">let</span> <span class="pl-s1">config</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
    <span class="pl-c1">baseURL</span>: <span class="pl-s">'http://8.8.8.8'</span><span class="pl-kos">,</span>
    data
<span class="pl-kos">}</span>

<span class="pl-s1">axios</span><span class="pl-kos">.</span><span class="pl-en">post</span><span class="pl-kos">(</span><span class="pl-s1">url</span><span class="pl-kos">,</span> <span class="pl-s1">data</span><span class="pl-kos">,</span> <span class="pl-kos">{</span>config<span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">.</span><span class="pl-en">then</span><span class="pl-kos">(</span><span class="pl-s1">resp</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span> <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s1">resp</span><span class="pl-kos">.</span><span class="pl-c1">config</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">)</span> <span class="pl-kos">}</span><span class="pl-kos">)</span></pre></div>
<p dir="auto">get <code class="notranslate">resp.config.data</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="{&quot;baseURL&quot;: &quot;http://8.8.8.8&quot;, &quot;url&quot;: &quot;/dsk&quot;, &quot;data&quot;: {&quot;0&quot;: &quot;a1&quot;, &quot;1&quot;: &quot;a2&quot;}}"><pre class="notranslate"><code class="notranslate">{"baseURL": "http://8.8.8.8", "url": "/dsk", "data": {"0": "a1", "1": "a2"}}
</code></pre></div>
<p dir="auto">this config data is not expect.</p>
<h4 dir="auto">Context</h4>
<ul dir="auto">
<li>axios version: v0.18.0</li>
<li>Environment: node v10.4.1</li>
</ul>