feat: automatische Moduserkennung für fetchAnalogInputsService.ts implementiert

- Modus wird anhand von window.location.hostname bestimmt
- Lokale Umgebung (localhost/127.0.0.1) nutzt Mock-API
- Produktionsumgebung lädt analogInputs.json via CGI
- Kein Bedarf mehr für manuelle .env-Konfiguration
This commit is contained in:
ISA
2025-07-09 09:59:53 +02:00
parent eca52f35cb
commit 340990573f
7 changed files with 85 additions and 51 deletions

View File

@@ -6,6 +6,6 @@ NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START=false
NEXT_PUBLIC_EXPORT_STATIC=false NEXT_PUBLIC_EXPORT_STATIC=false
NEXT_PUBLIC_USE_CGI=false NEXT_PUBLIC_USE_CGI=false
# App-Versionsnummer # App-Versionsnummer
NEXT_PUBLIC_APP_VERSION=1.6.567 NEXT_PUBLIC_APP_VERSION=1.6.568
NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter) NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter)

View File

@@ -5,5 +5,5 @@ NEXT_PUBLIC_CPL_API_PATH=/CPL
NEXT_PUBLIC_EXPORT_STATIC=true NEXT_PUBLIC_EXPORT_STATIC=true
NEXT_PUBLIC_USE_CGI=true NEXT_PUBLIC_USE_CGI=true
# App-Versionsnummer # App-Versionsnummer
NEXT_PUBLIC_APP_VERSION=1.6.567 NEXT_PUBLIC_APP_VERSION=1.6.568
NEXT_PUBLIC_CPL_MODE=production NEXT_PUBLIC_CPL_MODE=production

View File

@@ -1,3 +1,13 @@
## [1.6.568] 2025-07-09
- feat: Modus-Erkennung über window.location.hostname implementiert
- Automatische Umschaltung zwischen Entwicklungs- und Produktionsmodus
- Hostname-basierte Erkennung: localhost/127.0.0.1 → "dev", sonst → "production"
- fetchDigitalInputsService.ts entsprechend angepasst
- Erleichtert Entwicklung und reduziert manuelle .env-Konfiguration
---
## [1.6.567] 2025-07-09 ## [1.6.567] 2025-07-09
- feat: CGI-kompatiblen CSV-Parser für digitale Eingänge implementiert - feat: CGI-kompatiblen CSV-Parser für digitale Eingänge implementiert

View File

