cf-shortener
cf-shortener copied to clipboard
🌩 Demo of a link shortener running on Cloudflare Workers
☁️ Link Shortener on Cloudflare Workers

This is a link shortener that runs as a Cloudflare Worker. It's the finished code for the Build a Link Shortener with Cloudflare Workers tutorial on DEV.to. To deploy it on your own Cloudflare account, follow these steps:
-
Clone this repo:
git clone https://github.com/mm/cf-shortener.git -
Ensure Wrangler v2+ is installed on your local machine:
$ wrangler versionIf you see
wrangler v1...., then you need to remove the old version:$ npm uninstall -g @cloudflare/wranglerNow install if needed; note the missing "@cloudflare/":
$ npm install -g wrangler $ wrangler version ⛅️ wrangler 2.*.* -
Authenticate with Cloudflare:
$ wrangler login -
In the project directory, copy the
wrangler.example.tomlfile towrangler.toml. Get your Cloudflare Account ID by runningwrangler whoami. Inwrangler.toml, replaceACCOUNT_ID_HEREwith the account ID you get from Wrangler or the Workers dashboard. -
Create the Workers KV namespace for the shortener:
$ wrangler kv:namespace create "SHORTEN" $ wrangler kv:namespace create "SHORTEN" --previewCopy the
idyou get in the terminal output towrangler.tomlin place ofID_HERE, and copy thepreview_idyou get in the terminal output in place ofPREVIEW_ID_HERE. -
Deploy the Worker:
wrangler publish
Changelog
v1.1.0
- Updated all dependencies
- Add to
wrangler.tomlcompatibility_date = "2023-01-20"(CloudFlare's new versioning tag) - Switching from Wrangler V1 to Wrangler V2
v1.0.0
- Initial version