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
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
requires the url that should be shortened. The default length of generated keys
5 characters. You can change that with the second parameter
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.
lookupis used to get the url for a given short key and redirects the client to the link destination.
addcan add a new short key with the information of the
urlthat should be shortened and the
secrettoken as defined in the config. The parameter have to be sent in the POST body of the request.
error404are 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