Serverless Link Shortener

Cloudflare Workers KV Storage REST API JavaScript HTML/CSS

Serverless Link Shortener

A blazing fast, private, and self-hosted URL shortener that operates entirely on Cloudflare Workers. It requires no traditional servers to maintain, incurs zero database costs under the free tier, and gives you 100% control over your routing data.

✨ Features

  • Global Low Latency: Runs on Cloudflare’s edge network for near-instant redirects.
  • Secure Admin Panel: Built-in GUI dashboard to manage links, protected by an environment variable password.
  • Link Management: Create, delete, and list all active short links through the dashboard.
  • Programmatic API: REST endpoints support automated link creation and deletion using Basic Authentication.

🧩 Tech Stack

  • Platform: Cloudflare Workers
  • Database: Cloudflare KV Namespace (SHORTLINKS)
  • Frontend (Admin): HTML / CSS / Vanilla JS

🛠️ Setup (CLI Method)

# Clone the repository
git clone [https://github.com/abduelmorsi/cflinkshortener.git](https://github.com/abduelmorsi/cflinkshortener.git)
cd link-shortener

# Install dependencies
npm install

# Create the KV Namespace
npx wrangler kv:namespace create SHORTLINKS

# Set your admin password securely
npx wrangler secret put ADMIN_PASSWORD

# Deploy to Cloudflare
npx wrangler deploy

⚙️ API Usage

You can programmatically add links by sending a POST request to /api/add with the slug and url form data, authorized via a base64 encoded string of your admin credentials.