Self-hosted URL shortener on Cloudflare (Worker + KV)
  • JavaScript 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-11 17:42:25 +02:00
src tiny.vaked.dev — self-hosted URL shortener (Cloudflare Worker + KV, token-gated, themed form) 2026-07-11 17:42:25 +02:00
.gitignore tiny.vaked.dev — self-hosted URL shortener (Cloudflare Worker + KV, token-gated, themed form) 2026-07-11 17:42:25 +02:00
package.json tiny.vaked.dev — self-hosted URL shortener (Cloudflare Worker + KV, token-gated, themed form) 2026-07-11 17:42:25 +02:00
README.md tiny.vaked.dev — self-hosted URL shortener (Cloudflare Worker + KV, token-gated, themed form) 2026-07-11 17:42:25 +02:00
wrangler.toml tiny.vaked.dev — self-hosted URL shortener (Cloudflare Worker + KV, token-gated, themed form) 2026-07-11 17:42:25 +02:00

tiny.vaked.dev

A self-hosted URL shortener on Cloudflare (Worker + KV). Private: creating links requires a Bearer token; anyone can follow a short link.

  • GET / — themed landing page with a create form (paste your token; kept in localStorage).
  • GET /:slug — 302 redirect to the target (increments a click counter).
  • POST /api/shorten — create a link. Requires Authorization: Bearer <SHORTEN_TOKEN>. Body: { "url": "https://…", "slug": "optional-custom" } → { slug, url, short }.
  • GET /health — { ok: true }.

Deploy

npm install
npx wrangler kv namespace create LINKS      # put the id in wrangler.toml
npx wrangler deploy                          # custom domain: tiny.vaked.dev
echo -n '<your-secret>' | npx wrangler secret put SHORTEN_TOKEN
# (if npx trips the nvm shim, use: node node_modules/wrangler/bin/wrangler.js secret bulk sec.json)
curl -X POST https://tiny.vaked.dev/api/shorten \
  -H "authorization: Bearer $SHORTEN_TOKEN" -H "content-type: application/json" \
  -d '{"url":"https://example.com/long","slug":"demo"}'

Note: the vaked.dev zone has a Cloudflare bot rule (error 1010) that blocks default script User-Agents — send a normal User-Agent header from scripts. Browsers are unaffected.

Stack

Cloudflare Worker (src/index.js, module syntax) + Workers KV (LINKS). No build step. pocoo-themed UI. MIT.