fix: add base URL to routes response

This commit is contained in:
Andrew Welker
2025-03-28 10:32:16 -05:00
parent 474b2eb647
commit bb045ba06b

View File

@@ -1,4 +1,5 @@
using Crestron.SimplSharp.WebScripting;
using Crestron.SimplSharp;
using Crestron.SimplSharp.WebScripting;
using Newtonsoft.Json;
using PepperDash.Core.Web.RequestHandlers;
@@ -7,13 +8,30 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
public class GetRoutesHandler:WebApiBaseRequestHandler
{
private HttpCwsRouteCollection routeCollection;
public GetRoutesHandler(HttpCwsRouteCollection routeCollection) {
private string basePath;
public GetRoutesHandler(HttpCwsRouteCollection routeCollection, string basePath) {
this.routeCollection = routeCollection;
this.basePath = basePath;
}
protected override void HandleGet(HttpCwsContext context)
{
var response = JsonConvert.SerializeObject(routeCollection);
var currentIp = CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_CURRENT_IP_ADDRESS, 0);
var hostname = CrestronEthernetHelper.GetEthernetParameter(
CrestronEthernetHelper.ETHERNET_PARAMETER_TO_GET.GET_HOSTNAME, 0);
var path = CrestronEnvironment.DevicePlatform == eDevicePlatform.Server
? $"https://{hostname}/VirtualControl/Rooms/{InitialParametersClass.RoomId}/cws{basePath}"
: $"https://{currentIp}/cws{basePath}";
var response = JsonConvert.SerializeObject(new RoutesResponseObject()
{
Url = path,
Routes = routeCollection
});
context.Response.StatusCode = 200;
context.Response.ContentType = "application/json";
@@ -22,4 +40,13 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
context.Response.End();
}
}
public class RoutesResponseObject
{
[JsonProperty("url")]
public string Url { set; get; }
[JsonProperty("routes")]
public HttpCwsRouteCollection Routes { get; set; }
}
}