A Simple Short URL Service on Cloudflare Workers
Sometimes you just need a short link. Maybe for a talk, a project, or a social media bio. You could sign up for yet another third-party service, but what if you could run your own, completely free, on the edge? That's exactly what this Cloudflare Workers Shortlink project does.
It's a minimal, self-hosted URL shortener that lives entirely on Cloudflare's global network. No databases to manage, no servers to provision—just a single Worker script and a KV store for the mappings. It’s the kind of project that solves a real problem with a beautifully simple stack.
What It Does
This project is a fully functional URL shortener. You give it a long URL and a short key (like my-project), and it stores that pairing in Cloudflare KV. When someone visits yourdomain.com/my-project, the Worker intercepts the request, looks up the key, and redirects them to the full URL instantly. It’s fast, global, and costs nothing to run for personal or moderate use.
Why It's Cool
The clever part is in the simplicity and the platform choice. By using Cloudflare Workers and KV, the entire service is serverless and runs at the edge—close to your users. The setup is incredibly lean: one JavaScript file for the Worker logic and a bit of configuration.
It also embraces developer control. You own the domain and the data. The redirect mappings live in your KV store, and you can manage them directly or, as the repo suggests, potentially extend it with a simple admin interface. It’s a perfect example of using the modern serverless edge to build a classic utility with almost zero overhead.
How to Try It
Getting your own instance running is straightforward. You'll need a Cloudflare account with Workers enabled.
- Fork or clone the repository.
- Install the Wrangler CLI and log in:
npm install -g wrangler && wrangler login - In the project directory, create a KV namespace:
wrangler kv:namespace create "SHORT_LINKS" - Update the
wrangler.tomlfile with your new KV namespace ID. - Run
wrangler deployto push your Worker live.
You can then start adding links by writing directly to your KV store (wrangler kv:key put --binding=SHORT_LINKS "my-key" "https://long-url.com"). Point your domain or a subdomain to the Worker in the Cloudflare dashboard, and you're in business.
Final Thoughts
This isn't a sprawling enterprise tool, and that's its strength. It’s a focused, practical script that demonstrates how powerful the edge can be for specific tasks. As a developer, it’s a great template for learning Workers and KV, and it gives you a genuinely useful service you can customize. Whether you want a branded link shortener, a way to manage redirects for a personal site, or just a cool weekend project, this codebase is a fantastic starting point.
Follow us for more interesting projects: @githubprojects