URL Shortener built as a single Cloudflare Worker with analytics and caching.
pnpm installCreate the D1 database and KV namespace and update wrangler.jsonc:
pnpm dlx wrangler d1 create shortener-db
pnpm dlx wrangler kv namespace create LINKS_CACHEApply the schema:
pnpm run db:migrate:local # Local
pnpm run db:migrate:remote # ProductionSet the secret:
# Local
cp .dev.vars.example .dev.vars
# Production
pnpm dlx wrangler secret put SECRETpnpm run dev
pnpm run typecheck
pnpm run tail # Stream logs from the deployed workerpnpm run deploySet in wrangler.jsonc under vars:
SITE_URLWhereGET /redirects to.ALLOWED_ORIGINOrigin allowed to call/api/*(use*for any origin).SHORT_URLURL used to build theshortUrlfield.