diff --git a/.env.development b/.env.development index 799f570..f72321b 100644 --- a/.env.development +++ b/.env.development @@ -1,3 +1,4 @@ NEXT_PUBLIC_NODE_ENV=development NEXT_PUBLIC_ENCRYPTION_KEY=1 NEXT_PUBLIC_ENCRYPTION_IV=1 +NEXT_PUBLIC_USE_MOCK_BACKEND_TDR_START=true diff --git a/config/webVersion.ts b/config/webVersion.ts index 492606e..ea07764 100644 --- a/config/webVersion.ts +++ b/config/webVersion.ts @@ -6,5 +6,5 @@ 2: Patch oder Hotfix (Bugfixes oder kleine Änderungen). */ -const webVersion = "1.6.242"; +const webVersion = "1.6.243"; export default webVersion; diff --git a/pages/api/cpl/tdrMessungStartenMockHandler.ts b/pages/api/cpl/tdrMessungStartenMockHandler.ts new file mode 100644 index 0000000..eb7cd98 --- /dev/null +++ b/pages/api/cpl/tdrMessungStartenMockHandler.ts @@ -0,0 +1,7 @@ +// pages/api/cpl/tdrMessungStartenMockHandler.ts +export default function handler(req, res) { + const { slot } = req.query; + setTimeout(() => { + res.status(200).json({ message: `TDR simuliert für Slot ${slot}` }); + }, 1000); +} diff --git a/utils/goTDR.ts b/utils/goTDR.ts index 5ce0c8d..ea45957 100644 --- a/utils/goTDR.ts +++ b/utils/goTDR.ts @@ -1,38 +1,53 @@ -export const goTDR = ( +// /utils/goTDR.ts +export const goTDR = async ( slotIndex: number, setLoading: (loading: boolean) => void ) => { - if (slotIndex >= 32) { + if (slotIndex >= 32) return; + + setLoading(true); + + // ✅ ENV-Variable prüfen (funktioniert nur mit NEXT_PUBLIC_) + const isMock = process.env.NEXT_PUBLIC_USE_MOCK_BACKEND_TDR_START === "true"; + + if (isMock) { + // 🔁 MOCK-MODUS + try { + const response = await fetch( + `/api/cpl/tdrMessungStartenMockHandler?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(`TDR wird für Slot ${slotIndex + 1} gestartet...`); - - fetch( - //`${window.location.origin}/CPL?Service/Kabelueberwachung.html&KTT${slotFormat}=1&slot=${slotIndex}`, - `${window.location.origin}/CPL?Service/Kabelueberwachung.html&KTT${slotIndex}=1`, - { - method: "GET", - } - ) - .then((response) => { - if (response.ok) { - alert( - `TDR Messung der KÜ705-FO Strecke ${slotIndex + 1} wurde durchgeführt` - ); - /* alert( - `TDR erfolgreich gestartet für Slot format ${Number(slotFormat) + 1}` - ); */ - console.log("TDR erfolgreich gestartet für Slot", slotIndex + 1); - } else { - console.error("Fehler beim Senden der TDR-Anfrage"); + // 🚀 ECHTER Backend-Aufruf über CGI + try { + const response = await fetch( + `${window.location.origin}/CPL?Service/Kabelueberwachung.html&KTT${slotIndex}=1`, + { + method: "GET", } - }) - .catch((error) => { - console.error("Fehler:", error); - }) - .finally(() => setLoading(false)); + ); + + if (response.ok) { + alert( + `TDR Messung der KÜ705-FO Strecke ${slotIndex + 1} wurde durchgeführt` + ); + console.log("TDR erfolgreich gestartet für Slot", slotIndex + 1); + } else { + console.error("Fehler beim Senden der TDR-Anfrage"); + } + } catch (error) { + console.error("Fehler:", error); + } finally { + setLoading(false); + } };