title: Cross-Origin HTTP Request originating from server-side NodeJS/Axios/JSDOM
body: <p>I am using Axios to create a HTTP request to a API server in different domain.</p>
  
  <ul>
  <li>The API server allows Cross-Origin requests from <code>http://localhost:3000</code>.</li>
  <li>I have no control over the API server.</li>
  <li>My app usually runs in <code>http://localhost:3000</code> and makes requests from browser.</li>
  </ul>
  
  <p>There's no problem up to this point. Cross-Origin requests are working fine. However, recently I want to add a unit test for those API calls. This test environment is <code>jsdom</code> since I'm using <code>Jest</code>. This raises a problem when I <strong>create HTTP request from server-side</strong>, the origin is set to <code>http://localhost</code>, which the server does not allow.</p>
  
  <p>The request is made using Axios:</p>
  
  <pre><code>axios.post(`${API_DOMAIN}/member/account/login`, {
    username,
    password,
  }, {
    headers: {
      Origin: 'http://localhost:3000'
    }
  })
  </code></pre>
  
  <p>However, the response still says that</p>
  
  <p><code>error: Cross origin http://localhost forbidden</code></p>
  
  <p>How to change the "Origin" of the HTTP request I create with Axios under jsdom to other than <code>http://localhost</code>? I need it to be <code>http://localhost:3000</code> so that the API server allows me.</p>