using System.Net;
using System.Security.Cryptography.X509Certificates;
using GenHTTP.Api.Infrastructure;
using GenHTTP.Engine;
using GenHTTP.Modules.Practices;
namespace InABox.API
{
public static class RestListener
{
private static IServerHost? _host;
//private static RestPusher? _pusher;
public static X509Certificate2? Certificate { get; private set; }
public static void Start()
{
_host?.Start();
//_pusher?.Start();
}
public static void Stop()
{
_host?.Stop();
//_pusher?.Stop();
}
public static void Init(ushort port, X509Certificate2? cert)
{
_host = Host.Create();
_host.Handler(new RestHandlerBuilder()).Defaults().Backlog(1024);
Certificate = cert;
RestService.IsHTTPS = cert != null;
if (cert != null)
_host?.Bind(IPAddress.Any, port, cert);
else
_host?.Bind(IPAddress.Any, port);
}
// ///
// /// Clears certificate and host information, and stops the listener.
// ///
// public static void Clear()
// {
// _host?.Stop();
// _host = null;
//
// //_pusher?.Stop();
// //_pusher = null;
//
// Certificate = null;
// }
///
/// Initialise rest listener, and set up web socket port if non-zero.
///
/// The web-socket port to use, or 0 for no websocket.
// public static void Init() //int webSocketPort)
// {
// if(webSocketPort != 0)
// {
// _pusher = new RestPusher(webSocketPort);
// PushManager.AddPusher(_pusher);
// }
//
// _host = Host.Create();
// _host.Handler(new RestHandlerBuilder(_pusher?.Port)).Defaults().Backlog(1024);
// }
}
}