A minimal URL shortener service built with Hono and Cloudflare Workers.
- Custom domain support with Cloudflare Workers
- R2 storage for URL mappings
- Protected API endpoints
- Auto-generated slugs
- Fallback 404 redirects
- Copy
.env.example
to.env
and fill in your values - Install dependencies:
pnpm install
- Build:
pnpm run build
- Deploy:
pnpm run deploy
POST /api/create
Creates a new short URL with optional social media metadata.
Authorization: Bearer <AUTH_TOKEN>
(Required)Content-Type: application/json
{
"redirectTo": "https://your-domain.com",
"slug": "my-awesome-slug" // Optional
}
GET /:slug
Redirects to the target URL.
GET /:slug/debug
Returns information about a redirect.
Authorization: Bearer <AUTH_TOKEN>
(Optional)
{
"success": true,
"data": {
"slug": "my-awesome-slug",
"redirectTo": "https://your-domain.com",
"createdAt": 1705123456789,
"meta": {
"title": "My Page",
"tags": ["example", "demo"],
"customField": "any value"
}
}
}
{
"success": true,
"data": {
"slug": "my-awesome-slug",
"redirectTo": "https://your-domain.com",
"createdAt": 1705123456789
}
}
- Slugs are auto-generated (4 characters) if not provided
- Auto-generation will retry up to 5 times if collision occurs
- All redirects use 302 (temporary) status code
- Root path ('/') redirects to FALLBACK_404, if not configured, it will return a 404 JSON response