A JavaScript URL shortener running in Node.js.
Download the folder and open config.json in a text editor.
You can specify the port, the domain you're serving and the path to the create-short-url function.
-
myPort should be 80 if the app is running on its own server. If it's running behind another server you might want to use another port.
-
rootDomain is the domain you're allocating URLs from. My domain is pocalyp.se. Your domain will obviously be something else. It must point to this server via DNS using a wildcard so that all sub-domains also point to this server.
-
createPath is like a password, so it should be something fairly random. If you leave it at its default value anyone who knows your domain will be able to allocate URLs. Maybe this is what you want? If so, leave it as-is.
config.json is also where we store all the data for the server, including the URL mappings, and hit counts, etc.
Open the file in a text editor after launching the server to see the values it initializes. And you can watch it as it the app is running through the /status endpoint.
A source listing that preserves the outline structure of the code might be useful for some.
We maintain a folder of static files, arranged by domain, one for each URL.
The files contain the HTML needed to convert the shortener to a static site. You can drop those folders into the domains folder of PagePark, for example, and point the root domain at the server, it will serve the files.
I added this feature because eventually all servers go away, and when this one does, I want to be able to easily keep the links from breaking.
The home page of each sub-domain is now a JSON listing of all the items posted on that domain.
Ask on the server-snacks mail list.