@@ -1,21 +1,63 @@
{ {
"win_analogInputsValues": [ "win_analogInputsValues": [
4.771072, 5.665244, 0.005467, -0.007468, 0.000002, 0.000001, 0.000001, "126.630287",
0.000007 "5.667177",
"-0.000531",
"0.012762",
"-0.000001",
"0.000009",
"-0.000002",
"-0.000012"
], ],
"win_analogInputsLabels": [ "win_analogInputsLabels": [
"AE 1", "'AE 1'",
"AE 2", "'Temperatur'",
"AE 3", "'AE 3'",
"AE 4", "'AE 4'",
"AE 5", "'AE 5'",
"AE 6", "'AE 6'",
"AE 7", "'AE 7'",
"AE 8" "'AE 8'"
], ],
"win_analogInputsOffset": [10.988, 0, 0, 0, 0, 0, 0, 0], "win_analogInputsUnits": [
"win_analogInputsFactor": [11.988, 1, 1, 1, 1, 1, 1, 1], "'V'",
"win_analogInputsUnits": ["V", "V", "V", "V", "mA", "mA", "mA", "mA"], "'V'",
"win_analogInputsLoggerIntervall": [7, 10, 10, 10, 10, 10, 10, 10], "'V'",
"win_analogInputsWeighting": [0, 0, 0, 0, 0, 0, 0, 0] "'V'",
"'mA'",
"'mA'",
"'mA'",
"'mA'"
],
"win_analogInputsFactor": [
"21.999",
"1.000",
"1.000",
"1.000",
"1.000",
"1.000",
"1.000",
"1.000"
],
"win_analogInputsOffset": [
"21.999",
"0.000",
"0.000",
"0.000",
"0.000",
"0.000",
"0.000",
"0.000"
],
"win_analogInputsWeighting": ["0", "0", "0", "0", "0", "0", "0", "0"],
"win_analogInputsLoggerIntervall": [
"21",
"10",
"10",
"10",
"10",
"10",
"10",
"10"
]
} }

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "cpl-v4", "name": "cpl-v4",
"version": "1.6.567", "version": "1.6.568",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "cpl-v4", "name": "cpl-v4",
"version": "1.6.567", "version": "1.6.568",
"dependencies": { "dependencies": {
"@fontsource/roboto": "^5.1.0", "@fontsource/roboto": "^5.1.0",
"@headlessui/react": "^2.2.4", "@headlessui/react": "^2.2.4",

View File

@@ -1,6 +1,6 @@
{ {
"name": "cpl-v4", "name": "cpl-v4",
"version": "1.6.567", "version": "1.6.568",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev", "dev": "next dev",

View File

@@ -1,12 +1,14 @@
// services/fetchAnalogInputsService.ts // services/fetchAnalogInputsService.ts
export const fetchAnalogInputsService = async () => { export const fetchAnalogInputsService = async () => {
const mode = process.env.NEXT_PUBLIC_CPL_MODE; // 🌐 Automatische Moduserkennung über Hostname
const hostname = window.location.hostname;
const mode =
hostname === "localhost" || hostname === "127.0.0.1" ? "dev" : "production";
// ✅ PRODUKTIV: lädt JSON-Datei vom Gerät über CGI // ✅ PRODUKTIV: lädt JSON-Datei vom Gerät über CGI
if (mode === "production") { if (mode === "production") {
console.log( console.log("🔄 Lade analoge Eingänge im Produktionsmodus (JSON über CGI)");
"🔄 Lade analoge Eingänge im Produktionsmodus (JSON über CPL?)..."
);
const res = await fetch("/CPL?/CPL/SERVICE/analogInputs.json", { const res = await fetch("/CPL?/CPL/SERVICE/analogInputs.json", {
headers: { Accept: "application/json" }, headers: { Accept: "application/json" },
@@ -30,13 +32,16 @@ export const fetchAnalogInputsService = async () => {
})); }));
} }
// ✅ jsSimulatedProd-MODUS (Script einbinden und aus window lesen) // ✅ ENTWICKLUNG: Daten vom lokalen API-Mock
else if (mode === "jsSimulatedProd") { else {
console.log("🧪 Lade analoge Eingänge im Simulationsmodus (JSON)"); console.log(
"🧪 Lade analoge Eingänge im Entwicklungsmodus (Mock über API)"
);
const res = await fetch("/api/cpl/getAnalogInputsHandler"); const res = await fetch("/api/cpl/getAnalogInputsHandler");
if (!res.ok) if (!res.ok) {
throw new Error("❌ Fehler beim Laden der analogen Eingänge (Mock)"); throw new Error("❌ Fehler beim Laden der analogen Eingänge (Mock)");
}
const data = await res.json(); const data = await res.json();
@@ -51,27 +56,4 @@ export const fetchAnalogInputsService = async () => {
weighting: parseInt(data.win_analogInputsWeighting[i]), weighting: parseInt(data.win_analogInputsWeighting[i]),
})); }));
} }
// ✅ JSON-MODUS (API gibt JSON-Daten zurück)
else if (mode === "json") {
console.log("🔄 Lade analoge Eingänge im JSON-Modus...");
const res = await fetch("/api/cpl/getAnalogInputsHandler");
if (!res.ok) throw new Error("❌ Fehler beim Laden der analogen Eingänge");
const data = await res.json();
console.log("📡 Analoge Eingänge geladen:", data);
return data.win_analogInputsValues.map((value: number, i: number) => ({
id: i + 1,
value,
label: data.win_analogInputsLabels[i],
unit: data.win_analogInputsUnits[i],
offset: parseFloat(data.win_analogInputsOffset[i]),
factor: parseFloat(data.win_analogInputsFactor[i]),
loggerInterval: parseInt(data.win_analogInputsLoggerIntervall[i]),
weighting: parseInt(data.win_analogInputsWeighting[i]),
}));
} else {
throw new Error(`Unbekannter Modus: ${mode}`);
}
}; };