Files
nodeMap/services/webservice/fetchGisLinesStatusService.js
ISA 3896381a8f Debug-Logging zentralisiert: Nutzung von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt und auf getDebugLog() mit config.json umgestellt
- Alle Vorkommen von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt
- Debug-Konfiguration erfolgt jetzt ausschließlich über public/config.json
- getDebugLog()-Utility überall verwendet
- .env-Dateien werden für Debug-Logging nicht mehr benötigt
- Alle betroffenen Komponenten, Services und API
2025-08-22 11:10:40 +02:00

67 lines
2.1 KiB
JavaScript

import { getDebugLog } from "../../utils/configUtils";
// /services/webservice/fetchGisLinesStatusService.js
let __configCache;
async function getConfig() {
if (__configCache) return __configCache;
const res = await fetch("/config.json");
if (!res.ok) throw new Error("config.json konnte nicht geladen werden");
__configCache = await res.json();
return __configCache;
}
export const fetchGisLinesStatusService = async () => {
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
const config = await getConfig();
const basePath = config.basePath || "";
if (useMocks) {
const mockBasePath = "/api/mocks/webservice/gisLinesStatus";
const mockURL = `${window.location.origin}${mockBasePath}`;
if (getDebugLog()) {
console.log("🧪 Mock-Modus aktiviert: fetchGisLinesStatusService ", mockURL);
}
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}`;
if (getDebugLog()) {
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;
}
};