var builder = WebApplication.CreateBuilder(args); // Serve frontend from wwwroot at solution root var webRootPath = Path.GetFullPath(Path.Combine(builder.Environment.ContentRootPath, "..", "wwwroot")); Directory.CreateDirectory(webRootPath); builder.Environment.WebRootPath = webRootPath; builder.WebHost.UseWebRoot(webRootPath); // Add services to the container. builder.Services.AddControllers(); builder.Services.AddSignalR(); builder.Services.AddOpenApi(); builder.Services.AddSwaggerGen(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.MapOpenApi(); app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseAuthorization(); app.MapControllers(); app.MapHub("/api/game"); // SPA fallback: serve index.html for routes not matched by API or static files app.MapFallbackToFile("index.html"); app.Run();