You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.4 KiB
C#

using EmbedIO;
using EmbedIO.Actions;
using EmbedIO.WebApi;
using System;
namespace KevServer
{
/// <summary>
/// 主服务,这个名字很丑,到时候换一个
/// </summary>
class DrawServer
{
private readonly WebServer webServer;
/// <summary>
/// 画布 server
/// </summary>
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<DrawController>())
.WithModule(
new ActionModule("/",
HttpVerbs.Any,
ctx => ctx.SendStringAsync("Hello, World!",
"text/plain", System.Text.Encoding.UTF8)));
}
/// <summary>
/// 启动 server
/// </summary>
public void Start()
{
webServer.RunAsync();
}
}
}