Files
nodeMap/services/webservice/fetchGisStationsMeasurementsService.js
ISA 34ca809ede fix:webService immer auf port 80
const baseUrl = `${window.location.protocol}//${window.location.hostname}:80${basePath}/ClientData/WebServiceMap.asmx`;
2025-06-02 15:24:11 +02:00

46 lines
1.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// /services/webservice/fetchGisStationsMeasurementsService.js
export const fetchGisStationsMeasurementsService = async () => {
const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true";
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
if (useMocks) {
console.log("🧪 Mock-Modus aktiviert: fetchGisStationsMeasurementsService");
const { mockGisStationsMeasurements } = await import("../../__mocks__/webservice/gisStationsMeasurements.js");
return mockGisStationsMeasurements.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 idUser = params.get("u");
const url = `${baseUrl}/GisStationsMeasurements?idMap=${idMap}&idUser=${idUser}`;
console.log("📡 fetchGisStationsMeasurementsService 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 text = await response.text();
let jsonResponse;
try {
jsonResponse = JSON.parse(text);
} catch (e) {
console.error("❌ Fehler beim JSON-Parsing der Antwort:", text);
throw new Error("Antwort ist kein gültiges JSON");
}
if (!jsonResponse?.Statis) {
throw new Error("Antwortstruktur ungültig 'Statis' fehlt");
}
return jsonResponse.Statis;
}
};