title: Firebase error with CORS when running on localhost
body: <p>I am getting the following error when running my project.</p>
  
  <blockquote>
    <p>Failed to load
    <a href="https://us-centralx-xxx.cloudfunctions.net/xxx" rel="nofollow noreferrer">https://us-centralx-xxx.cloudfunctions.net/xxx</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:3000" rel="nofollow noreferrer">http://localhost:3000</a>' is therefore not allowed
    access. The response had HTTP status code 500.</p>
  </blockquote>
  
  <p>After reading many SO post, I found the following solution, where I need to add the <code>Access-Control-Allow-Origin</code> , <code>Access-Control-Allow-Methods</code> , and <code>Access-Control-Allow-Headers</code></p>
  
  <pre><code>const HEADERS = {
      'Accept': 'application/json',
      'Content-Type': 'application/json',
      'Access-Control-Allow-Origin':  'http://localhost:3000/',
      'Access-Control-Allow-Methods': 'POST',
      'Access-Control-Allow-Headers': 'X-Requested-With,content-type'
  };
  </code></pre>
  
  <p>However, the error still persist. How can i solve this ?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>exports.uploadFile = functions.https.onRequest((req, res) =&gt; {
          res.setHeader("Access-Control-Allow-Origin", "*");
  
          res.setHeader('Access-Control-Allow-Methods', 'GET,POST,DELETE,HEAD,PUT,OPTIONS');
          res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
  
  
      res.status(200).json({
          message: req.body
      });
  });
  </code></pre>