Fix index.html and api

This commit is contained in:
dvirlabs 2025-07-01 06:42:30 +03:00
parent 5fa74043bc
commit d7edb08c1e
2 changed files with 13 additions and 3 deletions

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="%PUBLIC_URL%/env.js"></script> <script src="/env.js"></script>
<title>Vite + React</title> <title>Vite + React</title>
</head> </head>
<body> <body>

View File

@ -1,7 +1,10 @@
const API_BASE = import.meta.env.VITE_API_BASE; const API_BASE = window?.ENV?.API_BASE || "";
export async function fetchDiagram() { export async function fetchDiagram() {
const res = await fetch(`${API_BASE}/diagram/fetch`); const res = await fetch(`${API_BASE}/diagram/fetch`);
if (!res.ok) {
throw new Error(`Failed to fetch diagram: ${res.status}`);
}
return await res.json(); return await res.json();
} }
@ -11,11 +14,18 @@ export async function saveDiagram(data) {
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data), body: JSON.stringify(data),
}); });
if (!res.ok) {
throw new Error(`Failed to save diagram: ${res.status}`);
}
return await res.json(); return await res.json();
} }
export async function fetchIconCategories() { export async function fetchIconCategories() {
const res = await fetch(`${API_BASE}/icons`); const res = await fetch(`${API_BASE}/icons`);
if (!res.ok) {
throw new Error(`Failed to fetch icons: ${res.status}`);
}
return await res.json(); return await res.json();
} }