Self-host the Minekube API and relay
Minekube runs the Minekube API and relays for every network. You can also run your own. Each part is in the open source repository, and Minekube deploys the same code.
The Minekube API
Section titled “The Minekube API”The Minekube API is an Effect Cloudflare Worker in apps/api. It keeps its state in Durable Objects: the registry, where Directory maps every key to its network and Network holds one network’s instances, labels, versions and deployments, and Accounts, which holds accounts and their sessions. Deployed bundles go to the R2 bucket Bundles.
Locally: in a checkout, mk api runs it in workerd on http://localhost:4776 (--port for another), with local state and no Cloudflare account. It is the API every mk command and every project uses unless --api, MINEKUBE_API or api in vite.config.ts names another. mk server --network starts it for the dev network.
On Cloudflare: infra/network.run.ts deploys it with Alchemy, at api.minekube.com (staging: api.staging.minekube.com), with DNS for *.<domain>, where players reach networks. Your own deployment sets its own host names. The Worker reads three values:
| Variable | What |
|---|---|
MINEKUBE_NETWORK_DOMAIN |
Where networks are reached: <network>.<domain> |
MINEKUBE_API_DOMAIN |
The API’s own host name, such as api.example.com |
MINEKUBE_OPERATORS |
The issuers whose short-lived tokens may act as a relay or an admin |
MINEKUBE_LOGIN_HUB |
Where players get a login code, such as play.example.com, for mk login to say. Optional. |
There are no static tokens. A relay or an admin shows a short-lived token of an issuer in MINEKUBE_OPERATORS, such as a Kubernetes service account token.
The relay
Section titled “The relay”The relay is a Rust program in apps/relay, with a Dockerfile. CI publishes its image as ghcr.io/. Each option is a flag and an environment variable:
| Variable | Default | What |
|---|---|---|
MINEKUBE_RELAY_LISTEN |
0.0.0.0:25565 |
Where Java players connect |
MINEKUBE_API |
The Minekube API to look up routes in and announce the relay to | |
MINEKUBE_API_TOKEN_FILE |
A file with a short-lived token the API trusts for relays, read before each request | |
MINEKUBE_NETWORK_DOMAIN |
localhost |
Networks are reached at <network>.<domain>; other hosts are refused |
MINEKUBE_RELAY_REGION |
local |
Where the relay runs, a label on the instances homed here |
MINEKUBE_RELAY_KEY |
relay.key |
The relay’s key, made on first start. Connectors recognize the relay by it. |
MINEKUBE_RELAY_TLS_DOMAIN |
Serve the iroh relay over HTTPS for this name, with a certificate from Let’s Encrypt that the relay renews itself. Needs port 443. | |
MINEKUBE_RELAY_TLS_CACHE |
acme |
Where the certificate is kept across restarts |
Locally, mk relay runs one against the local API. Point your servers’ connector.json at your relay in relays and at your API in directory.
Related
Section titled “Related”- Connector, relay and API: what each part does and why.
- Open source: the license and what is in the repository.
Was this helpful?
Thanks for the feedback.