A simple URL shortener built with Hono and Prisma running on Cloudflare Workers with D1 as the database.
- Shorten URLs with unique, randomly generated short codes
- Redirect to original URLs via short links
- Built on Cloudflare Workers for scalability and low latency
- Uses D1 (SQLite) for persistent storage
- Prisma ORM for database access
npm installnpx wrangler d1 migrations apply your-db --localnpx prisma generatenpm run devnpm run deploynpm run cf-typegenTo shorten a URL, send a GET request to the root endpoint with the url query parameter:
GET /?url=https://example.com
Or even faster with shell function
hikari() {
curl -s https://hikari.nguyenducthien9.workers.dev/ \
-H "Content-Type: application/json" \
-d "{\"originalUrl\": \"$1\"}"
}
hikari https://www.example.com{
"id": 1,
"originalUrl": "https://example.com",
"shortUrl": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"description": null
}Configure your D1 database binding in your .env and wrangler.jsonc.
- Migrations are stored in the migrations/ directory.
- Prisma schema is in prisma/schema.prisma.
This project is licensed under the GNU Affero General Public License v3.0. See LICENSE for details.
For questions or contributions, please open an issue or pull request.