fork from 1.3
This commit is contained in:
43
FreeSR.Admin/Service/HttpAdminService.cs
Normal file
43
FreeSR.Admin/Service/HttpAdminService.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user