From f78be44d0cd8f73510335bd543207d414b003d37 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Sun, 24 May 2026 00:10:01 +1000 Subject: Updated Program.cs and converted to WASM --- Program.cs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'Program.cs') diff --git a/Program.cs b/Program.cs index 5863368..fdb899c 100644 --- a/Program.cs +++ b/Program.cs @@ -1,3 +1,4 @@ +using HyperBooru.Server.Components; using HyperBooru.Services; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.DataProtection; @@ -5,12 +6,12 @@ using Microsoft.AspNetCore.Http.Json; using Microsoft.EntityFrameworkCore; using System.Text.Json.Serialization; -namespace HyperBooru; +namespace HyperBooru.Server; public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); - builder.Services.AddSession(); + builder.Services.AddHttpContextAccessor(); builder.Services.AddAuthentication( CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); @@ -22,8 +23,8 @@ public class Program { builder.Services.Configure(o => { o.SerializerOptions.TypeInfoResolverChain.Insert(0, new ExceptionJsonResolver()); }); - builder.Services.AddRazorPages(); - builder.Services.AddServerSideBlazor(); + builder.Services.AddRazorComponents() + .AddInteractiveWebAssemblyComponents(); // Add our custom services builder.Services.AddSingleton(); @@ -34,7 +35,6 @@ public class Program { builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddHostedService(); - builder.Services.AddSingleton(); // Ensure session keys are stored in a persistent location on all platforms builder.Services.AddDataProtection() @@ -50,17 +50,24 @@ public class Program { using var db = scope.ServiceProvider.GetRequiredService(); db.Database.Migrate(); - app.UseRouting(); - app.UseSession(); app.UseAuthentication(); app.UseAuthorization(); + if(app.Environment.IsDevelopment()) { + app.UseWebAssemblyDebugging(); + } else { + app.UseExceptionHandler("/Error"); + } + + app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); app.UseHsts(); app.UseHttpsRedirection(); - app.UseStaticFiles(); + app.MapStaticAssets(); app.UseMiddleware(); - app.MapBlazorHub(); + app.UseAntiforgery(); app.MapControllers(); - app.MapFallbackToPage("/_Host"); + app.MapRazorComponents() + .AddInteractiveWebAssemblyRenderMode() + .AddAdditionalAssemblies(typeof(Client._Imports).Assembly); app.Run(); } -- cgit v1.3