MylesBorins / shortlink

Using HTML in ways it was not meant for in the name of convenience

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shortlink

omg this actually works

What is this?

Did you know that there is an HTML meta tag that you can use to redirect traffic

<meta http-equiv="refresh" content="0; URL='$URL'" />

It turns out you can build an entire URL shortening service on top of this with just Cloud Storage, HTML, a CDN, and a tiny bit of rsync.

Setup

Backend infrastructure

To get this working you need to have a GCS bucket setup that is serving HTTP content publically

You can find a tutorial on setting this up on the GCP website.

I have cloudflare setup in front of the bucket as a global CDN and to enable SSL via HTTPS.

I should write a blog about this at some point, open an issue if you need some pointers.

gcloud sdk

This shortlink script uses gsutil rsync to upload your shortlinks to gcs. You can get gsutil by installing the gcloud sdk. After installing the sdk run gcooud init to get everything setup properly. You are going to want to provision the CLI to use the project you created the GCS bucket in.

install shortlink

To install shortlink run the install script

$ ./install <BUCKET_URL> [INSTALL_LOCATION]
  • BUCKET_URL is the URL for your bucket not including gs: or any slashes
    • example: ./install kni.sh
  • INSTALL_LOCATION is the location on disc to install the shell script
    • default is $HOME/.bin
    • example: ./install kni.sh $HOME/.also_bin

After install you will need to add $HOME/.bin, or your custom install location, to your path.

Usage

$ shortlink <URL> [NAME]
  • URL is the path you want to shortlink to redirect to
  • NAME is a custom name for the shortlink

License

MIT

About

Using HTML in ways it was not meant for in the name of convenience

License:MIT License


Languages

Language:Shell 75.5%Language:HTML 24.5%