SPB Git forge
2commits 1branches 0releases
492.0 KBsize
maindefault branch
4 h agolast push
TypeScript 96.1% CSS 3.1% JavaScript 0.8%
1.2 KB · 42 lines typescript
Raw Blame History
1import { NextResponse } from "next/server";2import { CLUSTER_NODES } from "@/lib/cluster";3import { executeSSH } from "@/lib/ssh";45export const dynamic = "force-dynamic";67export async function POST(request: Request) {8  const { nodeId, command } = await request.json();910  if (!nodeId || !command) {11    return NextResponse.json({ error: "nodeId and command required" }, { status: 400 });12  }1314  if (nodeId === "all") {15    const results = await Promise.allSettled(16      CLUSTER_NODES.map(async (n) => ({17        nodeId: n.id,18        output: await executeSSH(n.hostname, command),19      }))20    );2122    const outputs = results.map((r, i) => {23      if (r.status === "fulfilled") return r.value;24      return { nodeId: CLUSTER_NODES[i].id, output: `Error: ${(r.reason as Error).message}` };25    });2627    return NextResponse.json({ results: outputs });28  }2930  const node = CLUSTER_NODES.find(n => n.id === nodeId);31  if (!node) {32    return NextResponse.json({ error: "Unknown node" }, { status: 404 });33  }3435  try {36    const output = await executeSSH(node.hostname, command);37    return NextResponse.json({ nodeId, output });38  } catch (err) {39    return NextResponse.json({ nodeId, output: `Error: ${(err as Error).message}` }, { status: 500 });40  }41}42