Setup
webapi.yml options, the access address, and running the API on one server of a network.
The web API is configured in plugins/MineDuels/webapi.yml. It is written from the jar on first start. Changes need a restart. API keys are the exception: /md web key ... takes effect at once.
webapi.yml
enabled: false
host: 127.0.0.1
port: 8765
base-path: /v1
public-url: ""
cors-origin: ""
trust-forwarded-for: false
threads: 4
queue: 64
database-concurrency: 3
max-body-kb: 256
cache-seconds: 5
limits:
per-ip: 30
read: 20
heavy: 5
write: 2
keys: []| Key | Default | Meaning |
|---|---|---|
enabled | false | Turns the API on. |
host | 127.0.0.1 | The address to listen on. 127.0.0.1 accepts the same machine only. 0.0.0.0 accepts every address. |
port | 8765 | The TCP port. |
base-path | /v1 | The path every endpoint lives under. |
public-url | empty | The address shown by /md web url when the API is reached through a proxy, for example https://api.example.com. Display only. |
cors-origin | empty | One origin that browsers may call from, for example https://panel.example.com. Empty sends no CORS headers. |
trust-forwarded-for | false | Behind a reverse proxy on the same machine, rate limit by the X-Forwarded-For address instead of the proxy's. |
threads | 4 | Worker threads (1 to 32). |
queue | 64 | How many requests may wait for a worker. Beyond that the answer is 503. |
database-concurrency | 3 | How many database reads run at once. A request waits up to 2 seconds for a slot, then gets 503. |
max-body-kb | 256 | The largest request body. Larger ones get 413. |
cache-seconds | 5 | How long lists, leaderboards and stats are reused (0 to 300). 0 turns caching off. |
limits.per-ip | 30 | Requests per second per address, checked before the key. |
limits.read | 20 | Cheap reads per second per key. |
limits.heavy | 5 | Database and config reads per second per key. |
limits.write | 2 | Drain, reload and config edits per second per key. |
keys | empty | Written by /md web key create. Only hashes are stored. |
A burst of twice the per-second limit is allowed (three times for write). See rate limits.
Commands
All need mineduels.admin.
| Command | What it does |
|---|---|
/md web url | Prints the base URL and a curl line to try. |
/md web status | Says whether the API runs and how many keys exist. |
/md web key list | Lists key names and scopes. |
/md web key create <name> <read|write|admin> | Creates a key and prints it once. |
/md web key remove <name> | Deletes a key. It stops working at once. |
Reaching it from another machine
By default only the server itself can connect. To call it from another machine:
- Set
host: 0.0.0.0inwebapi.ymland restart. - Allow the port. On a Pterodactyl server add the port as an allocation and use that port in
port. On a VPS open it in the firewall, for example:
sudo ufw allow from 203.0.113.10 to any port 8765 proto tcp- Call
http://<server-ip>:8765/v1/status.
The API speaks plain HTTP. For anything outside a private network use a reverse proxy with HTTPS, and keep host: 127.0.0.1 so only the proxy can connect.
Running it on one server of a network
Enable the web API on one server only. It does not need to run on every backend.
What the one server can see, because every backend shares the MySQL database and the Redis channel:
| Data | Source | Covers |
|---|---|---|
| Player stats, history, leaderboards | The shared MySQL database | The whole network |
| Running matches | The md_running table in the database | Every server |
| Finished matches | The md_matches table | Every server |
| Server list, players, free arenas, queues, drain flags | Redis heartbeats | Every server and proxy |
| Drain, from here to another server | A signed Redis message | Any lobby or game server |
What stays local to the server that runs the API:
/status,/parties,/arenasand/tournamentsdescribe that server./configand/reloadedit and reload that server's own files. A config file of another server cannot be reached from here. To change another server, run the API there too, or edit its files and run/md reload.
Pick a lobby or the server that holds the matchmaker. Either works. The server needs storage.type: mysql in database.yml, as every cross-server backend does. On a single server with SQLite the API works the same and /servers shows one entry named local.
Example network:
lobby-1 web API on (127.0.0.1:8765 behind nginx)
lobby-2 web API off
game-1 web API off
game-2 web API offcurl -H "Authorization: Bearer $KEY" http://127.0.0.1:8765/v1/servers{
"ok": true,
"data": [
{ "name": "game-1", "role": "game", "players": 8, "maxPlayers": 100, "fresh": true, "ageSeconds": 1,
"draining": false, "matchmaker": false, "freeArenas": { "nodebuff": 3 }, "playing": { "nodebuff": 4 }, "queued": {} },
{ "name": "lobby-1", "role": "lobby", "players": 31, "maxPlayers": 100, "fresh": true, "ageSeconds": 0,
"draining": false, "matchmaker": true, "freeArenas": {}, "playing": {}, "queued": { "nodebuff|r1": 2 } }
]
}Checking that it works
/md web statusWeb API running at http://127.0.0.1:8765/v1
Keys: 2If the console says the API could not start, the message names the reason. The rest of MineDuels is not affected.
| Console message | Cause | Fix |
|---|---|---|
The web API could not start on 127.0.0.1:8765 (BindException: Address already in use) | Another program uses the port. | Change port. |
The web API could not start on ... (SocketException: Permission denied) | The port is below 1024 without permission. | Use a port above 1024. |
The web API is on but has no API key | No key exists yet. | /md web key create <name> read |
webapi.yml: base-path '...' is not valid | The path has other characters than letters, digits, _, -, /. | Fix base-path. |
Stopping it
Set enabled: false and restart. The server also stops the API first when MineDuels disables, so a restart does not leave the port open.