fix: add DOMContentLoaded wrapper and error handling to vue init
Deploy API / deploy (push) Failing after 13s

This commit is contained in:
2026-04-26 21:34:40 +02:00
parent 4bb31fe82a
commit 56733c6483
+27 -4
View File
@@ -3,6 +3,7 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>RoggioApp - API Dashboard</title> <title>RoggioApp - API Dashboard</title>
<!-- Lade Vue 3 Global Build (kein Modul-Zwang) -->
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://cdn.tailwindcss.com"></script> <script src="https://cdn.tailwindcss.com"></script>
</head> </head>
@@ -10,6 +11,11 @@
<div id="app" class="container mx-auto p-8"> <div id="app" class="container mx-auto p-8">
<h1 class="text-4xl font-bold mb-8 text-indigo-600">RoggioApp Dashboard</h1> <h1 class="text-4xl font-bold mb-8 text-indigo-600">RoggioApp Dashboard</h1>
<div v-if="error" class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative mb-4">
<strong class="font-bold">Fehler!</strong>
<span class="block sm:inline">{{ error }}</span>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-8"> <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
<!-- UNITS SECTION --> <!-- UNITS SECTION -->
@@ -64,6 +70,8 @@
</div> </div>
<script> <script>
document.addEventListener("DOMContentLoaded", () => {
try {
const { createApp } = Vue const { createApp } = Vue
createApp({ createApp({
@@ -72,18 +80,29 @@
units: [], units: [],
events: [], events: [],
newUnit: { name: '', traits: '{"is_rentable": true}' }, newUnit: { name: '', traits: '{"is_rentable": true}' },
newEvent: { unitId: '', type: 'booking' } newEvent: { unitId: '', type: 'booking' },
error: null
} }
}, },
methods: { methods: {
async fetchUnits() { async fetchUnits() {
try {
const res = await fetch('/api/units'); const res = await fetch('/api/units');
if (!res.ok) throw new Error("API Fehler beim Laden der Units");
const data = await res.json(); const data = await res.json();
this.units = data.map(u => ({ ...u, traitsRaw: JSON.stringify(u.traits, null, 2) })); this.units = data.map(u => ({ ...u, traitsRaw: JSON.stringify(u.traits || {}, null, 2) }));
} catch(e) {
this.error = e.message;
}
}, },
async fetchEvents() { async fetchEvents() {
try {
const res = await fetch('/api/events'); const res = await fetch('/api/events');
if (!res.ok) throw new Error("API Fehler beim Laden der Events");
this.events = await res.json(); this.events = await res.json();
} catch(e) {
this.error = e.message;
}
}, },
getUnitName(id) { getUnitName(id) {
const u = this.units.find(u => u.id === id); const u = this.units.find(u => u.id === id);
@@ -95,14 +114,14 @@
await fetch('/api/units', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify(body) }); await fetch('/api/units', { method: 'POST', headers: {'Content-Type':'application/json'}, body: JSON.stringify(body) });
this.newUnit.name = ''; this.newUnit.name = '';
this.fetchUnits(); this.fetchUnits();
} catch(e) { alert("Invalid JSON in Traits"); } } catch(e) { alert("Fehler: " + e.message); }
}, },
async updateUnit(unit) { async updateUnit(unit) {
try { try {
const body = { name: unit.name, traits: JSON.parse(unit.traitsRaw) }; const body = { name: unit.name, traits: JSON.parse(unit.traitsRaw) };
await fetch(\`/api/units/\${unit.id}\`, { method: 'PUT', headers: {'Content-Type':'application/json'}, body: JSON.stringify(body) }); await fetch(\`/api/units/\${unit.id}\`, { method: 'PUT', headers: {'Content-Type':'application/json'}, body: JSON.stringify(body) });
alert("Gespeichert!"); alert("Gespeichert!");
} catch(e) { alert("Invalid JSON"); } } catch(e) { alert("Invalid JSON: " + e.message); }
}, },
async deleteUnit(id) { async deleteUnit(id) {
await fetch(\`/api/units/\${id}\`, { method: 'DELETE' }); await fetch(\`/api/units/\${id}\`, { method: 'DELETE' });
@@ -123,6 +142,10 @@
this.fetchEvents(); this.fetchEvents();
} }
}).mount('#app') }).mount('#app')
} catch (err) {
document.body.innerHTML += "<div style='color:red; padding: 20px;\>Kritischer Fehler beim Starten von Vue: " + err.message + "</div>";
}
});
</script> </script>
</body> </body>
</html> </html>