feat(loop): Mock-Backend für Schleifenmessung über ENV-Flag integriert

- NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START in .env.development hinzugefügt
- goLoop.ts aktualisiert, um im Mock-Modus die Dummy-API (/api/cpl/loopMessungStartenMockHandler) aufzurufen
- Neuer Mock-Handler loopMessungStartenMockHandler.ts erstellt, der eine simulierte Antwort zurückgibt

Damit können Entwickler die Schleifenmessung lokal testen, ohne echte Hardware.
This commit is contained in:
Ismail Ali
2025-04-17 23:46:28 +02:00
parent ce32d90ee7
commit a300ad9f6b
4 changed files with 55 additions and 29 deletions

View File

@@ -1,36 +1,53 @@
export const goLoop = (
// /utils/goLoop.ts
export const goLoop = async (
slotIndex: number,
setLoading: (loading: boolean) => void
) => {
if (slotIndex >= 32) {
if (slotIndex >= 32) return;
setLoading(true);
const isMock = process.env.NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START === "true";
if (isMock) {
// 🔁 MOCK-MODUS
try {
const response = await fetch(
`/api/cpl/loopMessungStartenMockHandler?slot=${slotIndex + 1}`
);
const data = await response.json();
alert(`(MOCK) ${data.message}`);
console.log("(MOCK)", data.message);
} catch (error) {
console.error("(MOCK) Fehler:", error);
} finally {
setLoading(false);
}
return;
}
const slotFormat = slotIndex < 10 ? `${slotIndex}` : `${slotIndex}`;
setLoading(true);
alert(`Schleifenmessung wird für Slot ${slotIndex + 1} gestartet...`);
fetch(`/CPL?kabelueberwachung.html&KS_${slotFormat}=1&slot=${slotIndex}`, {
method: "GET",
})
.then((response) => {
if (response.ok) {
alert(
`Schleifenmessung erfolgreich gestartet für Slot ${slotIndex + 1}`
);
console.log(
"Schleifenmessung erfolgreich gestartet für Slot",
slotIndex
);
} else {
alert("Fehler beim Starten der Schleifenmessung.");
console.error("Fehler beim Senden der Schleifen-Anfrage");
// 🚀 ECHTER Backend-Request
try {
const slotFormat = slotIndex < 10 ? `${slotIndex}` : `${slotIndex}`;
const response = await fetch(
`/CPL?kabelueberwachung.html&KS_${slotFormat}=1&slot=${slotIndex}`,
{
method: "GET",
}
})
.catch((error) => {
alert("Ein Fehler ist aufgetreten.");
console.error("Fehler:", error);
})
.finally(() => setLoading(false));
);
if (response.ok) {
alert(`Schleifenmessung erfolgreich gestartet für Slot ${slotIndex + 1}`);
console.log("Schleifenmessung gestartet für Slot", slotIndex);
} else {
alert("Fehler beim Starten der Schleifenmessung.");
console.error("Fehler beim Senden der Schleifen-Anfrage");
}
} catch (error) {
alert("Ein Fehler ist aufgetreten.");
console.error("Fehler:", error);
} finally {
setLoading(false);
}
};