- 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
61 lines
2.0 KiB
JavaScript
61 lines
2.0 KiB
JavaScript
/**
|
||
* Holt statische GIS-Stationen-Daten für Bezirke.
|
||
* Wechselt automatisch zwischen echten Daten und Mock-Daten via .env.local
|
||
*
|
||
* @returns {Promise<Array>} Liste mit Points[]
|
||
* @throws {Error} bei Fehler oder ungültiger Antwortstruktur
|
||
*/
|
||
|
||
import { getDebugLog, getConfig } from "../../utils/configUtils";
|
||
|
||
export const fetchGisStationsStaticDistrictService = 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/gisStationsStaticDistrict";
|
||
const mockURL = `${window.location.origin}${mockBasePath}`;
|
||
if (getDebugLog()) {
|
||
console.log("🧪 Mock-Modus aktiviert: fetchGisStationsStaticDistrictService ", mockURL);
|
||
}
|
||
|
||
const res = await fetch("/api/mocks/webservice/gisStationsStaticDistrict");
|
||
if (!res.ok) {
|
||
throw new Error("Mockdaten konnten nicht geladen werden");
|
||
}
|
||
|
||
const mockData = await res.json();
|
||
if (!Array.isArray(mockData.Points)) {
|
||
throw new Error("Mockdaten enthalten kein gültiges 'Points'-Feld");
|
||
}
|
||
|
||
return mockData.Points;
|
||
} 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 idUser = params.get("u");
|
||
|
||
const url = `${baseUrl}/GisStationsStaticDistrict?idMap=${idMap}&idUser=${idUser}`;
|
||
if (getDebugLog()) {
|
||
console.log("📡 fetchGisStationsStaticDistrictService URL:", url);
|
||
}
|
||
|
||
const response = await fetch(url);
|
||
if (!response.ok) {
|
||
const message = `❌ Fehler: ${response.status} ${response.statusText}`;
|
||
console.error(message);
|
||
throw new Error(message);
|
||
}
|
||
|
||
const jsonResponse = await response.json();
|
||
if (!Array.isArray(jsonResponse.Points)) {
|
||
throw new Error("Antwortstruktur ungültig – 'Points' fehlt");
|
||
}
|
||
|
||
return jsonResponse.Points;
|
||
}
|
||
};
|