SharpRSS/SharpRSS.Blazor/Program.cs

65 lines
1.6 KiB
C#
Raw Normal View History

using Blazored.LocalStorage;
using Microsoft.EntityFrameworkCore;
2024-06-17 13:53:48 +02:00
using MudBlazor.Services;
using SharpRSS.Blazor.Components;
using SharpRSS.Business;
using SharpRSS.Data;
2024-07-13 16:29:27 +02:00
using SharpRSS.Data.Domains.Configuration;
var builder = WebApplication.CreateBuilder(args);
builder.UseSRSS();
2024-07-06 00:02:02 +02:00
builder.Services.AddBlazoredLocalStorage();
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
2024-06-17 13:53:48 +02:00
builder.Services.AddMudServices();
builder.Services.AddHttpContextAccessor(); // HttpContext accessor
2024-07-06 00:02:02 +02:00
/*
* HSTS config
*/
2024-07-13 16:29:27 +02:00
var hstsConfig = new HstsConfiguration();
var configSection = builder.Configuration.GetSection($"HTTP:{HstsConfiguration.Hsts}");
configSection.Bind(hstsConfig);
if (hstsConfig.EnableHsts)
2024-07-06 00:02:02 +02:00
{
2024-07-13 16:29:27 +02:00
builder.Services.AddHsts(options =>
{
options.Preload = hstsConfig.Preload;
options.IncludeSubDomains = hstsConfig.IncludeSubdomains;
options.MaxAge = TimeSpan.FromSeconds(hstsConfig.MaxAgeSeconds);
});
}
2024-07-06 00:02:02 +02:00
var app = builder.Build();
2024-07-13 16:29:27 +02:00
//TODO: Move to migrations
var contextFactory = app.Services.GetService<IDbContextFactory<SRSSContext>>();
if (contextFactory != null)
{
await using var context = await contextFactory.CreateDbContextAsync();
context.Database.EnsureCreated();
}
2024-07-06 00:02:02 +02:00
else
{
}
if (!app.Environment.IsDevelopment())
{
2024-07-13 16:29:27 +02:00
app.UseDeveloperExceptionPage();
app.UseExceptionHandler("/Error", createScopeForErrors: true);
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
2024-07-13 16:29:27 +02:00
app.UseAuthentication();
app.UseAuthorization();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();