title: Making CORS API requests with create-react-app and webpack - no express
body: <p>I'm trying to make API calls without disabling CORS in my browser.  The app was created using react-create-app.  It is using webpack, and webpackDevServer for dev.  All the answers I found on here say to put the following code into my <code>webpack.config</code> file.</p>
  
  <pre><code>devServer: {
        headers: {
          "Access-Control-Allow-Origin": "*",
          "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
          "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
        }
    }
  </code></pre>
  
  <p>However, I've tried it in a number of different places and it doesn't work.  </p>
  
  <p>I continue to get the error:</p>
  
  <blockquote>
    <p>Failed to load resource: the server responded with a status of 500 ()</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>Failed to load ... 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:3000" rel="nofollow noreferrer">http://localhost:3000</a>' is therefore
    not allowed access. The response had HTTP status code 500.</p>
  </blockquote>
  
  <p>I also attempted to change my calls from axios calls to fetch calls</p>
  
  <pre><code>return fetch(process.env.REACT_APP_API_URL + "/prod/user", {
      mode: 'no-cors',
      credentials: 'include',
      method: "GET",
      headers: {
          "x-api-key": process.env.REACT_APP_API_KEY
      }
  })
  .then(response =&gt; {
     return response.json()
  })
  .then(resp =&gt; dispatch(receiveUsers(resp.data)))
  .catch(error =&gt; {console.log(error)})
  </code></pre>
  
  <p>That got me closer but the console now is returning </p>
  
  <p><code>Response {type: "opaque", url: "", redirected: false, status: 0, ok: false, …}</code></p>
  
  <p>How do I get around this CORS issue?  Thanks in advance for your help!</p>
  
  <p><a href="https://i.stack.imgur.com/IEgjM.png" rel="nofollow noreferrer">Response/Request Headers</a></p>