URL shortener for manjaro friends.
curl -s https://mjr.sh/add?url=https://example.com
Which returns:
{
"url": "https://mjr.sh/C7D3",
"edit": "https://mjr.sh/C7D3/edit?url=https%3A%2F%2Fexample.com&secret=4673cab7-6d01-479c-97b2-999010fa8987",
"stats": "https://mjr.sh/C7D3/stats",
"key": "C7D3",
"timestamp": "2024-05-18 12:58:17",
"value": "https://example.com",
"secret": "4673cab7-6d01-479c-97b2-999010fa8987"
}
Store the secret if you'd like to edit the URL afterwards.
curl -s https://mjr.sh/C7D3/edit?secret=4673cab7-6d01-479c-97b2-999010fa8987&url=https%3A%2F%2Fexample.de
Which returns:
{
"url": "https://mjr.sh/C7D3",
"key": "C7D3",
"timestamp": "2024-05-18 12:59:30",
"value": "https://example.de",
"secret": "4673cab7-6d01-479c-97b2-999010fa8987"
}
curl -s https://mjr.sh/C7D3/stats
Which returns something like this
{
"key": "C7D3",
"count": 1,
"timestamp": "2024-05-17 19:34:01",
"badge": "https://img.shields.io/badge/dynamic/json?url=https%3A%2F%2Fmjr.sh%2FAB34%2Fstats&query=%24.count&label=redirects"
}
This is a Cloudflare Worker (src/index.ts) with the rendered README.md served
as a static asset from public/.
bun install
cp .dev.vars.example .dev.vars # SALT used to hash edit secrets
bunx wrangler d1 execute urls --local --file=./schema.sql
bunx wrangler d1 migrations apply urls --local
bun run dev # builds public/ and starts wrangler dev
Other scripts: bun run typecheck, bun run check (biome), bun run types
(regenerates worker-configuration.d.ts), bun run deploy.
The SALT secret has to exist in production as well:
bunx wrangler secret put SALT
bunx wrangler d1 migrations apply urls --remote
SAFE_BROWSING_API_KEY is optional; submissions are accepted unchecked when
it is absent. If set, it enables a Google Safe Browsing check on /add:
bunx wrangler secret put SAFE_BROWSING_API_KEY
/add rejects submissions whose domain is on a KV-backed blocklist, refreshed
daily: hagezi TIF mini (GPL-3.0,
known-malicious domains) and
PeterDaveHello/url-shorteners
(MIT, nested shorteners aren't accepted)