Files
4Gewinnt/API/Program.cs
T

39 lines
962 B
C#

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.Controllers.GameController>("/api/game");
// SPA fallback: serve index.html for routes not matched by API or static files
app.MapFallbackToFile("index.html");
app.Run();