title: Cors - Access-Control-Allow-Origin Error in firebase cloud functions
body: <p>This is the error I'm getting :</p>
  
  <pre><code>Access to XMLHttpRequest at has been blocked by CORS policy: Response to preflight request 
  doesn't pass access control check: 
  No 'Access-Control-Allow-Origin' header is present on the requested resource.
  </code></pre>
  
  <p>This is my cloud function: </p>
  
  <pre class="lang-js prettyprint-override"><code>...
  app.use(cors({
    origin: true,
  }))
  app.use(express.json());
  app.use(express.urlencoded({extended: false}));
  
  
  app.post('/submit', async (req, clientRes) =&gt; {
  ...
  }
  
  exports.app = functions.region('europe-west2').runWith({timeoutSeconds: 540, memory: '2GB'}).https.onRequest(app);
  </code></pre>
  
  <p>This is the post request I'm making from the client side:</p>
  
  <pre class="lang-js prettyprint-override"><code>axios.post('/submit', body, {headers: {
        // 'Access-Control-Allow-Origin': '*',
        'Content-Type': 'application/json',
      }});
  </code></pre>
  
  <p>I tried setting the <code>Access-Control-Allow-Origin: '*'</code>, <code>Access-Control-Allow-Origin: mydomain.com</code> and also <code>Access-Control-Allow-Origin: cloudFunctionDomain.net</code> but it is still not working.</p>
  
  <p>Help would be very much appreciated.</p>