Stanislavja / serverlessURLfauna

Home Page:serverless-url-fauna.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serverless URL Shortener

Deploy your own based on bendechrai code

but without tracking clicks or IPs for enhanced privacy compliance

Vecel and Fauna accounts

Sign up for a Vercel and Fauna account if you don't have them already, and install the now command-line utilities.

Clone and deploy!

push

Now run the following in your terminal:

git clone https://github.com/gurugeek/serverless-url-shortener-redirector.git
cd url-shortener
now --prod

Integrate Fauna into Zeit

  1. Create a new Fauna Database called url-shortener;
  2. Add the Fauna Integration into your Vercel account;
  3. Create a new Fauna Database Server Key for your new database and copy the key;
  4. Create one collection in the database, called redirects;
  5. In the redirects collection, create an index called all_redirects, set the Terms field toshortcoded; and
  6. Paste this key into Vercels's Fauna Integration setup when prompted, and link the Fauna database with the new Vercel project created during deployment.

Managing redirects

One at a time

Head to the redirects collection, click on New Document, and enter something in the following format:

{
  "shortcode": "twitter",
  "dest": "https://twitter.com"
}

Multiples

If you are migrating from another system, you can generate a script that looks like this:

Create(Collection("redirects"), { data: { "shortcode": "contact", "dest": "https://bendechrai.com/contact/" } });
Create(Collection("redirects"), { data: { "shortcode": "github", "dest": "https://github.com/bendechrai" } });
Create(Collection("redirects"), { data: { "shortcode": "linkedin", "dest": "https://www.linkedin.com/in/bendechrai/" } });
Create(Collection("redirects"), { data: { "shortcode": "twitter", "dest": "https://twitter.com/bendechrai" } });
Create(Collection("redirects"), { data: { "shortcode": "youtube", "dest": "https://www.youtube.com/channel/UCY5SDWGg5Wa1ptwFF1EXQPg" } });

Take this, and paste it into the Fauna Web Shell.

Default redirect

If you go to the base URL of your URL Shortener (i.e. https://url-shortener.yourname.now.sh/), this system will look for a shortcode of __default__. Creating a record like this will let you set the destination for this scenario:

{
  "shortcode": "__default__",
  "dest": "https://bendechrai.com"
}

Duplicates

Currently, this redirector will fail if the shortcode cannot be found, or it is found more than once.

About

serverless-url-fauna.vercel.app


Languages

Language:JavaScript 100.0%