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:
@@ -2,3 +2,4 @@ NEXT_PUBLIC_NODE_ENV=development
|
||||
NEXT_PUBLIC_ENCRYPTION_KEY=1
|
||||
NEXT_PUBLIC_ENCRYPTION_IV=1
|
||||
NEXT_PUBLIC_USE_MOCK_BACKEND_TDR_START=true
|
||||
NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START=false
|
||||
|
||||
@@ -6,5 +6,5 @@
|
||||
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
|
||||
|
||||
*/
|
||||
const webVersion = "1.6.243";
|
||||
const webVersion = "1.6.244";
|
||||
export default webVersion;
|
||||
|
||||
8
pages/api/cpl/loopMessungStartenMockHandler.ts
Normal file
8
pages/api/cpl/loopMessungStartenMockHandler.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
export default function handler(req, res) {
|
||||
const { slot } = req.query;
|
||||
setTimeout(() => {
|
||||
res
|
||||
.status(200)
|
||||
.json({ message: `Schleifenmessung simuliert für Slot ${slot}` });
|
||||
}, 1000);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
// 🚀 ECHTER Backend-Request
|
||||
try {
|
||||
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}`, {
|
||||
const response = await 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
|
||||
);
|
||||
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) => {
|
||||
} catch (error) {
|
||||
alert("Ein Fehler ist aufgetreten.");
|
||||
console.error("Fehler:", error);
|
||||
})
|
||||
.finally(() => setLoading(false));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user