mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-18 23:42:28 +00:00
* Initial work for rate limiting * Refactor GameServerStartup and change default rate limit config * Adjust config naming and add Enabled option to global and override rate limits * Fix LBP3 republish bug * Fix bugs in rate limiting and allow for multiple matched overrides * Add this qualifier for private variable * Changes from self review
98 lines
3.2 KiB
C#
98 lines
3.2 KiB
C#
using System.Globalization;
|
|
using System.Reflection;
|
|
using LBPUnion.ProjectLighthouse.Localization;
|
|
using LBPUnion.ProjectLighthouse.Middlewares;
|
|
using LBPUnion.ProjectLighthouse.Servers.Website.Middlewares;
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;
|
|
using Microsoft.Extensions.FileProviders;
|
|
|
|
#if !DEBUG
|
|
using Microsoft.Extensions.Hosting.Internal;
|
|
#else
|
|
using LBPUnion.ProjectLighthouse.Startup;
|
|
#endif
|
|
|
|
namespace LBPUnion.ProjectLighthouse.Servers.Website.Startup;
|
|
|
|
public class WebsiteStartup
|
|
{
|
|
public WebsiteStartup(IConfiguration configuration)
|
|
{
|
|
this.Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddControllers();
|
|
#if DEBUG
|
|
services.AddRazorPages().WithRazorPagesAtContentRoot().AddRazorRuntimeCompilation((options) =>
|
|
{
|
|
// jank but works
|
|
string projectDir = Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..", "..", ".."));
|
|
|
|
options.FileProviders.Clear();
|
|
options.FileProviders.Add(new PhysicalFileProvider(projectDir));
|
|
});
|
|
#else
|
|
services.AddRazorPages().WithRazorPagesAtContentRoot();
|
|
#endif
|
|
|
|
services.AddDbContext<Database>();
|
|
|
|
services.Configure<ForwardedHeadersOptions>
|
|
(
|
|
options =>
|
|
{
|
|
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
|
}
|
|
);
|
|
|
|
services.Configure<RequestLocalizationOptions>(config =>
|
|
{
|
|
List<CultureInfo> languages = LocalizationManager.GetAvailableLanguages().Select(l => new CultureInfo(LocalizationManager.MapLanguage(l))).ToList();
|
|
|
|
config.DefaultRequestCulture = new RequestCulture(new CultureInfo("en"));
|
|
|
|
config.SupportedCultures = languages;
|
|
config.SupportedUICultures = languages;
|
|
});
|
|
|
|
#if DEBUG
|
|
services.AddSingleton<IHostLifetime, DebugWarmupLifetime>();
|
|
#else
|
|
services.AddSingleton<IHostLifetime, ConsoleLifetime>();
|
|
#endif
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
{
|
|
#if DEBUG
|
|
app.UseDeveloperExceptionPage();
|
|
#endif
|
|
|
|
app.UseForwardedHeaders();
|
|
|
|
app.UseMiddleware<HandlePageErrorMiddleware>();
|
|
app.UseMiddleware<RequestLogMiddleware>();
|
|
app.UseMiddleware<UserRequiredRedirectMiddleware>();
|
|
app.UseMiddleware<RateLimitMiddleware>();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseStaticFiles(new StaticFileOptions
|
|
{
|
|
ServeUnknownFileTypes = true,
|
|
});
|
|
|
|
app.UseRequestLocalization();
|
|
|
|
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
|
app.UseEndpoints(endpoints => endpoints.MapRazorPages());
|
|
}
|
|
}
|