blob: bdf498b72cf2d07f0665f7b405282a9009418ad1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
const API = 'http://localhost:8080/api';
export async function load({ locals }) {
const token = locals.token;
const headers = token ? { Authorization: `Bearer ${token}` } : {};
const res = await fetch(`${API}/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}/services/${svc.id}/stats`, { headers });
if (statsRes.ok) {
svc.stats = await statsRes.json();
}
} catch { /* ignore */ }
return svc;
})
);
return { services: servicesWithStats, error: null, token: token ?? '' };
}
|