title: Enable CORS in fetch api
body: <p>I am getting the following error message that unable me to continue</p>
  
  <blockquote>
    <p>Failed to load <a href="https://site/data.json" rel="noreferrer">https://site/data.json</a>: Response to preflight request
    doesn't pass access control check: No 'Access-Control-Allow-Origin'
    header is present on the requested resource. Origin
    '<a href="http://localhost:8080" rel="noreferrer">http://localhost:8080</a>' is therefore not allowed access. If an opaque
    response serves your needs, set the request's mode to 'no-cors' to
    fetch the resource with CORS disabled.
        localhost/:1 Uncaught (in promise) TypeError: Failed to fetch</p>
  </blockquote>
  
  <p>I am trying to enable <code>CORS</code> in my react js file but I was not able to get the expected result.  I have installed a chrome extension and it work. But to use this in production site, I need to enable it inside my code. How should I properly arrange the code to enable the <code>CORS</code>.</p>
  
  <pre><code>fetch(URL, {
    mode: 'cors',
    headers: {
      'Access-Control-Allow-Origin':'*'
    }
  })
    .then(response =&gt; response.json())
    .then(data =&gt; {
  </code></pre>