using EmbedIO; using EmbedIO.Actions; using EmbedIO.WebApi; using System; namespace KevServer { /// /// 主服务,这个名字很丑,到时候换一个 /// class DrawServer { private readonly WebServer webServer; /// /// 画布 server /// public DrawServer() { var instance = WebConfig.Instance; if (string.IsNullOrEmpty(instance.ListenUrl)) { Console.WriteLine("未配置服务地址,请先配置,如 http://192.168.31.2:8080"); return; } webServer = new WebServer(o => o .WithUrlPrefix(instance.ListenUrl) .WithMode(HttpListenerMode.EmbedIO)) .WithLocalSessionManager(options => options.SessionDuration = TimeSpan.FromHours(5)) .WithWebApi("/graphics", m => m .WithController()) .WithModule( new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendStringAsync("Hello, World!", "text/plain", System.Text.Encoding.UTF8))); } /// /// 启动 server /// public void Start() { webServer.RunAsync(); } } }