This is a demonstrate how to use the Firebase Dynamic Link API to build the shorten URL app.
Target:
- Simple
- Fast
- Fast 😎
Live: https://s.duyet.net
-
Set up Node.js and the Firebase CLI
yarn global add firebase-tools
To initialize project: Run
firebase login
to log in via the browser and authenticate the firebase tool. -
Setup packages
cd functions/ && yarn cd hosting/ && yarn
-
Go to https://console.firebase.google.com and create new project.
-
Setup env variables, copy and modify
env.default.sh
toenv.local.sh
Get the
api_key
by Project settings > General > Web API KeyGet the
domain_uri_prefix
by Dynamic Links, then Add URL prefixfirebase functions:config:set config.api_key=AIzaSyC8mZm********** firebase functions:config:set config.domain_uri_prefix=duyet.page.link
Run:
bash ./env.local.sh
-
Update the frontend config:
hosting/gatsby-config.js
:
module.exports = {
siteMetadata: {
title: 'duyet shorten url',
description: 'Shorten URL by Firebase Dynamic Link',
author: '@duyet',
},
...
-
Running in local: https://firebase.google.com/docs/functions/local-emulator
- Export local configs:
firebase functions:config:get > functions/.runtimeconfig.json
- Start firebase function:
firebase serve
- Start hosting local in another terminal:
cd hosting && yarn develop
- Open the UI in browser: http://localhost:8000
- Export local configs:
Deploy serverless functions and hosting to Firebase
firebase deploy
MIT