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
This commit is contained in:
@@ -3,12 +3,12 @@
|
||||
export const fetchAllTDMDataFromServer = async (): Promise<any[]> => {
|
||||
if (typeof window === "undefined") return [];
|
||||
|
||||
const isDev = window.location.hostname === "localhost";
|
||||
const isDev = process.env.NEXT_PUBLIC_NODE_ENV === "development";
|
||||
|
||||
const slotRequests = Array.from({ length: 32 }, (_, i) => {
|
||||
const url = isDev
|
||||
? `/CPLmockData/TDM/slot${i}.json` // ✅ korrekt für DEV (Dateien im public-Ordner)
|
||||
: `${window.location.origin}/CPL?Service/empty.acp&TDM=${i}`; // ✅ korrekt für PROD
|
||||
? `/CPLmockData/TDM/slot${i}.json` // ✅ Entwicklung: aus public-Ordner
|
||||
: `${window.location.origin}/CPL?Service/empty.acp&TDM=${i}`; // ✅ Produktion
|
||||
|
||||
return fetch(url)
|
||||
.then((res) => (res.ok ? res.json() : null))
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
// /services/fetchAllTDRChartData.ts
|
||||
|
||||
const getTDRBasePath = () => {
|
||||
if (typeof window !== "undefined") {
|
||||
return window.location.hostname === "localhost"
|
||||
? "/CPLmockData/LastTDR/jsonDatei"
|
||||
: "/CPL?/CPL/LastTDR";
|
||||
}
|
||||
return "";
|
||||
};
|
||||
|
||||
export const fetchAllTDRChartDataFromServer = async (): Promise<any[]> => {
|
||||
const basePath = getTDRBasePath();
|
||||
const isDev = process.env.NEXT_PUBLIC_NODE_ENV === "development";
|
||||
|
||||
const basePath = isDev
|
||||
? "/CPLmockData/LastTDR/jsonDatei"
|
||||
: "/CPL?/CPL/LastTDR";
|
||||
|
||||
const fileNames = Array.from({ length: 32 }, (_, i) => `slot${i}.json`);
|
||||
|
||||
const fetchPromises = fileNames.map(async (fileName) => {
|
||||
@@ -20,7 +16,7 @@ export const fetchAllTDRChartDataFromServer = async (): Promise<any[]> => {
|
||||
throw new Error(`Fehler bei ${fileName}: ${response.statusText}`);
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error(`Fehler beim Laden von ${fileName}:`, error);
|
||||
console.error(`❌ Fehler beim Laden von ${fileName}:`, error);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
const getTDRReferenceBasePath = () => {
|
||||
if (typeof window !== "undefined") {
|
||||
return window.location.hostname === "localhost"
|
||||
const env = process.env.NEXT_PUBLIC_NODE_ENV;
|
||||
return env === "development"
|
||||
? "/CPLMockData/tdr-reference-curves"
|
||||
: "/CPL?/CPL/tdr-reference-curves";
|
||||
}
|
||||
|
||||
@@ -1,42 +1,50 @@
|
||||
// ✅ Service: /services/fetchAnalogeEingaenge.ts
|
||||
// services/fetchAnalogeEingaenge.ts
|
||||
|
||||
export const fetchAnalogeEingaenge = async () => {
|
||||
export const fetchAnalogeEingaenge = async (): Promise<Record<
|
||||
string,
|
||||
any
|
||||
> | null> => {
|
||||
try {
|
||||
if (typeof window === "undefined") return null;
|
||||
|
||||
// ✅ Pfad je nach Umgebung
|
||||
const scriptSrc =
|
||||
process.env.NODE_ENV === "production"
|
||||
? "/CPL?/CPL/SERVICE/ae.js"
|
||||
: "/CPLmockData/SERVICE/ae.js";
|
||||
// Umgebungserkennung: localhost = Entwicklung, alles andere = Produktion
|
||||
const isDevelopment = process.env.NEXT_PUBLIC_NODE_ENV === "development";
|
||||
|
||||
// Skriptpfad abhängig von der Umgebung
|
||||
const scriptSrc = isDevelopment
|
||||
? "/CPLmockData/SERVICE/ae.js"
|
||||
: "/CPL?/CPL/SERVICE/ae.js";
|
||||
|
||||
// Skript dynamisch laden
|
||||
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 ae.js");
|
||||
script.onerror = () => reject(`❌ Fehler beim Laden von ${scriptSrc}`);
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
|
||||
const formattedData: Record<string, any> = {};
|
||||
// Analoge Eingänge parsen (1 bis 8)
|
||||
const result: Record<string, any> = {};
|
||||
for (let i = 1; i <= 8; i++) {
|
||||
const varName = `win_analogeEingaenge${i}`;
|
||||
const raw = (window as any)[varName];
|
||||
if (raw && Array.isArray(raw)) {
|
||||
formattedData[varName] = {
|
||||
id: raw[0],
|
||||
value: raw[1],
|
||||
name: raw[2],
|
||||
uW: raw[3] === 1,
|
||||
uG: raw[4] === 1,
|
||||
oW: raw[5] === 1,
|
||||
oG: raw[6] === 1,
|
||||
const data = (window as any)[varName];
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
result[varName] = {
|
||||
id: data[0],
|
||||
value: data[1],
|
||||
name: data[2],
|
||||
untererWarnwert: data[3] === 1,
|
||||
untererGrenzwert: data[4] === 1,
|
||||
obererWarnwert: data[5] === 1,
|
||||
obererGrenzwert: data[6] === 1,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return formattedData;
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error("❌ Fehler beim Laden der analogen Eingänge:", error);
|
||||
return null;
|
||||
|
||||
@@ -5,7 +5,7 @@ export const fetchDigitalOutputs = async () => {
|
||||
|
||||
// ✅ da.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung)
|
||||
const scriptSrc =
|
||||
process.env.NODE_ENV === "production"
|
||||
process.env.NEXT_PUBLIC_NODE_ENV === "production"
|
||||
? "/CPL?/CPL/SERVICE/da.js"
|
||||
: "/CPLmockData/SERVICE/da.js";
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ export const fetchDigitaleEingaenge = async () => {
|
||||
|
||||
// ✅ de.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung)
|
||||
const scriptSrc =
|
||||
process.env.NODE_ENV === "production"
|
||||
process.env.NEXT_PUBLIC_NODE_ENV === "production"
|
||||
? "/CPL?/CPL/SERVICE/de.js"
|
||||
: "/CPLmockData/SERVICE/de.js";
|
||||
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
// ✅ Service: /services/fetchKueData.ts
|
||||
|
||||
const devScriptPath = "/CPLmockData/SERVICE/kueData.js";
|
||||
const prodScriptPath = "/CPL?/CPL/SERVICE/kueData.js";
|
||||
|
||||
export const fetchKueData = async () => {
|
||||
try {
|
||||
if (typeof window === "undefined") return null;
|
||||
|
||||
const scriptPath =
|
||||
process.env.NEXT_PUBLIC_NODE_ENV === "production"
|
||||
? prodScriptPath
|
||||
: devScriptPath;
|
||||
|
||||
// ✅ Nur bei Bedarf nachladen
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const script = document.createElement("script");
|
||||
script.src = "/CPLmockData/SERVICE/kueData.js"; // In Produktion ggf. /CPL/SERVICE/kueData.js
|
||||
script.src = scriptPath;
|
||||
script.async = true;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () => reject("❌ Fehler beim Laden von kueData.js");
|
||||
@@ -42,7 +50,7 @@ export const fetchKueData = async () => {
|
||||
tdrLocation: win.win_tdrLocation || [],
|
||||
tdrActive: win.win_tdrActive || [],
|
||||
tdrLast: win.win_tdrLast || [],
|
||||
tdrOverflow: win.win_kueOverflow || [],
|
||||
tdrOverflow: win.win_kueOverflow || [], // ggf. abgleichen, ob tdrOverflow separat existiert
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("❌ Fehler beim Laden der KÜE-Daten:", error);
|
||||
|
||||
@@ -7,7 +7,7 @@ export const fetchLast20MessagesFromWindow = async (): Promise<
|
||||
|
||||
// ✅ Start.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung)
|
||||
const scriptSrc =
|
||||
process.env.NODE_ENV === "production"
|
||||
process.env.NEXT_PUBLIC_NODE_ENV === "production"
|
||||
? "/CPL?/CPL/SERVICE/Start.js"
|
||||
: "/CPLmockData/SERVICE/Start.js";
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ const getApiUrl = (
|
||||
? "schleifenwiderstand"
|
||||
: "unbekannterTyp";
|
||||
|
||||
return process.env.NODE_ENV === "development"
|
||||
return process.env.NEXT_PUBLIC_NODE_ENV === "development"
|
||||
? `/CPLmockData/kuesChartData/slot${slotNumber}/${typeFolder}/${mode}.json`
|
||||
: `${window.location.origin}/CPL?seite.ACP&${mode}=${formatDate(
|
||||
vonDatum
|
||||
|
||||
@@ -6,7 +6,7 @@ export const fetchOpcUaSettings = async () => {
|
||||
|
||||
// ✅ opcua.js nur bei Bedarf nachladen (Pfad abhängig von Umgebung)
|
||||
const scriptSrc =
|
||||
process.env.NODE_ENV === "production"
|
||||
process.env.NEXT_PUBLIC_NODE_ENV === "production"
|
||||
? "/CPL?/CPL/SERVICE/opcua.js"
|
||||
: "/CPLmockData/SERVICE/opcua.js";
|
||||
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
// /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 = "/CPLmockData/SERVICE/System.js"; // ggf. anpassen
|
||||
script.src = scriptSrc;
|
||||
script.async = true;
|
||||
script.onload = () => resolve();
|
||||
script.onerror = () => reject("❌ Fehler beim Laden von System.js");
|
||||
script.onerror = () => reject("❌ Fehler beim Laden von system.js");
|
||||
document.body.appendChild(script);
|
||||
});
|
||||
|
||||
@@ -40,7 +45,7 @@ export const fetchSystemSettings = async () => {
|
||||
ntp3: win_ntp3,
|
||||
ntpTimezone: win_ntpTimezone,
|
||||
ntpActive: win_ntpActive === "1",
|
||||
appVersion: win_appVersion, // ✅ jetzt korrekt
|
||||
appVersion: win_appVersion,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("❌ Fehler beim Laden der Systemdaten:", error);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
export const fetchTDRChartDataById = async (
|
||||
id: number
|
||||
): Promise<any[] | null> => {
|
||||
const isDev = process.env.NODE_ENV === "development";
|
||||
const isDev = process.env.NEXT_PUBLIC_NODE_ENV === "development";
|
||||
|
||||
const url = isDev
|
||||
? `http://localhost:3000/CPLmockData/Last100TDR/kue_01/id/${id}.json`
|
||||
|
||||
Reference in New Issue
Block a user