A very simple url shortener based on fly.io, with request logging
  • TypeScript 93.7%
  • Dockerfile 5.2%
  • Shell 0.7%
  • JavaScript 0.4%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Benjamin Chrobot 34728638b8
chore: update example configurations (#39)
Fly has made changes to Apps V2 [1]. Rewired's applications have been automatically migrated,
including updating configuration. This commit captures the changes to configuration based on Fly's
update command:

fly config save

[1] https://community.fly.io/t/get-in-losers-were-getting-off-nomad/12914

Reviewed-by: @hiemanshu
2023-06-01 17:01:26 -04:00
.github/workflows build: upgrade to node v16 lts 2022-03-29 07:31:14 -04:00
.husky chore: add standard tooling 2021-03-07 18:02:36 -05:00
src fix: skip executing empty key deletes 2022-03-29 09:04:50 -04:00
types style: lint and format codebase 2021-03-07 17:54:43 -05:00
.dockerignore build: add dockerfile 2021-03-07 16:40:59 -05:00
.env.example docs: update documentation with redis instructions 2022-03-30 10:07:16 -04:00
.eslintignore chore: add eslint and prettier 2021-03-07 17:50:12 -05:00
.eslintrc.js chore: add eslint and prettier 2021-03-07 17:50:12 -05:00
.gitignore docs: update documentation with redis instructions 2022-03-30 10:07:16 -04:00
.prettierignore chore: add eslint and prettier 2021-03-07 17:50:12 -05:00
.prettierrc.js chore: add eslint and prettier 2021-03-07 17:50:12 -05:00
.versionrc.js chore: sign releases 2021-08-30 10:07:15 -04:00
CHANGELOG.md chore(release): 1.3.2 2022-03-29 09:04:58 -04:00
commitlint.config.js chore: add standard tooling 2021-03-07 18:02:36 -05:00
Dockerfile build: upgrade to node v16 lts 2022-03-29 07:31:14 -04:00
fly.redis.toml.example chore: update example configurations (#39) 2023-06-01 17:01:26 -04:00
fly.shortlinks.toml.example chore: update example configurations (#39) 2023-06-01 17:01:26 -04:00
LICENSE docs: add mit license 2021-03-07 08:50:49 -05:00
package.json chore(release): 1.3.2 2022-03-29 09:04:58 -04:00
README.md docs: update documentation with redis instructions 2022-03-30 10:07:16 -04:00
tsconfig.json style: lint and format codebase 2021-03-07 17:54:43 -05:00
yarn.lock fix: remove ioredis-mock 2022-03-29 08:22:58 -04:00

fly-shortener

A very simple url shortener based on fly.io, with request logging

Getting Started

Create Service Account

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.

Create Google Sheets Doc

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.

  1. From -- The URL path on the shortener
    • ex. /sat-event
  2. 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
  3. Is Regex -- boolean column (TRUE or FALSE) indicating whether the link record does regex matching
    • ex. From: /event/(.*)$ To: https://eventplatform.com/event/$1

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.

Install fly

See installation docs for platform-specific instructions.

Configure Secrets

cp .env.example .env
vi .env

Launching Redis Application

Fly deprecated their Redis offering and now recommends running your own:

Create Fly Configuration

cp fly.redis.toml.example fly.redis.toml
vi fly.redis.toml

Launch Application

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

Create Fly Configuration

cp fly.shortlinks.toml.example fly.shortlinks.toml
vi fly.shortlinks.toml

Create Fly Application

flyctl apps create --name myorg-shortlinks

Configure Secrets

Set application environment variables via Fly Secrets:

awk '!/^#/ && NF' .env | xargs -p flyctl secrets set --config fly.shortlinks.toml

Launch Application

flyctl deploy --config fly.shortlinks.toml