Configure API to serve SPA, integrate SignalR, and update build paths
This commit is contained in:
@@ -3,7 +3,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
namespace API.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
[Route("api/[controller]")]
|
||||
public class StatusController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user