Skip to content

A blazing fast link shortener built on CloudFlare Workers KV that allows you to set custom metadata to the shortened link.

License

Notifications You must be signed in to change notification settings

radiantly/the-redirector

Repository files navigation

The Redirector

A blazingly fast link shortener built on CloudFlare Workers KV that also allows you to set custom metadata to the redirected link.

Custom metadata? What do you mean?

When it comes to messaging apps like Discord, WhatsApp or Slack, you're probably familiar with the fact that when you send a link in chat, a link preview is generated. But what if I told you—the link preview is a lie! Generated link previews actually depend on something called Open Graph meta tags, which this link shortner allows you to conveniently set 😎

Here's a few of examples of how you can set the link previews to anything you'd like it to be.

Installation

  1. Install Wrangler
cargo install wrangler
  1. Clone this repository locally
git clone https://github.com/radiantly/the-redirector
cd the-redirector

# Copy the sample config file
cp wrangler.example.toml wrangler.toml
  1. Add your config to wrangler.toml (your account ID, KV namespace, etc)
  2. Build and publish
npm install
npm run build
wrangler publish

Contributing

Before contributing patches, you may need a CloudFlare Workers account to test changes locally. The key files used in the project are:

  • worker.js - This is the code that runs in the backend
  • public/ - These files are served on the frontend
  • staticpack.js - This is a script that bundles the files in public and worker.js to a single index.js which is the final file that is served.

To test your changes,

npm run build
wrangler run dev
# or
wrangler preview

Furthermore, if you use linux, you can use npm run dev or npm run preview to automatically build and run every time you save a file.

History

This project first started out as a repo for a list of internet pranks, aptly named box-of-tricks, and was built as a project for the MLH Hack-or-treat hackathon by Team Cheesy (comprising of my friend Jason and I). We came up with 3 pranks, a fake mouse, an infinite app opener vb script, and the redirect prank (inspired from jere-mie/routing-prank). For the redirect prank, we used CockroachDB (one of the sponsor technologies) but never got it completely working.

I dearly wanted to get the redirect prank working, so I rewrote the logic with Next.js and Airtable. This just so happened to be the wrong tool for the job with multiple caveats. There were issues generating the redirect page, and it frankly wasn't fast enough.

The project was then moved to CloudFlare workers.

License

MIT License.

About

A blazing fast link shortener built on CloudFlare Workers KV that allows you to set custom metadata to the shortened link.

Topics

Resources

License

Stars

Watchers

Forks