Files
short/README.md
T
traberphandClaude Opus 5.5 3eea5c23ef Rename the trending palettes section to "Colourful"
The palettes are a snapshot and don't follow coolors.co's trending
list, so the heading no longer claims they do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 16:58:38 +02:00

98 lines
4.9 KiB
Markdown

# short
A small self-hosted URL shortener and link-page tool for a handful of people, with login through Authentik (OIDC).
- **Short links**: `/<code>` for admins, `/<username>/<code>` for everyone else. Codes can be custom or random, and both codes and destinations can be edited later.
- **Link pages**: a "link in bio" page with avatar, link buttons, Markdown text blocks and colour themes, including built-in and pasted [coolors.co](https://coolors.co) palettes. Blocks are reordered by drag and drop.
- **QR codes**: choose the error correction level and colours, then download as PNG or SVG.
- **Privacy-friendly stats**: clicks per day, daily unique visitors, last visit. No raw IPs are stored, the visitor hash uses a salt that rotates daily, and individual clicks are deleted after 90 days.
- **API with personal access tokens**: for scripts and iOS Shortcuts.
- **Mobile-friendly admin UI** with light and dark mode, installable as a PWA. Everything runs as a single container with SQLite.
See [REQUIREMENTS.md](REQUIREMENTS.md) for the full feature list.
## URLs
| Path | What |
|---|---|
| `/` | Redirects to the pinned page, if an admin pinned one |
| `/<code>` | Root links and pages (admins) |
| `/<username>/<code>` | User links and pages |
| `/~/` | Admin UI |
| `/~/api/…` | JSON API |
| `/~/health` | Health check |
## Roles
- **Users** can create and manage links and link pages under `/<their username>/`. Link pages can only use their own links.
- **Admins** are members of the Authentik group `ADMIN_GROUP`. They can additionally create root links, pin a page to `/`, and view, edit and delete everything.
The username is Authentik's `preferred_username`, fixed at the first login. Usernames have to be URL-safe (`A-Z a-z 0-9 . _ -`). Root codes that match a username are blocked, and the dashboard warns admins about conflicts.
## Setup
### 1. Authentik
Create an **OAuth2/OpenID provider** and an application for it:
- Client type: *Confidential*
- Redirect URI: `https://<your domain>/~/auth/callback`
- Scopes: `openid`, `profile`, `email` (the default `profile` mapping includes the `groups` claim)
- Create a group (e.g. `short-admins`) for admins.
- Use the application's policy bindings to control who can log in at all.
### 2. Configuration
Copy `.env.template` to `.env` and fill it in:
| Variable | Required | Description |
|---|---|---|
| `BASE_URL` | yes | Public URL, e.g. `https://short.example.com` |
| `OIDC_ISSUER` | yes | The provider's issuer URL, e.g. `https://auth.example.com/application/o/short/` |
| `OIDC_CLIENT_ID` / `OIDC_CLIENT_SECRET` | yes | From the Authentik provider |
| `SESSION_SECRET` | yes | At least 32 random characters: `openssl rand -base64 32` |
| `ADMIN_GROUP` | | Authentik group for admins, default `short-admins` |
| `TIMEZONE` | | Timezone for "today" and the daily stats, default `UTC` |
| `TRUST_PROXY` | | `true` behind a reverse proxy, so `X-Forwarded-For` is used for the visitor IP |
| `DATA_DIR` | | Database and uploads, default `./data` (`/data` in Docker) |
| `LOGO_DEV_TOKEN` | | Enables website logos on link page buttons via [logo.dev](https://logo.dev). Page owners can turn them off per page; the logo.dev credit only shows where logos are on |
| `DISABLE_ATTRIBUTION` | | `true` hides the "powered by" footer |
### 3. Run
```sh
mkdir -p data && sudo chown 1000:1000 data # the container runs as uid 1000
docker compose up -d
```
Put it behind a reverse proxy with TLS. Back up `data/`: it holds the SQLite database (`short.db`) and the uploaded avatars. Database migrations run automatically on startup.
## API
The admin UI uses the same JSON API. Create a token under **API tokens**; it has the same permissions as your account.
```sh
curl -X POST https://short.example.com/~/api/pages \
-H "Authorization: Bearer short_…" \
-H "Content-Type: application/json" \
-d '{"kind":"redirect","dest":"https://example.com","code":"optional"}'
```
Main endpoints: `GET/POST /pages`, `GET/PATCH/DELETE /pages/:id`, `GET/DELETE /pages/:id/stats?days=7|30|90`, `POST /pages/:id/blocks`, `PUT /pages/:id/blocks/order`, `PATCH/DELETE /blocks/:id`, `PUT /pages/:id/avatar`, `GET/POST/DELETE /palettes`, `GET/POST/DELETE /tokens`.
Admin only: `PUT/DELETE /pin`, `GET /users`, `GET /conflicts`.
Link buttons can reference an existing short link (`{"kind":"link","label":"…","targetId":12}`) or create one in the page's namespace in the same request (`{"kind":"link","label":"…","newLink":{"dest":"https://…","code":"optional"}}`).
## Development
```sh
pnpm install
cp .env.template .env # BASE_URL=http://localhost:5173 for dev
pnpm dev # API on :3000, admin UI with hot reload on http://localhost:5173/~/
pnpm test # vitest
pnpm typecheck
pnpm db:generate # after changing src/server/db/schema.ts
```
Stack: Node 24, [Hono](https://hono.dev), SQLite with [Drizzle](https://orm.drizzle.team), [openid-client](https://github.com/panva/openid-client), React + Vite + Tailwind for the admin UI.