{"id":22903149,"url":"https://github.com/l480/url-shortener","last_synced_at":"2025-05-08T16:55:06.165Z","repository":{"id":249871434,"uuid":"832605774","full_name":"L480/url-shortener","owner":"L480","description":"🔗 Serverless URL shortener based on Cloudflare Workers","archived":false,"fork":false,"pushed_at":"2025-04-28T05:36:07.000Z","size":1832,"stargazers_count":3,"open_issues_count":4,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-05T01:14:33.137Z","etag":null,"topics":["bitly","cloudflare","cloudflare-workers","serverless","url-shortener"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/L480.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"L480_","github":"L480"}},"created_at":"2024-07-23T11:04:21.000Z","updated_at":"2025-04-20T12:24:18.000Z","dependencies_parsed_at":"2024-09-09T16:35:59.942Z","dependency_job_id":"189b3554-4183-4b84-91f6-c7e4fb4b067b","html_url":"https://github.com/L480/url-shortener","commit_stats":null,"previous_names":["l480/url-shortener"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L480%2Furl-shortener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L480%2Furl-shortener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L480%2Furl-shortener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/L480%2Furl-shortener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/L480","download_url":"https://codeload.github.com/L480/url-shortener/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253112078,"owners_count":21856070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bitly","cloudflare","cloudflare-workers","serverless","url-shortener"],"created_at":"2024-12-14T02:34:25.924Z","updated_at":"2025-05-08T16:55:06.120Z","avatar_url":"https://github.com/L480.png","language":"TypeScript","funding_links":["https://ko-fi.com/L480_","https://github.com/sponsors/L480"],"categories":[],"sub_categories":[],"readme":"# 🔗 url-shortener\n\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/l480/url-shortener/test.yml?label=E2E%20Test)\n\nServerless URL shortener based on Cloudflare Workers and Cloudflare Workers KV.\n\n![url-shortener](/images/header.png \"url-shortener\")\n\n## Setup\n\n### 1. Deploy Worker to Cloudflare\n\n[![Deploy to Cloudflare Workers](https://deploy.workers.cloudflare.com/button)](https://deploy.workers.cloudflare.com/?url=https://github.com/L480/url-shortener)\n\n### 2. Create KV Namespace and KV Binding\n\n![Create KV Binding](/images/kv-binding.png \"Create KV Binding\")\n\n### 3. Grab Your Worker URL\n\nGrab your Worker URL and go to `https://url-shortener.my-account.workers.dev/shorten`.\n\n\u003e [!TIP]\n\u003e Use [Cloudflare Access](https://developers.cloudflare.com/cloudflare-one/applications/configure-apps/self-hosted-apps/) to protect the `/shorten` route behind an [Entra ID authentication](https://learn.microsoft.com/en-us/entra/identity/enterprise-apps/cloudflare-integration).\n\n### 4. Shorten Your First URL\n\n![Shorten Your First URL](/images/shorten-url.png \"Shorten Your First URL\")\n\n## API\n\n### Shorten URL\n\n#### HTTP Request\n\n```http\nPOST /shorten\n```\n\n#### Request Body\n\n##### Random Alias\n\n```json\n{\n    \"url\": \"https://google.com\"\n}\n```\n\n##### Custom Alias\n\n```json\n{\n    \"url\": \"https://google.com\",\n    \"alias\": \"hZk\"\n}\n```\n\n#### Response\n\n```json\n{\n    \"status\": \"success\",\n    \"message\": \"Alias has been created.\",\n    \"alias\": \"hZk\"\n}\n```\n\n## FAQ\n\n- How long are the shortened URLs?\n    - By default it's your root domain `example.com` + a 3 character alias (`example.com/aS3`). Shortening the same URL multiple times would result in the same alias. 3 characters would last for about 200k unique aliases if no hash collision occurs. After exceeding ~200k unique aliases, each new alias is a hash collision, resulting in the behavior described below.\n- What happens in case of a hash collision?\n    - In case of a hash collision an additional character would be appended to your alias (`example.com/aS3q`).\n    - Hash collisions increase the read operations on the KV namespace (+1 for each appended character), resulting in higher costs. If you are expecting many alias creations, increase [`ALIAS_LENGTH`](wrangler.toml#L14) before going live.\n- Can I increase the length of my aliases?\n    - You can increase the alias length via the [`ALIAS_LENGTH`](wrangler.toml#L14) variable.\n    - Only increase [`ALIAS_LENGTH`](wrangler.toml#L14) if your KV namespace is empty, otherwise duplicated aliases are being created.\n- Are the aliases the same across all deployed workers?\n    - If you don't change the [`SALT`](wrangler.toml#L15) variable, the aliases will be the same.\n- Can I change the `/shorten` route?\n    - Yes, the `/shorten` route can be overwritten in [config.ts](src/config.ts#L2).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl480%2Furl-shortener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fl480%2Furl-shortener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fl480%2Furl-shortener/lists"}