URL Shortener π
A simple URL shortener that lives on a Cloudflare Worker.
API Reference
Create Shortlink:
POST /slugs
Authorization: <api-key>
{"url": "https://pupy.gay", "slug": "owo"}
Returns: HTTP 204
Delete Shortlink:
DELETE /slugs/:slug
Authorization: <api-key>
Returns: HTTP 204
Get Shortlink Info:
GET /slugs/:slug
Authorization: <api-key>
Returns: {"url": "<url>", "created_at": "<ISO-8601 date>", "user": "<user>"}
List All Shortlinks:
GET /slugs
Authorization: <api-key>
Returns: String[]
Running for Yourself
-
Create a secrets for generating API keys. The OpenSSL CLI works well for this (
openssl rand -hex 32
), but any 64 character long string should work. -
Deploy this repo to your Cloudflare Worker account using the wrangler CLI
-
Add your secret as an application variable called
JWT_SECRET
for your worker -
Generate an API key (MacOS/Linux only. Windows users can run this with WSL :P)
URL_SHORTENER_JWT_SECRET="<your-secret>"./scripts/urlshortener create-token <username>
. The username doesn't do anything other than show who created the shortlink if you look up a link with the CLI or API (outlined above)