import { NextResponse } from "next/server"; import { z } from "zod"; import { withAuth } from "@/lib/api-auth"; import { apiError, handleApiError } from "@/lib/api-errors"; import { createDeployment, DeploymentBody, DeploymentError, listDeployments } from "@/lib/deployments"; export const dynamic = "force-dynamic"; export const GET = withAuth(async () => NextResponse.json(await listDeployments())); /** Create a deployment; `start: true` starts it right away. */ export const POST = withAuth(async (req) => { try { const body = DeploymentBody.extend({ start: z.boolean().default(true) }).parse(await req.json()); return NextResponse.json(await createDeployment(body, body.start), { status: 201 }); } catch (err) { if (err instanceof DeploymentError) return apiError(err.status, err.code, err.message); return handleApiError(err); } });