title: Handling CORS when developing from localhost using REST APIs - Streamlabs API
body: <p>I'm sure this question will get flagged in some manner, however hours of searching has prompted no usable information.</p>
  
  <p>Many projects require me to use various APIs. The current project uses the Twitch and Streamlabs API. When trying to access the /authorize endpoints, I'm hit with a CORS policy restriction. This is because my referer/origin is localhost.</p>
  
  <p><a href="https://i.stack.imgur.com/2zLpc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2zLpc.png" alt="CORS origin policy"></a></p>
  
  <p>My question lies in how others set up their environment for this not to be an issue. I understand why CORS is blocking me (to an extent), but what I don't understand is how I'm expected to work away from my production server if <code>localhost</code> has a blanket restriction.</p>
  
  <p>I have as well tried manipulating headers in fetch as well as using <code>[no-cors]</code>, but no avail here either. Any ideas?</p>
  
  <pre><code>  // Starts authorization
    getAuth() {
      const data = fetch (`https://streamlabs.com/api/v1.0/authorize?client_id=${clientID}&amp;response_type=code&amp;redirect_uri=https%3A%2F%2Ftwitchinstudios.com&amp;scope=donations.create%20donations.read%20alerts.write`, {
      headers: {
        "Origin" : "https://twitchinstudios.com",
        "Referer" : "https://twitchinstudios.com"
      },   
      mode: 'no-cors'});
      const code = data.json.code;
      console.log(code);
  
    // Post to /token endpoint
    const tokenCall = fetch (`https://streamlabs.com/api/v1.0/token?grant_type=authorization_token&amp;client_id=knOhuT74QrSn8h1m8tU8ucrFfVIfUuVpll71ErbI&amp;client_secret=${clientSecret}&amp;redirect_uri=https%3A%2F%2Ftwitchinstudios.com&amp;code=${code}`, {
      method: 'POST',
      mode: 'no-cors'
    })
  </code></pre>
  
  <p>Here is the documentation for their API as well: <a href="https://dev.streamlabs.com/reference" rel="nofollow noreferrer">https://dev.streamlabs.com/reference</a></p>