Files
NetMapper2026/frontend/src/lib/api.ts
T

28 lines
1.2 KiB
TypeScript
Raw Normal View History

import type { NetObject, ServiceInfo } from '../types';
const AGENT_BASE = '/api';
export async function fetchObjects(): Promise<NetObject[]> {
return [
{ id: '1', name: 'Site HQ', slug: 'site-hq', type: 'site', status: 'active' },
{ id: '2', name: 'Rack A', slug: 'rack-a', type: 'rack', status: 'active' },
{ id: '3', name: 'Server Proxmox', slug: 'server-proxmox', type: 'physical_host', vendor: 'Dell', model: 'R730', status: 'active' },
{ id: '4', name: 'Switch Core', slug: 'switch-core', type: 'switch', vendor: 'Mikrotik', status: 'active' },
{ id: '5', name: 'Firewall Edge', slug: 'firewall-edge', type: 'firewall', status: 'active' },
];
}
export async function fetchServices(): Promise<ServiceInfo[]> {
const res = await fetch(`${AGENT_BASE}/services`);
if (!res.ok) throw new Error('Impossibile leggere lo stato dei servizi');
return res.json();
}
export async function serviceAction(name: string, action: 'start' | 'stop' | 'restart') {
const res = await fetch(`${AGENT_BASE}/services/${encodeURIComponent(name)}/${action}`, {
method: 'POST',
});
if (!res.ok) throw new Error(`Azione ${action} fallita su ${name}`);
return res.json();
}