Configure API to serve SPA, integrate SignalR, and update build paths

This commit is contained in:
2026-02-22 19:27:13 +01:00
committed by Jonas
parent 3fa0455f1b
commit 8eefc1a2b8
5 changed files with 35 additions and 9 deletions
+13
View File
@@ -1,8 +1,15 @@
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();
@@ -18,8 +25,14 @@ if (app.Environment.IsDevelopment())
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAuthorization();
app.MapControllers();
app.MapHub<API.Controllers.GameController>("/api/game");
// SPA fallback: serve index.html for routes not matched by API or static files
app.MapFallbackToFile("index.html");
app.Run();