fix: add root API response

This commit is contained in:
Anthony Ettinger 2026-06-06 11:59:58 +00:00
parent 9379d6eb2e
commit 4e4c78140d
2 changed files with 18 additions and 0 deletions

View file

@ -22,6 +22,15 @@ afterAll(async () => {
}); });
describe("CommandBoard API contracts", () => { describe("CommandBoard API contracts", () => {
it("exposes root API index", async () => {
const response = await fetch(`${baseUrl}/`);
const body = await response.json() as { ok: boolean; service: string; endpoints: string[] };
expect(response.status).toBe(200);
expect(body).toMatchObject({ ok: true, service: "commandboard-api" });
expect(body.endpoints).toEqual(expect.arrayContaining(["/health", "/api/boards", "/api/plugins"]));
});
it("exposes health contract", async () => { it("exposes health contract", async () => {
const response = await fetch(`${baseUrl}/health`); const response = await fetch(`${baseUrl}/health`);
const body = await response.json() as { ok: boolean; service: string }; const body = await response.json() as { ok: boolean; service: string };

View file

@ -54,6 +54,15 @@ export function createCommandBoardServer() {
async function route(request: IncomingMessage, response: ServerResponse) { async function route(request: IncomingMessage, response: ServerResponse) {
const url = new URL(request.url ?? "/", "http://localhost"); const url = new URL(request.url ?? "/", "http://localhost");
if (request.method === "GET" && url.pathname === "/") {
json(response, 200, {
ok: true,
service: "commandboard-api",
endpoints: ["/health", "/api/boards", "/api/tasks", "/api/plugins", "/api/schemas"]
});
return;
}
if (request.method === "GET" && url.pathname === "/health") { if (request.method === "GET" && url.pathname === "/health") {
json(response, 200, { ok: true, service: "commandboard-api" }); json(response, 200, { ok: true, service: "commandboard-api" });
return; return;