- Last Change:
Commit Briefs
update exqlite (master)
chore: release v0.5.3 (tags/v0.5.3)
chore: release v0.5.2 (tags/v0.5.2)
chore: release v0.5.1 (tags/v0.5.1)
chore: release v0.5.0 (tags/v0.5.0)
Branches
Tree
README.md
# shirts
[](https://builds.sr.ht/~mtmn/shirts?)
A URL shortener. Links are stored in a SQLite database and served under a configurable base URL.
## Building
```sh
mix deps.get
mix release
```
## Usage
### Create a short link
```sh
curl -X POST http://localhost:4000/curtail \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/very/long/path"}'
```
Optionally provide a custom code:
```sh
curl -X POST http://localhost:4000/curtail \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/very/long/path", "code": "my-code"}'
```
### List all short links
```sh
curl http://localhost:4000/history \
-H "Authorization: Bearer <token>"
```
Returns a table ordered by creation time. Request JSON instead with an `Accept` header:
```sh
curl http://localhost:4000/history \
-H "Authorization: Bearer <token>" \
-H "Accept: application/json"
```
JSON shape: `{"count": N, "shirts": [{"code": ..., "url": ..., "created_at": ...}]}`.
### Follow a short link
```
GET /s/<code>
```
## Configuration
Runtime configuration is resolved with the following precedence:
1. Environment variables
2. `/etc/shirts.conf` (a native Elixir config file; see `config/shirts.conf.example`)
3. Built-in defaults
| Variable | Description | Default |
|--------------|--------------------------------------|----------------|
| `PORT` | Port to listen on | `4000` |
| `HOST` | Host/interface to bind to | `127.0.0.1` |
| `BASE_URL` | Base URL used when generating links | `http://localhost` |
| `AUTH_TOKEN` | Bearer token for the create endpoint | _required_ |
| `DB_PATH` | Path to the SQLite database file | `data.db` |
In production, `AUTH_TOKEN` must be set either via the `AUTH_TOKEN` environment
variable or in `/etc/shirts.conf`, otherwise the application refuses to start.
### Config file
`/etc/shirts.conf` is an optional native Elixir config file. Copy the example
and edit it:
```sh
cp config/shirts.conf.example /etc/shirts.conf
```
```elixir
import Config
config :shirts,
port: 4000,
host: "127.0.0.1",
auth_token: "change-me",
db_path: "/var/db/shirts/data.db",
base_url: "https://shirts.example"
```
### Release settings
The following are read natively by the Elixir release runtime (not by the
config file above); set them as environment variables:
| Variable | Description |
|-----------------------|--------------------------------------|
| `RELEASE_COOKIE` | Distribution cookie for the BEAM node |
| `RELEASE_NODE` | Node name, e.g. `shirts@127.0.0.1` |
| `RELEASE_DISTRIBUTION`| `name` / `sname` for node distribution |
