Archived
1
0
Fork 0
forked from Moux23333/FreeSR
This repository has been archived on 2024-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
FreeSR/FreeSR.Admin/Service/HttpAdminService.cs
2024-01-27 21:06:07 +08:00

43 lines
1.4 KiB
C#

namespace FreeSR.Admin.Service
{
using Ceen.Httpd;
using Ceen.Httpd.Logging;
using FreeSR.Admin.Handlers;
using FreeSR.Shared.Configuration;
using System.Net;
internal static class HttpAdminService
{
public static string ConsoleHTML { get; private set; }
private static ServerConfig s_httpdConfiguration;
public static void Initialize(NetworkConfiguration config)
{
LoadHtDocs();
s_httpdConfiguration = CreateConfiguration();
_ = BootHttpAsync(config);
}
private static void LoadHtDocs()
{
ConsoleHTML = File.ReadAllText("assets/console.html");
}
private static ServerConfig CreateConfiguration()
{
return new ServerConfig().AddLogger(new CLFStdOut())
.AddRoute("/console", new ConsolePageRequestHandler())
.AddRoute("/console/exec", new ExecuteCommandRequestHandler());
}
private static async Task BootHttpAsync(NetworkConfiguration config)
{
await HttpServer.ListenAsync(new IPEndPoint(
IPAddress.Parse(config.Host),
config.Port),
false, s_httpdConfiguration);
}
}
}