Skip to content

Benricheson101/urlshortener

dev
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

  1. 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.

  2. Deploy this repo to your Cloudflare Worker account using the wrangler CLI

  3. Add your secret as an application variable called JWT_SECRET for your worker

  4. 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)