From 6c5288a5f85a2b521f61bb29a7a1153421fe3540 Mon Sep 17 00:00:00 2001 From: Louis Wehmschulte <59291494+L-Wehmschulte@users.noreply.github.com> Date: Sat, 4 Apr 2026 19:21:09 +0200 Subject: [PATCH] Add ScalingTarget to Routes API response (#541) --- README.md | 8 ++++++++ server/api_server.go | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3934c90..27c35e4 100644 --- a/README.md +++ b/README.md @@ -564,6 +564,14 @@ If the client reports "Connection refused" check: * `GET /routes` (with `Accept: application/json`) Retrieves the currently configured routes + ```json + { + "serverAddress": { + "backend": "HOST:PORT", // The address the client is routed to + "scalingTarget": "HOST:PORT" // The address of the actual minecraft server (will differ from backend when a proxy is configured) + } + } + ``` * `POST /routes` (with `Content-Type: application/json`) diff --git a/server/api_server.go b/server/api_server.go index eaba753..5620f0b 100644 --- a/server/api_server.go +++ b/server/api_server.go @@ -1,6 +1,7 @@ package server import ( + "context" "encoding/json" "expvar" "net/http" @@ -37,8 +38,19 @@ func registerApiRoutes(apiRoutes *mux.Router) { } func routesListHandler(writer http.ResponseWriter, _ *http.Request) { + type serverRoute = struct { + Backend string `json:"backend"` + ScalingTarget string `json:"scalingTarget"` + } + mappings := Routes.GetMappings() - bytes, err := json.Marshal(mappings) + routes := make(map[string]serverRoute, len(mappings)) + for k := range mappings { + backend, address, scalingTarget, _, _ := Routes.FindBackendForServerAddress(context.Background(), k) + routes[address] = serverRoute{Backend: backend, ScalingTarget: scalingTarget} + } + + bytes, err := json.Marshal(routes) if err != nil { logrus.WithError(err).Error("Failed to marshal mappings") writer.WriteHeader(http.StatusInternalServerError)