aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/routes/+page.ts
diff options
context:
space:
mode:
authorzwlucas <lucas.fariamo08@gmail.com>2026-05-29 18:57:37 +0000
committerzwlucas <lucas.fariamo08@gmail.com>2026-05-29 18:57:37 +0000
commit6cc0bfd1d79074df790272b8091b1f0226d14283 (patch)
treecab18b0f708cf3b0eaeeeb98e2cf81459365b33e /frontend/src/routes/+page.ts
downloadyaum-6cc0bfd1d79074df790272b8091b1f0226d14283.tar.gz
yaum-6cc0bfd1d79074df790272b8091b1f0226d14283.zip
feat: upload project
Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
Diffstat (limited to 'frontend/src/routes/+page.ts')
-rw-r--r--frontend/src/routes/+page.ts33
1 files changed, 33 insertions, 0 deletions
diff --git a/frontend/src/routes/+page.ts b/frontend/src/routes/+page.ts
new file mode 100644
index 0000000..ba70169
--- /dev/null
+++ b/frontend/src/routes/+page.ts
@@ -0,0 +1,33 @@
+import type { Service, Heartbeat } from '$lib/types';
+
+export interface EnhancedService extends Service {
+ heartbeats: Heartbeat[];
+}
+
+export async function load({ fetch }) {
+ let services: EnhancedService[] = [];
+ let error = '';
+
+ try {
+ const res = await fetch('/api/services');
+ if (!res.ok) throw new Error(`HTTP ${res.status}`);
+ const list: Service[] = await res.json();
+
+ services = await Promise.all(
+ list.map(async (svc) => {
+ try {
+ const hres = await fetch(`/api/services/${svc.id}/history`);
+ if (!hres.ok) throw new Error(`HTTP ${hres.status}`);
+ const heartbeats: Heartbeat[] = await hres.json();
+ return { ...svc, heartbeats };
+ } catch {
+ return { ...svc, heartbeats: [] };
+ }
+ })
+ );
+ } catch (e) {
+ error = 'Não foi possível conectar ao servidor';
+ }
+
+ return { services, error };
+}