Split viewer and simulation into separate apps
This commit is contained in:
36
apps/backend/Program.cs
Normal file
36
apps/backend/Program.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using SpaceGame.Simulation.Api.Simulation;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.WebHost.UseUrls("http://127.0.0.1:5079");
|
||||
builder.Services.AddCors((options) =>
|
||||
{
|
||||
options.AddDefaultPolicy((policy) =>
|
||||
{
|
||||
policy
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyOrigin();
|
||||
});
|
||||
});
|
||||
builder.Services.AddSingleton<WorldService>();
|
||||
builder.Services.AddHostedService<SimulationHostedService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.UseCors();
|
||||
|
||||
app.MapGet("/", () => Results.Redirect("/api/world"));
|
||||
app.MapGet("/api/world", (WorldService worldService) => Results.Ok(worldService.GetSnapshot()));
|
||||
app.MapGet("/api/world/health", (WorldService worldService) => Results.Ok(new
|
||||
{
|
||||
ok = true,
|
||||
generatedAtUtc = worldService.GetSnapshot().GeneratedAtUtc,
|
||||
}));
|
||||
app.MapPost("/api/world/reset", (WorldService worldService) =>
|
||||
{
|
||||
var snapshot = worldService.Reset();
|
||||
return Results.Ok(snapshot);
|
||||
});
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user