56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using System.IO;
|
|
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 ILogger _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");
|
|
|
|
if (Program.AppSettingsHandler.GetValue<bool>("WebServer:Debug", false))
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
app.UseForwardedHeaders();
|
|
app.UseMiddleware<AuthenticationMiddleware>();
|
|
app.UseRouting();
|
|
app.UseAuthorization();
|
|
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
|
|
|
|
DefaultFilesOptions options = new DefaultFilesOptions();
|
|
options.DefaultFileNames.Clear();
|
|
options.DefaultFileNames.Add("index.html");
|
|
app.UseDefaultFiles(options);
|
|
app.UseStaticFiles();
|
|
}
|
|
}
|
|
} |