var builder = WebApplication.CreateBuilder(args); builder.Services.AddControllers(); var app = builder.Build(); var webRootPath = app.Environment.WebRootPath ?? Path.Combine(app.Environment.ContentRootPath, "wwwroot"); var indexFilePath = Path.Combine(webRootPath, "index.html"); app.UseDefaultFiles(); app.UseStaticFiles(); app.MapControllers(); app.MapFallback(async context => { if (context.Request.Path.StartsWithSegments("/api")) { context.Response.StatusCode = StatusCodes.Status404NotFound; return; } if (!File.Exists(indexFilePath)) { context.Response.StatusCode = StatusCodes.Status404NotFound; return; } context.Response.ContentType = "text/html; charset=utf-8"; await context.Response.SendFileAsync(indexFilePath); }); app.Run();