title: Cloud Functions for Firebase: 'Error: could not handle the request'
body: <p>I feel like pulling my hair out; this is either super simple and i'm having brain freeze or it is not that simple.</p>
  
  <h2>What I want</h2>
  
  <p>I am trying to unshorten a shortened URL using firebase, when a user goes to:<br>
  <code>myapp.firebaseappurl.com/url/SHORTENEDLINK</code><br>
  <em>SO wont let me add a shortened URL</em></p>
  
  <p>I would like the output to be:</p>
  
  <pre><code>{
    "url": "https://stackoverflow.com/questions/45420989/sphinx-search-how-to-use-an-empty-before-match-and-after-match"
  }
  </code></pre>
  
  <h2>What I have tried</h2>
  
  <p><code>firebase.json</code> file:</p>
  
  <pre><code>{
    "hosting": {
      "public": "public",
      "rewrites": [ {
      "source": "/url/:item",
        "destination": "/url/:item"
      } ]
    }
  }
  </code></pre>
  
  <p><code>index.js</code> file:</p>
  
  <pre><code>const functions = require('firebase-functions');
  
  exports.url = functions.https.onRequest((requested, response) =&gt; {
  
      var uri = requested.url;
      request({
          uri: uri,
          followRedirect: true
        },
        function(err, httpResponse) {
          if (err) {
            return console.error(err);
          }
          response.send(httpResponse.headers.location || uri);
        }
      );
  
  });
  </code></pre>
  
  <h1>Result</h1>
  
  <p>When I go to <code>myapp.firebaseappurl.com/url/SHORTENEDLINK</code> I get the following: </p>
  
  <pre><code>Error: could not handle the request
  </code></pre>