A LevelDB backed URL unshortening microservice written in JavaScript
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
commands
.dockerignore
.gitignore
.travis.yml
Dockerfile
LICENSE
Makefile
README.md
index.js
package-lock.json
package.json
test.js

README.md

unshrtn

Build Status

unshrtn is a LevelDB backed URL unshortening microservice written in JavaScript and Node for quick, asynchronous processing of requests. unshrtn remembers what it has already looked up so it can save you the trouble of keeping track of URLs when you are looking up a lot of them at one time and they haven't necessarily been de-duplicated.

unshrtn uses the metaweb library to do the lookups, which means that in addition to returning the unshortened URL you will also get some potentially useful metadata if the response happens to be HTML:

% curl http://localhost:3000?url=https://bitly.com/4kb77v
{
  "short": "https://bitly.com/4kb77v",
  "long": "https://www.youtube.com/watch?v=oHg5SJYRHA0",
  "canonical": "https://www.youtube.com/watch?v=oHg5SJYRHA0",
  "status": 200,
  "content_type": "text/html; charset=utf-8",
  "title": "RickRoll'D - YouTube",
  "description": "http://www.facebook.com/rickroll548 As long as trolls are still trolling, the Rick will never stop rolling.",
  "image": "https://i.ytimg.com/vi/oHg5SJYRHA0/hqdefault.jpg",
  "publisher": "YouTube",
  "keywords": ["Cotter548", "Shawn", "Cotter", "lol", "gamefaqs", "CE", "reddit", "rettocs", "no", "brb", "afk", "lawl", "pwnt", "Rickroll", "Rickroll'd", "Rick", "Roll", "Duckroll", "Duck", "rick", "roll", "astley", "..."]
}

Install

Probably the easiest way to get unshrtn up and running is with Docker.

docker run -p 3000:3000 docnow/unshrtn

You can also install it with npm:

% npm install -g unshrtn

Usage

Once installed you can start up the microservice:

% unshrtn start

If you'd like more control over how it starts use the start subcommand:

% unshrtn start --host 0.0.0.0 --port 8080 --log /var/log/unshrtn.log

By default unshrtn writes its database to unshrtn.db in the current working directory. However you can control this with the --database option:

% unshrt start --database /var/unshrtn/unshrtn.db

You can dump the database as line oriented JSON and load it againif you want to back it up or move it around:

% unshrtn dump /path/to/datbase > backup.jsonl
% cat backup.jsonl | unshrtn load /path/to/another/database

If you just want to look up one URL you can also use unshrtn on the command line:

% unshrtn get https://bitly.com/4kb77v