This is a web server that can be used to encode a short message in a URL. It also serves a page at that URL, containing the message and a QR code pointing to that URL. Unlike with a URL shortener, the URL contains the full message in a compressed form so there is no need to store relations between messages and URLs server-side, and any URL that can be uncompressed to a message is automatically served. While this approach is appealing because it means no database or server state, the tradeoff is that messages must be short enough that their compressed URL form fits inside a QR code.
There is a live instance of this server at qr.samflam.com.
When compressing a message the server runs an ensemble of compression algorithms and chooses the one with the best compression ratio for the particular message. A 1-byte value is prepended to the compressed data indicating the algorithm that was used, which simplifies later decompression. Supported compression algorithms include:
- trivial - No compression. Acts as fallback if everything else behaves poorly.
- zlib - General lossless compressor.
- smaz - Optimized for very short english text.
- xz - Similar to zlib but has a slightly worse compression ratio in my testing. Disabled by default.
- bwtc - Similar to zlib and has a slightly better compression ratio in some cases.
It's straightforward to add new algorithms to the ensemble as desired. The final URL is generated by encoding this compressed byte array in a URL-safe base64 string.
This project requires node and yarn. In the cloned repo, first do
yarn install
to install dependencies.
Then do
yarn start
to run the server. You can also do
yarn dev
to run with nodemon, which automatically restarts the server whenever the source code changes.
By default the server generates QR codes for and runs on http://localhost:8000
. You can change this with environment variables:
Variable | Description |
---|---|
QRMIRROR_PORT |
The port the server should listen on. Defaults to 8000. |
QRMIRROR_PREFIX |
The first part of the public URL including protocol and domain. Change this to match the URLs you want the QR codes to point to. Defaults to http://localhost:${QRMIRROR_PORT} . |
QRMIRROR_ENSEMBLE_STATS |
If enabled, the default ensemble compressor console logs size statistics for all its members when processing a message. Enable by setting to a non-empty value. This is enabled automatically with yarn dev . |
If you have questions or issues running the server please feel free to open an issue.
I do my testing and devlopment on a linux machine, so your mileage may vary on other platforms.