- Login: redirect to original page after auth via returnUrl query param - RedirectToLogin: encodes current URL as ?returnUrl=/path - API URL: configurable via appsettings.json ApiBaseUrl or API_BASE_URL env - NotFound page: preserved from template
53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using System.Security.Claims;
|
|
using Heimdall.Web.Components;
|
|
using Heimdall.Web.Services;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using MudBlazor.Services;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents();
|
|
|
|
// Auth for Blazor
|
|
builder.Services.AddScoped<AuthenticationStateProvider, HeimdallAuthStateProvider>();
|
|
builder.Services.AddAuthorizationCore();
|
|
|
|
builder.Services.AddMudServices(config =>
|
|
{
|
|
config.SnackbarConfiguration.PositionClass = "mud-alert-center-top";
|
|
config.SnackbarConfiguration.PreventDuplicates = true;
|
|
config.SnackbarConfiguration.ShowCloseIcon = true;
|
|
config.SnackbarConfiguration.VisibleStateDuration = 4000;
|
|
});
|
|
|
|
builder.Services.AddScoped<HeimdallApiClient>();
|
|
var apiBaseUrl = builder.Configuration.GetValue<string>("ApiBaseUrl")
|
|
?? Environment.GetEnvironmentVariable("API_BASE_URL")
|
|
?? "http://localhost:5000";
|
|
builder.Services.AddHttpClient("HeimdallApi", client =>
|
|
{
|
|
client.BaseAddress = new Uri(apiBaseUrl.TrimEnd('/') + "/");
|
|
client.Timeout = TimeSpan.FromSeconds(30);
|
|
});
|
|
|
|
// Auth state
|
|
builder.Services.AddScoped<AuthState>();
|
|
|
|
var app = builder.Build();
|
|
|
|
if (!app.Environment.IsDevelopment())
|
|
{
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
app.UseHsts();
|
|
}
|
|
|
|
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
|
|
app.UseHttpsRedirection();
|
|
app.UseAntiforgery();
|
|
app.MapStaticAssets();
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode();
|
|
|
|
app.Run();
|