37 lines
939 B
C#
37 lines
939 B
C#
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();
|