title: Firebase Cloud Function CORS issue in TypeScript
body: <p>i know there are tons of CORS post and solutions and i been going through them many times. No luck to resolve my CORS issue after hours and i decided to post here :)</p>
  
  <p>my client angular method
  imported and initialized package</p>
  
  <pre><code>...import { AngularFireFunctions } from "@angular/fire/functions";
    constructor(...
      private afn: AngularFireFunctions,
    ) {}
  </code></pre>
  
  <pre><code>  initCloudFunctions() {
      let cmd = "helloWorld";
      const callable = this.afn.httpsCallable(cmd);
      let data = callable({ name: "some-data" }).subscribe({
        next(res) {
          console.log("res: ", res);
        },
        error(msg) {
          console.log("Error : ", msg);
        }
      });
    }
  </code></pre>
  
  <p>My firebase cloud-function (in TypeScript), index.ts</p>
  
  <pre><code>export const helloWorld = functions.https.onRequest((request, response) =&gt; {
      response.set('Access-Control-Allow-Origin', '*');
      // let url = 'https://a1rvv0rk2.stackblitz.io/main/firecp'
      // response.set('Access-Control-Allow-Origin', url);
      response.set('Access-Control-Allow-Credentials', 'true');
      response.set('Access-Control-Allow-Headers', 'Content-Type')
  
      response.send("Hello from Firebase! " + new Date());
  });
  </code></pre>
  
  <p>i have used wildcard but yet i still get CORS error</p>
  
  <blockquote>
    <p>Access to fetch at '<a href="https://...my" rel="nofollow noreferrer">https://...my</a> project
    ....cloudfunctions.net/helloWorld' from origin '<a href="https://..my" rel="nofollow noreferrer">https://..my</a> project
    ....stackblitz.io'  has been blocked by CORS policy: Request header
    field authorization is not allowed by Access-Control-Allow-Headers in
    preflight response. zone.js:1118 
    POST <a href="https://...my" rel="nofollow noreferrer">https://...my</a> project
    .....cloudfunctions.net/helloWorld net::ERR_FAILED</p>
  </blockquote>
  
  <p>really appreciate if i could get some helps from gurus.</p>
  
  <p>Updates:
  Thanks Doug, and <a href="https://www.youtube.com/watch?v=H0rZnxRV7_k" rel="nofollow noreferrer">Lars from youtube</a>, i managed to import CORS successfully!
  here my updated code and hope it helps for those using TypeScript rather than JavaScript</p>
  
  <p><em>import CORS lib</em></p>
  
  <pre><code>import * as corsModule from 'cors'
  const cors = corsModule(({ origin: true }))
  </code></pre>
  
  <p><em>Cloud Function</em></p>
  
  <pre><code>export const helloWorldWithCORS = functions.https.onRequest((request, response) =&gt; {
      // ref: https://github.com/firebase/firebase-js-sdk/issues/1338#issuecomment-461234192
      cors(request, response, () =&gt; {
          response.status(200).send({data: { success: true, message: 'yeah!' }})
      })
  });
  </code></pre>
  
  <p><em>Angular App</em></p>
  
  <pre><code> async initCloudFunctions() {
      // let cmd = "helloWorld";
      let cmd = "helloWorldWithCORS";
      const callable = this.afn.httpsCallable(cmd);
  
      this.data = await callable({name: 'some data'})
      console.log(this.data)
    }
  </code></pre>