Files
blog-manager/app/api/publish/route.ts
2026-11-01 13:23:44 -05:00

19 lines
757 B
TypeScript

import { HttpError } from "@/lib/errors";
import { gitStatus } from "@/lib/git";
import { readJson, route } from "@/lib/http";
import { publish } from "@/lib/publish";
export const dynamic = "force-dynamic";
export const GET = route(async () => Response.json(await gitStatus()));
/** Body: { message } -> commit managed paths, push, trigger deploy. A failed
* step is reported in the body ({ ok: false, steps }), not as an HTTP error. */
export const POST = route(async (req) => {
const { message } = await readJson<{ message?: string }>(req);
const msg = message?.trim();
if (!msg) throw new HttpError(400, "commit message is required");
const result = await publish(msg);
return Response.json({ ...result, status: await gitStatus() });
});