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)