Skip to Content
MineDuels

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: []
KeyDefaultMeaning
enabledfalseTurns the API on.
host127.0.0.1The address to listen on. 127.0.0.1 accepts the same machine only. 0.0.0.0 accepts every address.
port8765The TCP port.
base-path/v1The path every endpoint lives under.
public-urlemptyThe address shown by /md web url when the API is reached through a proxy, for example https://api.example.com. Display only.
cors-originemptyOne origin that browsers may call from, for example https://panel.example.com. Empty sends no CORS headers.
trust-forwarded-forfalseBehind a reverse proxy on the same machine, rate limit by the X-Forwarded-For address instead of the proxy's.
threads4Worker threads (1 to 32).
queue64How many requests may wait for a worker. Beyond that the answer is 503.
database-concurrency3How many database reads run at once. A request waits up to 2 seconds for a slot, then gets 503.
max-body-kb256The largest request body. Larger ones get 413.
cache-seconds5How long lists, leaderboards and stats are reused (0 to 300). 0 turns caching off.
limits.per-ip30Requests per second per address, checked before the key.
limits.read20Cheap reads per second per key.
limits.heavy5Database and config reads per second per key.
limits.write2Drain, reload and config edits per second per key.
keysemptyWritten 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.

CommandWhat it does
/md web urlPrints the base URL and a curl line to try.
/md web statusSays whether the API runs and how many keys exist.
/md web key listLists 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:

  1. Set host: 0.0.0.0 in webapi.yml and restart.
  2. 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
  1. 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:

DataSourceCovers
Player stats, history, leaderboardsThe shared MySQL databaseThe whole network
Running matchesThe md_running table in the databaseEvery server
Finished matchesThe md_matches tableEvery server
Server list, players, free arenas, queues, drain flagsRedis heartbeatsEvery server and proxy
Drain, from here to another serverA signed Redis messageAny lobby or game server

What stays local to the server that runs the API:

  • /status, /parties, /arenas and /tournaments describe that server.
  • /config and /reload edit 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 off
curl -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 status
Web API running at http://127.0.0.1:8765/v1
Keys: 2

If the console says the API could not start, the message names the reason. The rest of MineDuels is not affected.

Console messageCauseFix
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 keyNo key exists yet./md web key create <name> read
webapi.yml: base-path '...' is not validThe 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.

On this page