123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- 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);
- }
-
- // /// <summary>
- // /// Clears certificate and host information, and stops the listener.
- // /// </summary>
- // public static void Clear()
- // {
- // _host?.Stop();
- // _host = null;
- //
- // //_pusher?.Stop();
- // //_pusher = null;
- //
- // Certificate = null;
- // }
- /// <summary>
- /// Initialise rest listener, and set up web socket port if non-zero.
- /// </summary>
- /// <param name="webSocketPort">The web-socket port to use, or 0 for no websocket.</param>
- // 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);
- // }
- }
- }
|