Add ScalingTarget to Routes API response (#541)
release / release (push) Failing after 0s

This commit is contained in:
Louis Wehmschulte
2026-04-04 19:21:09 +02:00
committed by GitHub
parent f43f2786d0
commit 6c5288a5f8
2 changed files with 21 additions and 1 deletions
+8
View File
@@ -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`)
+13 -1
View File
@@ -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)