Projects
zbi.baby

zbi.baby

Static URL compressor and QR code optimizer — stateless, database-free URL shortener.

sourcelive

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), emoji strings, and path-safe qr codes.
  • Developer Friendly: Clean REST API with open CORS, text/plain bot 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 in docs/ are served directly by Cloudflare’s edge asset cache without invoking Worker compute. All non-static routes fall through to api/worker.js.

Essential wrangler.toml requirements:

  • html_handling = "none": Prevents redirection of 404.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.
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

  1. Protocol & Port Stripping: Protocol (http://, https://), common subdomains (www.), standard file endings (index.html), and ports are reduced to compact bit flags.
  2. Huffman Dictionary Matching: Domains and common TLDs match against pre-compiled Huffman-coded tree dictionaries.
  3. Path Segment Encoding: Remaining URL segments are partitioned and mapped to character-optimized sets or Huffman trees.
  4. 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: