A serverless URL shortener based on Cloudflare Workers and Vercel.
A fork of Likenttt/eastlake-cloudflare-worker-short-url. Read the original README file. 阅读原始的“README”文件。
- Authentication
- List shortened URL data on the KV database
- Click counter for a specific URL
- Correctly and swiftly redirect a short URL to its original long URL.
- Monitor click history per link
- Optional: if enabled, it will consume more read/write times for Cloudflare KV. If you are on a paid plan, disregard since the plan has unlimited read/write times.
- Expiration time
- Password protection
- 404 Not Found fallback page
You must have:
- A Vercel account.
- A Cloudflare account.
- A domain on Cloudflare.
Fork this repository and clone it to your local machine. Then start the deployment process.
The frontend code is in /fe, which is a Next.js project. Vercel is highly recommended.
- Create a Cloudflare KV namespace named
LINKS
. - Populate the namespace ID in
wrangler.toml
below.
[[kv_namespaces]]
binding = "LINKS" # Don't change
id = "uuid" # Change
Don't expose your variables in the wrangler.toml
file. Exclude this file in future commits.
USERNAME = "li2niu" # Change it and don't expose it in this file
PASSWORD = "li2niu" # Change it and don't expose it in this file
JWT_SECRET = "li2niu" # Change it and don't expose it in this file
DEFAULT_PAGE = "https://blog.li2niu.com" # Change it
RECORD_CLICKS = true
FE_ADMIN_DOMAIN = "https://cf-url-admin.li2niu.com" # Replace it with your admin domain, important for cross-origin allowlist
git clone <forked repository>
npm install -g wrangler
wrangler login
If you have yarn installed globally, meaning you have a file located at ~/.pnp.cjs
, rename the file to something else temporarily as Babel will complain about Plug'n'Play when wrangler runs the build script.
cd worker
wrangler publish
Cloudflare free plan has limits for KV, especially write times. Even in a paid plan, the write speed for the same key is limited to 1 time/second, potentially causing inaccuracies in high concurrency. Click history is not recommended for free plan users.