SharpRSS/SharpRSS.Blazor/Program.cs
2024-07-13 16:29:27 +02:00

65 lines
1.6 KiB
C#

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