mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-27 19:22:27 +00:00
84 lines
No EOL
2.5 KiB
C#
84 lines
No EOL
2.5 KiB
C#
using System.Globalization;
|
|
using LBPUnion.ProjectLighthouse.Localization;
|
|
using LBPUnion.ProjectLighthouse.Middlewares;
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
using Microsoft.AspNetCore.Localization;
|
|
|
|
#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();
|
|
#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-US"));
|
|
|
|
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<RequestLogMiddleware>();
|
|
|
|
app.UseRouting();
|
|
|
|
app.UseStaticFiles(new StaticFileOptions
|
|
{
|
|
ServeUnknownFileTypes = true,
|
|
});
|
|
|
|
app.UseRequestLocalization();
|
|
|
|
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
|
app.UseEndpoints(endpoints => endpoints.MapRazorPages());
|
|
}
|
|
} |