A serverless URL shortener built with Cloudflare Workers and KV storage, featuring IP-based access control and customizable link expiration.
- URL shortening: Create short links that redirect to original URLs
- IP restriction: Limit API access to specific IP addresses
- Custom expiration: Set expiration time for links (default: 7 days)
- Simple API: Easy-to-use JSON API for creating short links
- Automatic cleanup: Expired links are automatically removed
- User-friendly expired link page: Clean HTML response for expired links
- POST a URL to the
/apiendpoint with valid JSON - The worker generates a short code and stores the URL in KV storage
- Visiting the short URL redirects to the original URL
- Expired links show a friendly expiration message
- Create clourflare worker
- paste the worker.js code
- Create a KV namespace named LINKS in your Cloudflare dashboard
- Bind the KV namespace to your worker from worker settings
- Update ALLOWED_IPS in the worker code with your authorized IP addresses
curl -X POST "https://your-workerApiLink.com/api" \
-H "Content-Type: application/json" \
-d '{"url": "http://example.com"}'