title: CORS error when making Axios calls to Cloudrun service from Firebase hosted app
body: <p>This looks to be pretty obvious but I've been trying to figure it out for a couple of days now and still can't get it to work. Please, can someone point out what I'm missing.</p>
  
  <p>I'm trying to make an axios call to my cloud run service from my firebase hosted SPA. To isolate the issue I followed the steps outlined in the [firebase tutorial for cloud run] (<a href="https://firebase.google.com/docs/hosting/cloud-run#node.js" rel="nofollow noreferrer">https://firebase.google.com/docs/hosting/cloud-run#node.js</a>) </p>
  
  <p><strong>Step 4</strong> of the tutorial talks about setting up rewrite to use the firebase domain as a proxy to your cloud run service. It says that the <em>helloworld</em> service would be reachable via</p>
  
  <blockquote>
    <p>Your Firebase subdomains:
    <em>projectID</em>.web.app/helloworld and <em>projectID</em>.firebaseapp.com/helloworld</p>
  </blockquote>
  
  <p>So I follow the steps and deploy the service. Then I try to make an axios call to the service from the SPA like below</p>
  
  <pre><code>testHelloWorld () {
    axios.get(`https://myProjectId.firebaseapp.com/helloworld`)
       .then((data) =&gt; {
         console.log(data)
       })
       .catch(ex =&gt; {
          console.error(ex)
       })
    })
  }
  </code></pre>
  
  <p>But then I get the CORS error</p>
  
  <blockquote>
    <p>Access to XMLHttpRequest at '<a href="https://myProjectId.firebaseapp.com/helloworld" rel="nofollow noreferrer">https://myProjectId.firebaseapp.com/helloworld</a>' from origin '<a href="https://myFirabaseApp.firebaseapp.com" rel="nofollow noreferrer">https://myFirabaseApp.firebaseapp.com</a>' 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.</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/questions/55872735/ajax-request-to-cloud-run-service-that-requires-authentication">This answer</a> states that this should be possible so I'm not sure what I'm doing wrong.</p>
  
  <p><strong>N.B:</strong> </p>
  
  <p>While debugging, I updated the node app from the tutorial to add cors support like below. Still didnt work.</p>
  
  <pre><code>const express = require('express');
  const app = express();
  const cors = require('cors'); //Imported and added this
  
  app.use(cors()); // Used here
  
  app.get('/', (req, res) =&gt; {
    console.log('Hello world received a request.');
  
    const target = process.env.TARGET || 'World';
    res.send(`Hello ${target}!`);
  });
  
  const port = process.env.PORT || 8080;
  app.listen(port, () =&gt; {
    console.log('Hello world listening on port', port);
  });
  
  </code></pre>
  
  <p>So the question here is, how do I make an Axios/AJAX call to my cloud run service using the firebase rewrite rule?</p>