Add basic webserver setup
This commit is contained in:
parent
8682cc99bc
commit
b2f859f817
@ -48,6 +48,7 @@ namespace ChaosBot
|
|||||||
_logger.Info($"Starting Up {ConfigurationRepository.GetValue<string>("Bot:Name")} v{ConfigurationRepository.GetValue<string>("Bot:Version")}");
|
_logger.Info($"Starting Up {ConfigurationRepository.GetValue<string>("Bot:Name")} v{ConfigurationRepository.GetValue<string>("Bot:Version")}");
|
||||||
|
|
||||||
var discordBot = DiscordConnect.StartUp();
|
var discordBot = DiscordConnect.StartUp();
|
||||||
|
WebServer.WebServer.Start(new string[]{});
|
||||||
await discordBot;
|
await discordBot;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
47
ChaosBot/WebServer/Startup.cs
Normal file
47
ChaosBot/WebServer/Startup.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using Microsoft.AspNetCore.Authentication;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using NLog;
|
||||||
|
|
||||||
|
namespace ChaosBot.WebServer
|
||||||
|
{
|
||||||
|
class Startup
|
||||||
|
{
|
||||||
|
private readonly Logger _logger = Program._logger;
|
||||||
|
|
||||||
|
public IConfiguration Configuration { get; }
|
||||||
|
|
||||||
|
public Startup(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
Configuration = configuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method gets called by the runtime. Use this method to add services to the container.
|
||||||
|
public void ConfigureServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddControllers();
|
||||||
|
|
||||||
|
services.Configure<ForwardedHeadersOptions>(options =>
|
||||||
|
{
|
||||||
|
options.ForwardedHeaders =
|
||||||
|
ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline
|
||||||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
{
|
||||||
|
_logger.Info("Initializing Kestrel Startup and Configuration");
|
||||||
|
|
||||||
|
app.UseForwardedHeaders();
|
||||||
|
app.UseDeveloperExceptionPage();
|
||||||
|
app.UseMiddleware<AuthenticationMiddleware>();
|
||||||
|
app.UseRouting();
|
||||||
|
app.UseAuthorization();
|
||||||
|
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
ChaosBot/WebServer/WebServer.cs
Normal file
39
ChaosBot/WebServer/WebServer.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
using System.Net;
|
||||||
|
using ChaosBot.Database.Repository;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
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 =>
|
||||||
|
{
|
||||||
|
webBuilder.ConfigureKestrel(serverOptions =>
|
||||||
|
{
|
||||||
|
serverOptions.Listen(IPAddress.Any, ConfigurationRepository.GetValue<int>("WebServer:Port"),
|
||||||
|
listenOptions =>
|
||||||
|
{
|
||||||
|
listenOptions.UseConnectionLogging();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.ConfigureLogging(logging =>
|
||||||
|
{
|
||||||
|
logging.ClearProviders();
|
||||||
|
logging.SetMinimumLevel(LogLevel.Trace);
|
||||||
|
logging.AddNLog(new NLogLoggingConfiguration(ConfigurationRepository.GetSection("NLog")));
|
||||||
|
})
|
||||||
|
.UseStartup<Startup>();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user