A very simple url shortener based on fly.io, with request logging
Enable the Sheets API on your Google Cloud Platform project.
Create a service account on Google Cloud and download the JSON credentials. This will contain the service account email as well as the private key needed below.
It should have one sheet with the following columns in order. There can be other columns, these three just need to be next to each other in this order.
- From -- The URL path on the shortener
- ex.
/sat-event
- ex.
- To -- The destination URL. This supports using a special
YYMMDD
sequence that will be replaced with the current date (useful for tracking campaigns)- ex.
https://alongdomain.com/path/to/url?source=twitter-YYMMDD
- ex.
- Is Regex -- boolean column (
TRUE
orFALSE
) indicating whether the link record does regex matching- ex. From:
/event/(.*)$
To:https://eventplatform.com/event/$1
- ex. From:
Grant read access on the document to the service account email address.
Copy the document ID from the URL.
Copy the range of the short links in A1 notation.
See installation docs for platform-specific instructions.
cp .env.example .env
vi .env
Fly deprecated their Redis offering and now recommends running your own:
cp fly.redis.toml.example fly.redis.toml
vi fly.redis.toml
flyctl apps create --name myorg-redis
flyctl volumes create --app myorg-redis myorg_redis_server --region ewr --size 4
flyctl secrets set --app myorg-redis REDIS_PASSWORD="SomethingElseSecretAndComplicated"
flyctl deploy --config fly.redis.toml
cp fly.shortlinks.toml.example fly.shortlinks.toml
vi fly.shortlinks.toml
flyctl apps create --name myorg-shortlinks
Set application environment variables via Fly Secrets:
awk '!/^#/ && NF' .env | xargs -p flyctl secrets set --config fly.shortlinks.toml
flyctl deploy --config fly.shortlinks.toml