A stateless, database-free URL shortener.
Entire links are squeezed directly into the URL itself—no database, zero storage, no leaks, and no API keys required.
Live Web App • Interactive API Docs
Overview
zbi.baby is a production-ready fork of ha.mr hosted entirely on Cloudflare Workers & Cloudflare Pages (Static Assets).
- Zero-Storage Architecture: Links are compressed using Huffman coding and custom dictionaries; URLs decode client-side or on-the-fly at the edge.
- Unified Infrastructure: Static web assets and the JSON API run under a single Cloudflare Worker deployment using static asset routing.
- Multiple Output Modes: Standard URL fragments (
#hash),emojistrings, and path-safeqrcodes. - Developer Friendly: Clean REST API with open CORS,
text/plainbot responses, and a local CLI.
Quick Start & Deployment
Hosted on Cloudflare Workers & Pages
The frontend (docs/) and API (api/worker.js) deploy together under a single domain via Cloudflare Workers with asset hosting:
npm install
npx wrangler login
npm run deploy
Architecture Note:
Static files indocs/are served directly by Cloudflare’s edge asset cache without invoking Worker compute. All non-static routes fall through toapi/worker.js.Essential
wrangler.tomlrequirements:
html_handling = "none": Prevents redirection of404.html(which preserves QR route payloads).[assets]: Required to serve the frontend app shell directly from the edge.
Local Development
Run the full stack via Docker or Node:
# Full stack (Nginx web server on :8080 + Node API)
docker compose up -d --build
# Standalone API server only (:3000)
npm start
| Environment Variable | Default | Purpose |
|---|---|---|
PORT |
3000 |
Port for the local Node server |
PUBLIC_URL |
https://zbi.baby |
Base domain for generated links |
MAX_URL_LENGTH |
2048 |
Maximum acceptable link length (bytes) |
API Reference
Base Endpoint: https://zbi.baby/api/v1
1. Shorten a URL
# Standard JSON output
curl -G "https://zbi.baby/api/v1/shorten" \
--data-urlencode "url=https://example.com/very/long/path"
# Plaintext output (optimized for bots and scripts)
curl -H "Accept: text/plain" "https://zbi.baby/api/v1/shorten?url=https://example.com/very/long/path"
# POST (JSON body)
curl -X POST "https://zbi.baby/api/v1/shorten" \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/very/long/path"}'
Encoding Modes (mode parameter):
hash(default): Stores payload in fragment (#...). Zero server exposure.emoji: Encodes the fragment into an emoji sequence.qr: Encodes directly into the path (/OQ...). Ideal for QR printing and bot unfurling.
2. Expand a Short Link
curl -G "https://zbi.baby/api/v1/expand" \
--data-urlencode "link=https://zbi.baby#OQ/ap#"
Discord Bot Example (discord.py)
Using mode=qr ensures links are path-based and reliably unfurled by scrapers and chat bots:
import requests
response = requests.get(
"https://zbi.baby/api/v1/shorten",
params={"url": url, "mode": "qr"},
headers={"Accept": "text/plain"},
timeout=5,
)
response.raise_for_status()
await ctx.send(response.text.strip())
CLI Usage
Encode and decode URLs directly from your terminal:
# Encode
node standalone.js https://example.com/some/long/path
# Decode (wrap in quotes to preserve fragment symbols)
node standalone.js "https://zbi.baby#OQ/ap#"
# Encode for QR (path-safe alphabet)
node standalone.js https://example.com/some/long/path qr
Testing
npm test # Test against local Docker stack
BASE_URL=https://zbi.baby npm test # Run suite against production
Runs a 19-test suite validating CORS headers, payload modes, bot user-agents, error handling, and plain-text formats.
How It Works
- Protocol & Port Stripping: Protocol (
http://,https://), common subdomains (www.), standard file endings (index.html), and ports are reduced to compact bit flags. - Huffman Dictionary Matching: Domains and common TLDs match against pre-compiled Huffman-coded tree dictionaries.
- Path Segment Encoding: Remaining URL segments are partitioned and mapped to character-optimized sets or Huffman trees.
- Alphanumeric Output: For QR modes, output is constrained to alphanumeric tables to minimize matrix density.
Acknowledgements & Upstream
Forked and maintained from ha.mr by p2r3 (MIT Licensed).
Special thanks to:
- lean-qr for lightweight QR generation.
- reddit_links_dataset and url-dataset for compression training corpuses.
