Pull request Compare This branch is 6 commits ahead, 146 commits behind Node-8.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Shortens URLs automatically using the Google URL Shortener API.

This template shows how to shorten URLs automatically as they are added.

Functions Code

See file functions/index.js for the code.

This uses the Bit.ly API.

The dependencies are listed in functions/package.json.

Setting up the sample

  • Create a Firebase project using the Firebase Console.
  • Create a Bit.ly application and generate an Access Tokens.
  • Set the sample ot use your Firebase project using firebase use --add and select your new Firebase project.
  • Set your Bit.ly app's access token on your function by running:
    firebase functions:config:set bitly.access_token=XXXXXXXXXXXXX
  • Deploy the function using firebase deploy
  • Manually add an object to the Realtime Database following the structure described below.

Sample Database Structure

We'll be using a simple database structure:

        link-123456: "https://my.super.long-link.com/api/user/profile/-jEHitne10395-k3593085"

When a new URL (string) is pushed to /links, it gets replaced with an object containing the original URL and a shortened one. This way, you can display a clean URL by fetching /links/$linkId/short.

            original: "https://my.super.long-link.com/api/user/profile/-jEHitne10395-k3593085",
            short: "https://goo.gl/EKDdza"