Shrinking URLs á la skill share.
This README file contains 3 main sections:
- Intro to Shrink
- Configuration
- Using the CLI
Shrink is a ver basic tool that, essentially, shrinks URLs via CLI using a REST API and MongoDB. It has two main components:
- The API: This enables all services to shrink and redirect to source URLs.
- The CLI: This is the official interface to access all Shrink functionality.
Shrink allows you to:
- Shrink any URL: You can use the CLI with the
this:
command to obtain the shrunk URL. See more details in the "Using the CLI" section below. - Get stats from any shrunk URL (or the 'original' URL, works both ways): You can use the CLI with the
stats:
command. - Toggle on/off any shrunk URL (or the 'original' URL): You can use the CLI with the
toggle:
command.
All of the configuration is defaulted, but you can base on the following snippet to create a .env
file with overrides to any (or all) of them:
# Database host/port config. (Default: mongodb://localhost:27017/shrink)
DB_HOST=mongodb://my.hosted.mongo.com:29000/shortenerdata
# Domain of your choice (Default: shri.nk)
DOMAIN=sho.rt
# Port override (Default: 80)
PORT=8080
# Protocol (Default: http)
PROTOCOL=https
You may want to add a line to your /etc/hosts
file to have nice routing to your defined domain (see above).
Our CLI works as a node command that is executed by npm. In turn, we advise you create an alias so that it can be used with ease:
alias shrink='npm run cli'
Run a local image of MongoDB to avoid installing anything:
docker pull mongo:3-xenial && docker run -d --name mongo-container -p 27017:27017 mongo:3-xenial
You can shrink an url by passing the command this:
. NOTE: This call is idempotent, meaning that it will return on every equal request the same shrunk URL after it has been shrunk the first time.
shrink this: http://www.skillshare.com
You can also retrieve stats of the times this shrunk URL has been used by passing the stats:
command.
shrink stats: http://shri.nk/emI05
Finally, your shrunk URL can be disabled temporarily, by passing the toggle:
command. It will return 409 if the URL is used while disabled. This call is a switch to alternate between 'enabled' and 'disabled' status.
shrink toggle: http://www.bbc.co.uk