import { building } from '$app/environment'; const API_BASE = building ? 'http://localhost:8080/api' : '/api'; export async function load({ locals }) { const token = locals.token; const headers = token ? { Authorization: `Bearer ${token}` } : {}; const res = await fetch(`${API_BASE}/services`, { headers }); if (!res.ok) { return { services: [], error: 'Falha ao carregar serviços', token: token ?? '' }; } const services = await res.json(); const servicesWithStats = await Promise.all( services.map(async (svc) => { try { const statsRes = await fetch(`${API_BASE}/services/${svc.id}/stats`, { headers }); if (statsRes.ok) { svc.stats = await statsRes.json(); } } catch { /* ignore */ } return svc; }) ); return { services: servicesWithStats, error: null, token: token ?? '' }; }