This commit is contained in:
committed by
GitHub
parent
f43f2786d0
commit
6c5288a5f8
@@ -564,6 +564,14 @@ If the client reports "Connection refused" check:
|
|||||||
* `GET /routes` (with `Accept: application/json`)
|
* `GET /routes` (with `Accept: application/json`)
|
||||||
|
|
||||||
Retrieves the currently configured routes
|
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`)
|
* `POST /routes` (with `Content-Type: application/json`)
|
||||||
|
|
||||||
|
|||||||
+13
-1
@@ -1,6 +1,7 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"expvar"
|
"expvar"
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -37,8 +38,19 @@ func registerApiRoutes(apiRoutes *mux.Router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func routesListHandler(writer http.ResponseWriter, _ *http.Request) {
|
func routesListHandler(writer http.ResponseWriter, _ *http.Request) {
|
||||||
|
type serverRoute = struct {
|
||||||
|
Backend string `json:"backend"`
|
||||||
|
ScalingTarget string `json:"scalingTarget"`
|
||||||
|
}
|
||||||
|
|
||||||
mappings := Routes.GetMappings()
|
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 {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("Failed to marshal mappings")
|
logrus.WithError(err).Error("Failed to marshal mappings")
|
||||||
writer.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|||||||
Reference in New Issue
Block a user