shorten
Minimal secure URL shortener
Summary
| Latest Version | 0.2.0 |
|---|---|
| License | MIT |
| CI Status | Failing |
| Downloads | 0 |
| Last Indexed | 2026-09-04 07:26 |
Tags
Authors
- Carlo Capocasa
Installation
nimble install shorten
choosenim install shorten
git clone https://github.com/capocasa/shorten
OS Compatibility
| Platform | Linux | macOS | Windows | FreeBSD | OpenBSD | NetBSD | Android | iOS | WASM | Embedded |
|---|---|---|---|---|---|---|---|---|---|---|
| shorten | ✓ | ✓ | ✓ | - | - | - | - | - | - | - |
Dependencies
| Package | Version | Optional |
|---|---|---|
| nim >= | 2.0.0 | No |
| limdb | - | No |
| httpbeast#master | - | No |
| libsha | - | No |
Source
| Repository | https://github.com/capocasa/shorten |
|---|---|
| Homepage | https://github.com/capocasa/shorten |
| Registry Source | nimble_official |
README
shorten
A minimal, secure URL shortener written in Nim.
Server
shortend is a headless HTTP server backed by an embedded LMDB database.
Write operations require bearer token authentication.
Build
nimble build
Token Setup
Generate a hash for your secret token:
$ export NIMSHORT_TOKEN=mysecrettoken
$ shortend
a1b2c3d4...
The hash is printed to stderr and the program exits. Use it in the systemd config below.
Systemd
# /etc/systemd/system/shortend.service
[Unit]
Description=shortend
After=network.target
Wants=network-online.target
[Service]
DynamicUser=True
ExecStart=shortend
Restart=always
NoNewPrivileges=yes
PrivateDevices=yes
PrivateTmp=yes
ProtectHome=yes
ProtectSystem=full
Environment=NIMSHORT_HASH=<your-hash> NIMSHORT_PORT=7071
StateDirectory=shortend
WorkingDirectory=%S/shortend
[Install]
WantedBy=multi-user.target
systemctl enable --now shortend
Nginx
Proxy all requests to shortend, serving static files first if they exist:
server {
server_name short.url;
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/letsencrypt/live/short.url/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/short.url/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
root /var/www/short.url;
location / {
try_files $uri @shortend;
}
location @shortend {
proxy_pass http://127.0.0.1:7071;
proxy_buffering off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
}
API
PUT /<key> Auth: Bearer <token> Body: <url> → 201
GET /<key> → 301 redirect
HEAD /<key> → 200 / 404
DELETE /<key> Auth: Bearer <token> → 201 / 404
CLI
The shorten command is a companion CLI tool included in the same package.
Setup
Add to ~/.bashrc:
export SHORTEN_KEY=mysecrettoken
export SHORTEN_URL=https://short.url
Usage
# Shorten a URL
shorten https://example.com/very/long/url
# https://short.url/abcdef
# Pipe from stdin
echo https://example.com/long | shorten
# Look up a short URL
shorten get abcdef
# https://example.com/very/long/url
# Delete a short URL
shorten delete abcdef
Changelog
0.2.0 Rename to shorten, add CLI tool
0.1.0 Minimal secure headless URL shortener
License
MIT