Files
CPLv4.0/services/fetchSystemSettings.ts
ISA c55f0e7fe5 feat: Umgebungsspezifisches Laden von Datenquellen implementiert
- Alle fetch-Services (TDM, TDR, analoge/digitale Eingänge/Ausgänge, SystemSettings usw.) angepasst,
  um `NEXT_PUBLIC_NODE_ENV` zu verwenden.
- Entwicklungsumgebung lädt Daten aus /CPLmockData/...
- Produktionsumgebung verwendet echte Endpunkte mit /CPL?/CPL/...
- .env.production und .env.development korrekt berücksichtigt
- loadWindowVariables, WindowVariablesInitializer und verwandte Dateien bereinigt
- Mockdaten erscheinen nicht mehr versehentlich in Produktionsumgebung
2025-03-27 11:03:23 +01:00

55 lines
1.4 KiB
TypeScript

// /services/fetchSystemSettings.ts
export const fetchSystemSettings = async () => {
try {
if (typeof window === "undefined") return null;
const isDev = process.env.NODE_ENV === "development";
const scriptSrc =
process.env.NEXT_PUBLIC_NODE_ENV === "development"
? "/CPLmockData/SERVICE/system.js"
: "/CPL?/CPL/SERVICE/system.js";
await new Promise<void>((resolve, reject) => {
const script = document.createElement("script");
script.src = scriptSrc;
script.async = true;
script.onload = () => resolve();
script.onerror = () => reject("❌ Fehler beim Laden von system.js");
document.body.appendChild(script);
});
const {
win_deviceName,
win_mac1,
win_ip,
win_subnet,
win_gateway,
win_cplInternalTimestamp,
win_ntp1,
win_ntp2,
win_ntp3,
win_ntpTimezone,
win_ntpActive,
win_appVersion,
} = window as any;
return {
deviceName: win_deviceName,
mac1: win_mac1,
ip: win_ip,
subnet: win_subnet,
gateway: win_gateway,
cplInternalTimestamp: win_cplInternalTimestamp,
ntp1: win_ntp1,
ntp2: win_ntp2,
ntp3: win_ntp3,
ntpTimezone: win_ntpTimezone,
ntpActive: win_ntpActive === "1",
appVersion: win_appVersion,
};
} catch (error) {
console.error("❌ Fehler beim Laden der Systemdaten:", error);
return null;
}
};