title: How to allow specific domain to access cloud functions
body: <p>I am using firebase cloud functions and at the first time I saw cors then set origin to true.. but in that way anyone can access to my functions, so I looked a way to allow only specific domains to access my cloud functions, I got the code from cors github page and tried it, but I get unexpectedly closed the connection after waiting and waiting.</p>
  
  <p>here is my function index.js --</p>
  
  <pre><code>const functions = require('firebase-functions');
  const cors = require('cors');
  
  var whitelist = ['http://example1.com', 'http://example2.com']
  var corsOptionsDelegate = function (req, callback) {
    var corsOptions;
    if (whitelist.indexOf(req.header('Origin')) !== -1) {
      corsOptions = { origin: true } // reflect (enable) the requested origin in the CORS response
    }else{
      corsOptions = { origin: false } // disable CORS for this request
    }
    callback(null, corsOptions) // callback expects two parameters: error and options
  }
  
  exports.api = functions.https.onRequest((req, res) =&gt; {
  cors(req, res, () =&gt; {  
      var d = new Date();
     var n = d.getHours();
    if (n &gt; 8 &amp;&amp; n &lt; 17) {
      res.status(200).send("Get started")
    } else {
      res.status(200).send("Closed")
    } 
  })
  });
  </code></pre>