48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using System.IO;
|
|
using System.Net;
|
|
using ChaosBot.ConfigHelpers;
|
|
using NLog.Extensions.Logging;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace ChaosBot.WebServer
|
|
{
|
|
public static class WebServer
|
|
{
|
|
public static void Start(string[] args)
|
|
{
|
|
CreateHostBuilder(args).Build().Run();
|
|
}
|
|
|
|
private static IHostBuilder CreateHostBuilder(string[] args) =>
|
|
Host.CreateDefaultBuilder(args)
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
string contentRoot = Directory.GetCurrentDirectory();
|
|
string webRoot = Path.Combine(contentRoot, "wwwroot/dist");
|
|
Configuration config = new Configuration();
|
|
|
|
webBuilder.UseContentRoot(contentRoot);
|
|
webBuilder.UseWebRoot(webRoot);
|
|
webBuilder.ConfigureKestrel(serverOptions =>
|
|
{
|
|
serverOptions.Listen(IPAddress.Any, config.GetByKey<int>("WebServer:Port").GetValue(),
|
|
listenOptions =>
|
|
{
|
|
listenOptions.UseConnectionLogging();
|
|
});
|
|
})
|
|
.ConfigureLogging(logging =>
|
|
{
|
|
logging.ClearProviders();
|
|
logging.SetMinimumLevel(LogLevel.Trace);
|
|
logging.AddNLog(new NLogLoggingConfiguration(config.GetSection("NLog")));
|
|
})
|
|
.UseStartup<Startup>();
|
|
});
|
|
}
|
|
}
|