Add routes (untested)

This commit is contained in:
Jack Mechem 2026-03-27 18:40:05 -07:00
parent db20819ad2
commit d346ccf701
9 changed files with 132 additions and 13 deletions

View file

@ -0,0 +1,29 @@
import { NextRequest, NextResponse } from "next/server";
const ALLOWED_ACTIONS = ["start", "stop", "restart"];
export async function POST(
req: NextRequest,
{ params }: { params: { service: string; action: string } },
) {
const token = req.cookies.get("token")?.value;
if (!token) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
if (!ALLOWED_ACTIONS.includes(params.action)) {
return NextResponse.json({ error: "Invalid action" }, { status: 400 });
}
const res = await fetch(
`http://localhost:3001/services/${params.service}/${params.action}`,
{
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
},
},
);
return NextResponse.json(await res.json(), { status: res.status });
}

View file

@ -0,0 +1,22 @@
import { NextRequest, NextResponse } from "next/server";
export async function GET(
req: NextRequest,
{ params }: { params: { service: string } },
) {
const token = req.cookies.get("token")?.value;
if (!token) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const res = await fetch(
`http://localhost:3001/services/${params.service}/logs`,
{
headers: {
Authorization: `Bearer ${token}`,
},
},
);
return NextResponse.json(await res.json(), { status: res.status });
}