# Configuration

> Who can sign up, Discover, bots, the limits that cost you disk and bandwidth, the anti-abuse values, and your own terms. Everything lives in .env.

Every setting is a line of `selfhost/.env`. After changing one, apply it with:

```bash
docker compose up -d
```

Compose recreates the services whose settings changed. The app picks up the new values the next
time each person connects.

Changes to the services themselves (more memory, another port, a service of your own) go in
`selfhost/compose.override.yml`, never in `docker-compose.yml`. Compose reads the override by
itself, git ignores it, and an update leaves it alone.

## Who can sign up

| Setting                       | What happens                                                                                                                                                                                                          |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `BETA_CLOSED=false` (default) | Anyone who reaches the app can create an account                                                                                                                                                                      |
| `BETA_CLOSED=true`            | Creating an account asks for an invite code. You create them in the panel, under **Closed beta**: how many, how many accounts each creates and when they expire. People who already have an account sign in as always |

Invites to a server also let people in as guests (a name and nothing else), as on Klang Cloud.
`ANONYMOUS_SIGNUPS_PER_HOUR` caps how many guest accounts one IP creates in an hour (see
[Against abuse](https://docs.klang.gg/self-hosting/configuration/#against-abuse)).

To keep the install for a known group only, use `BETA_CLOSED=true` and hand out codes. If you
close it from the start, make your own first code with
`docker compose exec api node dist/cli/beta.js create 1` ([Install](https://docs.klang.gg/self-hosting/install/#6-register)).

## Discover

`DISCOVERY_ENABLED=true` turns on Discover: a list of this install’s public servers, which
people can browse and join. Off (the default), its pages and its panel section don’t exist.

## Bots

Bots written for Discord’s API work with your install, as with Klang Cloud
([Bots](https://docs.klang.gg/bots/)). They’re off by default:

- `BOTS_ENABLED` unset or `false` (default): nobody can create apps or add bots, the bot API
  answers `401` and the bot gateway refuses every connection.
- `BOTS_ENABLED=true`: **any registered account** can create apps and bots in
  **Settings › Developers**.
- `BOTS_ENABLED=true` and `BOTS_BETA=true`: only the accounts you add in the panel
  (**Developers**) can create them.

In a bot’s code, use your hostname instead of Klang Cloud’s. With discord.js:

```js
const client = new Client({
  intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages],
  rest: {
    api: 'https://chat.example.org/api',
    cdn: 'https://chat.example.org/api/media',
    mediaProxy: 'https://chat.example.org/api/media',
  },
});
```

The bot gateway is `wss://chat.example.org/bot-gateway`; libraries learn it from the API by
themselves.

## Limits

Unset, the defaults below apply to everyone: up to 500 MB per file, 100 GB of files per person, and
the best quality Klang has for screens, cameras and microphones. Lower what costs you money:

| Setting                     | Range                                     | Default   | What it costs                             |
| --------------------------- | ----------------------------------------- | --------- | ----------------------------------------- |
| `LIMIT_UPLOAD_MB`           | 1-500                                     | 500       | Disk, per file                            |
| `LIMIT_STORAGE_GB`          | 1-100                                     | 100       | Disk, per person                          |
| `LIMIT_SCREEN_SHARE`        | `720p30`, `1080p30`, `1080p60`, `1440p60` | `1440p60` | Upload bandwidth, per viewer              |
| `LIMIT_CAMERA`              | `720p30`, `1080p30`                       | `1080p30` | Upload bandwidth, per viewer              |
| `LIMIT_VOICE_KBPS`          | 32-256                                    | 256       | Bandwidth, per listener                   |
| `LIMIT_STREAMS_PER_CHANNEL` | 1-10                                      | 10        | Screens shared at once in a voice channel |

The server enforces them, not only the app. Everything that costs nothing (emojis, stickers,
themes, animated profiles) is always unlocked.

A screen share at `1440p60` can send several megabits per second to **each** person watching it.
On a server with a capped or paid-per-GB connection, `LIMIT_SCREEN_SHARE=1080p30` is a sensible
start.

## Against abuse

Change them only if you see a reason:

| Setting                         | Default | What it does                                                                                                                                                                                                                   |
| ------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `ANONYMOUS_SIGNUPS_PER_HOUR`    | 10      | Guest accounts per hour from one IP                                                                                                                                                                                            |
| `GATEWAY_CONNECTIONS_PER_5_MIN` | 60      | New real-time connections per IP every 5 minutes. Klang Cloud uses 10; an install often has a whole household behind one router. Raise it if more people share one IP (an office, a school)                                    |
| `SIGNUP_SHARED_IP_MIN_DEVICES`  | 3       | After a ban, new accounts from the person’s IP are flagged for the staff to review, unless at least this many other devices used that IP lately: then it’s a shared IP (a mobile carrier, a university) and nothing is flagged |
| `SIGNUP_SHARED_IP_WINDOW_DAYS`  | 30      | What “lately” means, in days                                                                                                                                                                                                   |

Sign-in, sign-up and 2FA attempts per IP and the rate limits of every route are fixed.

## Your terms and contact

- `TERMS_URL` and `PRIVACY_URL`: your terms of service and privacy policy. They’re linked at
  sign-up, at sign-in and in **Settings › Privacy**. Without them, no link is shown.
- `CONTACT_EMAIL`: where people can write to you. A refused sign-up and the panel show it.

You run the install, so you’re the one responsible for what happens on it, including the
obligations that apply to you as a service provider (in the EU, the Digital Services Act and the
GDPR). Klang Cloud’s terms and policies don’t cover your install. This isn’t legal advice: see
the [repository’s README](https://github.com/klang-gg/klang-server#what-it-isnt).

## The staff panel’s addresses

To open the panel only from some addresses (your home, a VPN), uncomment the two `client_ip`
lines in `selfhost/Caddyfile`, list the IPs or ranges, and run `docker compose restart caddy`. The
Caddyfile is a file of the repository: [Updating](https://docs.klang.gg/self-hosting/updating/#your-changes) says how
to keep the change.

## GIFs, game covers and detected games

All three need outside services and are off by default:

- `KLIPY_API_KEY`: the GIF picker, with a key from KLIPY’s partner panel.
- `IGDB_CLIENT_ID` and `IGDB_CLIENT_SECRET`: game covers, with a Twitch application (both or
  neither).
- `GAMES_CATALOG_URL`: the URL of a JSON list of the games the app can detect people
  playing, in the format of Discord’s list of detectable applications. Unset, there’s no list.

## Logs

`LOG_LEVEL` (`info` by default; `debug` for more, `warn` for less). See
[Troubleshooting](https://docs.klang.gg/self-hosting/troubleshooting/#reading-the-logs).
