mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-13 19:54:59 +00:00
fix: add base URL to routes response
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Crestron.SimplSharp.WebScripting;
|
using Crestron.SimplSharp;
|
||||||
|
using Crestron.SimplSharp.WebScripting;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using PepperDash.Core.Web.RequestHandlers;
|
using PepperDash.Core.Web.RequestHandlers;
|
||||||
|
|
||||||
@@ -7,13 +8,30 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
public class GetRoutesHandler:WebApiBaseRequestHandler
|
public class GetRoutesHandler:WebApiBaseRequestHandler
|
||||||
{
|
{
|
||||||
private HttpCwsRouteCollection routeCollection;
|
private HttpCwsRouteCollection routeCollection;
|
||||||
public GetRoutesHandler(HttpCwsRouteCollection routeCollection) {
|
private string basePath;
|
||||||
|
|
||||||
|
public GetRoutesHandler(HttpCwsRouteCollection routeCollection, string basePath) {
|
||||||
this.routeCollection = routeCollection;
|
this.routeCollection = routeCollection;
|
||||||
|
this.basePath = basePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void HandleGet(HttpCwsContext context)
|
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.StatusCode = 200;
|
||||||
context.Response.ContentType = "application/json";
|
context.Response.ContentType = "application/json";
|
||||||
@@ -22,4 +40,13 @@ namespace PepperDash.Essentials.Core.Web.RequestHandlers
|
|||||||
context.Response.End();
|
context.Response.End();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class RoutesResponseObject
|
||||||
|
{
|
||||||
|
[JsonProperty("url")]
|
||||||
|
public string Url { set; get; }
|
||||||
|
|
||||||
|
[JsonProperty("routes")]
|
||||||
|
public HttpCwsRouteCollection Routes { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user