30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
using System.Text.Json;
|
|
using Journal.Core;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
builder.Services.AddOpenApi();
|
|
builder.Services.AddFragmentServices();
|
|
builder.Services.AddSingleton<Entry>();
|
|
|
|
var app = builder.Build();
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
app.MapOpenApi();
|
|
|
|
app.MapGet("/health", () => Results.Json(new { ok = true, data = "healthy" }));
|
|
app.MapGet("/healthz", () => Results.Json(new { ok = true, data = "healthy" }));
|
|
app.MapGet("/api/health", () => Results.Json(new { ok = true, data = "healthy" }));
|
|
|
|
// Mirrors sidecar transport semantics over HTTP.
|
|
// request body is passed directly to Entry.HandleCommandAsync so malformed JSON
|
|
// and payload errors return the same {ok:false,error} envelope as sidecar mode.
|
|
app.MapPost("/api/command", async (HttpRequest request, Entry entry) =>
|
|
{
|
|
using var reader = new StreamReader(request.Body);
|
|
var body = await reader.ReadToEndAsync();
|
|
var response = await entry.HandleCommandAsync(body);
|
|
return Results.Content(response, "application/json");
|
|
});
|
|
|
|
app.Run();
|