import { NextResponse } from 'next/server'; import { getNodes, getLXC, getConfigIPs } from '@/lib/proxmox'; const PROXMOX_WEB_URL = process.env.PROXMOX_WEB_URL || process.env.PROXMOX_API_URL?.replace('/api2/json', ''); /** @param {import('next').Request} _req */ export async function GET(_req) { try { const nodes = await getNodes(); const allLXC = []; for (const node of nodes) { try { const lxcs = await getLXC(node.name); for (const lxc of lxcs) { let ips = []; if (lxc.status === 'running') { try { ips = await getConfigIPs(node.name, lxc.vmid, 'lxc'); } catch { /* guest agent not available */ } } allLXC.push({ ...lxc, node: node.name, consoleUrl: `${PROXMOX_WEB_URL}/?console=lxc&vmid=${lxc.vmid}&node=${encodeURIComponent(node.name)}&resize=scale&xtermjs=1`, ips, }); } } catch { /* skip node */ } } return NextResponse.json({ data: allLXC, timestamp: Date.now() }); } catch (error) { return NextResponse.json({ error: error.message, data: null }, { status: 502 }); } }