using System.Net.Http; using ChaosBot.WebServer.Services; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpOverrides; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace ChaosBot.WebServer { class Startup { 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(options => { options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto; }); services .AddSingleton(sp => new AccessTokenCache()) .AddSingleton(sp => new DiscordInviteGenerator()) .AddSingleton(sp => new HttpClient()) .AddSingleton(sp => new ValidationService()) ; } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { LoggingFacade.Info("Initializing Kestrel Startup and Configuration"); if (Program.AppSettingsHandler.GetValue("WebServer:Debug", false)) app.UseDeveloperExceptionPage(); app.UseForwardedHeaders(); app.UseMiddleware(); 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(); } } }