From bf8b1d0d49703e82cf8162399405984bd0b3fe88 Mon Sep 17 00:00:00 2001
From: zwlucas <lucas.fariamo08@gmail.com>
Date: Fri, 29 May 2026 18:24:59 -0300
Subject: feat: implement static file serving and Docker support, update
 frontend build process

Signed-off-by: zwlucas <lucas.fariamo08@gmail.com>
---
 frontend/src/routes/(admin)/admin/+page.svelte | 49 +++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 9 deletions(-)

(limited to 'frontend/src/routes/(admin)/admin/+page.svelte')

diff --git a/frontend/src/routes/(admin)/admin/+page.svelte b/frontend/src/routes/(admin)/admin/+page.svelte
index 7fa361d..9a48ba0 100644
--- a/frontend/src/routes/(admin)/admin/+page.svelte
+++ b/frontend/src/routes/(admin)/admin/+page.svelte
@@ -1,5 +1,7 @@
 <script lang="ts">
-	const API = 'http://localhost:8080/api';
+	import { onMount } from 'svelte';
+
+	const API = '/api';
 
 	let { data } = $props();
 
@@ -8,15 +10,42 @@
 	let services = $state<any[]>([]);
 	let showForm = $state(false);
 
-	$effect(() => {
-		if (!initialized && data) {
-			token = data.token;
-			services = data.services ?? [];
-			initialized = true;
-			fetchMaintenances();
-			fetchServerStats();
+	function getCookie(name: string) {
+		return document.cookie.split('; ').find(r => r.startsWith(name + '='))?.split('=')[1] ?? '';
+	}
+
+	async function bootstrap() {
+		if (initialized) return;
+		initialized = true;
+		token = data?.token || getCookie('auth_token') || '';
+		if (data?.services && data.services.length > 0) {
+			services = data.services;
+		} else {
+			await fetchServices();
 		}
-	});
+		fetchMaintenances();
+		fetchServerStats();
+	}
+
+	async function fetchServices() {
+		try {
+			const res = await fetch(`${API}/services`, { headers: { Authorization: `Bearer ${token}` } });
+			if (await handleUnauthorized(res)) return;
+			if (res.ok) {
+				const svcs = await res.json();
+				const withStats = await Promise.all(
+					svcs.map(async (svc: any) => {
+						try {
+							const sr = await fetch(`${API}/services/${svc.id}/stats`, { headers: { Authorization: `Bearer ${token}` } });
+							if (sr.ok) svc.stats = await sr.json();
+						} catch { /* ignore */ }
+						return svc;
+					})
+				);
+				services = withStats;
+			}
+		} catch { /* ignore */ }
+	}
 	let editingSvc: any = $state(null);
 	let saving = $state(false);
 	let formError = $state('');
@@ -24,6 +53,8 @@
 	let toggling = $state<Record<number, boolean>>({});
 
 	// maintenance state
+	onMount(bootstrap);
+
 	let maintenances = $state<any[]>([]);
 	let showMtnForm = $state(false);
 	let editingMtn: any = $state(null);
-- 
cgit v1.2.3

