Minimal short link system for https://schchn.gr
Simple url shortener on json base that matches short keys to urls and keeps track of the number of clicks including a small social suffix feature to differentiate the platform the link was clicked on.
Link is the main class of the project. You can lookup urls and create new keys:
You can lookup a given key with optional source platform. If the key is unknown
the method returns false
.
const link = require('./lib/Link').getInstance();
const url = link.lookup('MY_KEY');
If you want to add another url to the system you can do this with store
, that
requires the url that should be shortened. The default length of generated keys
is currently 5
characters. You can change that with the second parameter
keyLength
.
const key = link.store('https://schaechinger.com');
If the given url exists in the system already, you will of course get the current key for the url!
At the moment there are a few routes that define the basic needs of the system.
lookup
is used to get the url for a given short key and redirects the client to the link destination.add
can add a new short key with the information of theurl
that should be shortened and thesecret
token as defined in the config. The parameter have to be sent in the POST body of the request.error400
anderror404
are default JSON responses that notify the user that the link could not be added or the key was not found.
Currently the system comes without database support but can be added via an
adapter in future releases. The current version uses a simple links.json
file
in the ./data
directory.