RestListener.cs 983 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System.Net;
  2. using System.Security.Cryptography.X509Certificates;
  3. using GenHTTP.Api.Infrastructure;
  4. using GenHTTP.Engine;
  5. using GenHTTP.Modules.Practices;
  6. namespace InABox.API
  7. {
  8. public static class RestListener
  9. {
  10. private static IServerHost? _host;
  11. public static X509Certificate2? Certificate { get; private set; }
  12. public static void Start()
  13. {
  14. _host?.Start();
  15. }
  16. public static void Stop()
  17. {
  18. _host?.Stop();
  19. }
  20. public static void Init(ushort port, X509Certificate2? cert)
  21. {
  22. _host = Host.Create();
  23. _host.Handler(new RestHandlerBuilder()).Defaults().Backlog(1024);
  24. Certificate = cert;
  25. RestService.IsHTTPS = cert != null;
  26. if (cert != null)
  27. _host?.Bind(IPAddress.Any, port, cert);
  28. else
  29. _host?.Bind(IPAddress.Any, port);
  30. }
  31. }
  32. }