Start/stop deployments

This commit is contained in:
2026-02-14 14:09:58 +01:00
parent 2e8525123d
commit 8f320747ad
4 changed files with 94 additions and 12 deletions
+29 -3
View File
@@ -1,7 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import testAuth from "../auth";
import { StatusCodes } from "http-status-codes";
import { deployApp } from "@/core/deployment";
import { deployApp, toggleDeployment } from "@/core/deployment";
import { Application, Port } from "@/lib/types";
export async function POST(req: NextRequest): Promise<NextResponse> {
@@ -15,14 +15,14 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
if (auth) {
return NextResponse.json(
{ message: auth },
{ status: StatusCodes.UNAUTHORIZED }
{ status: StatusCodes.UNAUTHORIZED },
);
}
if (!name || !app) {
return NextResponse.json(
{ message: "Body missing name, appId, nodeId" },
{ status: StatusCodes.BAD_REQUEST }
{ status: StatusCodes.BAD_REQUEST },
);
}
@@ -33,3 +33,29 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
deployId,
});
}
export async function PUT(req: NextRequest): Promise<NextResponse> {
const auth = await testAuth(req);
const { deployId, action }: { deployId: string; action: "start" | "stop" } =
await req.json();
if (auth) {
return NextResponse.json(
{ message: auth },
{ status: StatusCodes.UNAUTHORIZED },
);
}
if (!deployId || !action) {
return NextResponse.json(
{ message: "Body missing deployId or action" },
{ status: StatusCodes.BAD_REQUEST },
);
}
await toggleDeployment(deployId, action);
return NextResponse.json({
message: "ok",
});
}