title: CORS error on localhost event with correct headers
body: <p>I have a service that have the following headers on the response:</p>
  <pre><code>access-control-allow-origin: *
  access-control-allow-headers: *
  access-control-allow-methods: *
  </code></pre>
  <p>My cloudflare worker</p>
  <pre><code>addEventListener(&quot;fetch&quot;, (event) =&gt; {
    event.respondWith(handleRequest(event.request));
  });
  
  async function handleRequest(request) {
    const headers = new Headers({
      &quot;Content-Type&quot;: &quot;application/json&quot;,
      &quot;Access-Control-Allow-Origin&quot;: &quot;*&quot;,
      &quot;Access-Control-Allow-Headers&quot;: &quot;*&quot;,
      &quot;Access-Control-Allow-Methods&quot;: &quot;*&quot;,
      &quot;Access-Control-Max-Age&quot;: &quot;-1&quot;,
    });
  
    return new Response(
      JSON.stringify({
        network_address: request.headers.get(&quot;CF-Connecting-IP&quot;),
      }),
      { headers: headers, status: 200 }
    );
  }
  </code></pre>
  <p>We can check using cURL</p>
  <p><code>curl -s -D - -o /dev/null https://example.com</code></p>
  <pre><code>HTTP/2 200
  date: Thu, 02 Sep 2021 13:20:55 GMT
  content-type: application/json
  content-length: 36
  access-control-allow-origin: *
  access-control-allow-headers: *
  access-control-allow-methods: *
  access-control-max-age: -1
  expect-ct: max-age=604800, report-uri=&quot;https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct&quot;
  report-to: {&quot;endpoints&quot;:[{&quot;url&quot;:&quot;https:\/\/a.nel.cloudflare.com\/report\/v3?s=HERU%2BxkJuLdgGnre4HxDofQDXnCZGbEsX4RVTaL%2FjmO%2FE0iIRY7UGEYvkBpL85g%2F7o3V4ZdbpNma48SpLg%2BZ%2FFnW4hIf%2F3tpNCfA4EocZCtYCOdNAsEooxBAww%3D%3D&quot;}],&quot;group&quot;:&quot;cf-nel&quot;,&quot;max_age&quot;:604800}
  nel: {&quot;success_fraction&quot;:0,&quot;report_to&quot;:&quot;cf-nel&quot;,&quot;max_age&quot;:604800}
  server: cloudflare
  cf-ray: 688709d64bdc51f8-GRU
  alt-svc: h3-27=&quot;:443&quot;; ma=86400, h3-28=&quot;:443&quot;; ma=86400, h3-29=&quot;:443&quot;; ma=86400, h3=&quot;:443&quot;; ma=86400
  </code></pre>
  <p>My code:</p>
  <pre><code>const response = await fetch(`//example.com/?_=${Math.floor(Date.now() / 1000)}`)
  
  const { network_address } = await response.json()
  </code></pre>
  <p>Unfortunately, on <code>localhost:3000</code> the browser was unable to do the request because of CORS, see bellow:</p>
  <p><a href="https://i.stack.imgur.com/2YAnw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2YAnw.png" alt="" /></a></p>
  <p>What I need to do to allow CORS on localhost?</p>