using LifeLab.Client; using LifeLab.Client.Pages; using LifeLab.Components; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents() .AddInteractiveWebAssemblyComponents(); // Lifecycle probe: the same registration as in LifeLab.Client, so server-side // renders (static SSR, prerender, the circuit) POST to /api/log as well. builder.Services.AddSingleton(new HttpClient { BaseAddress = new Uri("http://localhost:15500") }); builder.Services.AddSingleton(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseWebAssemblyDebugging(); } else { app.UseExceptionHandler("/Error", createScopeForErrors: true); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); app.UseHttpsRedirection(); app.UseAntiforgery(); // Lifecycle log: an in-memory list, numbered in arrival order. var logLines = new List(); var logLock = new object(); app.MapPost("/api/log", async (HttpRequest request) => { using var reader = new StreamReader(request.Body); var line = await reader.ReadToEndAsync(); lock (logLock) { logLines.Add($"{logLines.Count + 1:00} | {line}"); } return Results.Ok(); }); app.MapGet("/api/log", () => { lock (logLock) { return Results.Text(string.Join("\n", logLines) + "\n"); } }); app.MapDelete("/api/log", () => { lock (logLock) { logLines.Clear(); } return Results.Ok(); }); app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(typeof(LifeLab.Client._Imports).Assembly); app.Run();