- Mock-API-Endpunkte unter pages/api/mocks/webservice erstellt (JSON-basiert) - Zentrale Variable NEXT_PUBLIC_USE_MOCKS zur Modussteuerung eingeführt - fetchGis*-Services rufen je nach Modus reale oder Mockdaten ab - Alert-Hinweis im UI für aktive Mockumgebung eingebaut - .env.production sichert produktives Verhalten (Mocks deaktiviert) - mockData-Verzeichnis via .gitignore vom Repo ausgeschlossen - appVersion.js auf 1.1.231 erhöht
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
export const fetchGisLinesStatusService = async () => {
|
|
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
|
|
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
|
|
|
|
if (useMocks) {
|
|
console.log("🧪 Mock-Modus aktiviert: fetchGisLinesStatusService");
|
|
|
|
const response = await fetch("/api/mocks/webservice/gisLinesStatus");
|
|
if (!response.ok) {
|
|
throw new Error("Mockdaten konnten nicht geladen werden");
|
|
}
|
|
|
|
const mockData = await response.json();
|
|
|
|
if (!Array.isArray(mockData.Statis)) {
|
|
throw new Error("Ungültige Struktur: 'Status' fehlt im Mock");
|
|
}
|
|
|
|
return mockData.Statis;
|
|
} else {
|
|
const baseUrl = `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx`;
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
const idMap = params.get("m");
|
|
|
|
const url = `${baseUrl}/GisLinesStatus?idMap=${idMap}`;
|
|
console.log("📡 fetchGisLinesStatusService URL:", url);
|
|
|
|
const response = await fetch(url);
|
|
if (!response.ok) {
|
|
throw new Error("Fehler beim Laden der Linienstatusdaten");
|
|
}
|
|
|
|
const text = await response.text();
|
|
|
|
let json;
|
|
try {
|
|
json = JSON.parse(text);
|
|
} catch (e) {
|
|
console.error("❌ Fehler beim JSON-Parsing der Antwort:", text);
|
|
throw new Error("Antwort ist kein gültiges JSON");
|
|
}
|
|
|
|
if (!Array.isArray(json.Statis)) {
|
|
throw new Error("Ungültige Antwortstruktur: Statis fehlt");
|
|
}
|
|
|
|
return json.Statis;
|
|
}
|
|
};
|