feat: TDR-Start mit Mock-Backend über Umgebungsvariable steuerbar gemacht
- .env.development mit NEXT_PUBLIC_USE_MOCK_BACKEND_TDR_START ergänzt - goTDR.ts überarbeitet: Mock-API oder echtes CGI-Interface je nach Modus - Verbesserte Flexibilität für Entwicklung ohne reale Hardware
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
7
pages/api/cpl/tdrMessungStartenMockHandler.ts
Normal file
7
pages/api/cpl/tdrMessungStartenMockHandler.ts
Normal file
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user