Skip to content

Files

Latest commit

author
Nicolas Garnier
Jun 29, 2017
c9a7e03 · Jun 29, 2017

History

History
This branch is 743 commits behind firebase/functions-samples:main.

url-shortener

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jun 29, 2017
Apr 28, 2017

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 Google URL Shortener API.

The dependencies are listed in functions/package.json.

Sample Database Structure

We'll be using a simple database structure:

/functions-project-12345
    /links
        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.

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