From 47a663f4d27b171e1d202c9c105fba88e397aee0 Mon Sep 17 00:00:00 2001 From: ISA Date: Tue, 11 Feb 2025 13:10:04 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Dynamische=20API-URL=20f=C3=BCr=20Produ?= =?UTF-8?q?ction=20&=20Development=20+=20JSON-Server=20Hinweis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - API-URL passt sich automatisch an die Umgebung an: - In Development (`npm run dev`) wird `http://localhost:3001/kabelueberwachung` genutzt. - In Production (`npm run build && npm start`) wird `window.location.origin/CPL` verwendet. - Verbesserte Fehlerbehandlung für JSON-Antworten implementiert. - **Hinweis:** Für die lokale Entwicklung wird `json-server` benötigt. Installation: `npm install -g json-server` Starten: `json-server --watch mockData.json --port 3001` --- .env.development | 2 +- .env.production | 1 + .../kueModal/LoopTDRChartActionBar.tsx | 50 +++++++++++++++---- config/webVersion.ts | 2 +- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/.env.development b/.env.development index da89f5b..c712d00 100644 --- a/.env.development +++ b/.env.development @@ -1,4 +1,4 @@ NEXT_PUBLIC_NODE_ENV=development NEXT_PUBLIC_ENCRYPTION_KEY=1 NEXT_PUBLIC_ENCRYPTION_IV=1 - +NEXT_PUBLIC_CPL_API_URL=http://localhost:3000/api/mockCPL diff --git a/.env.production b/.env.production index 7503ab2..2a65291 100644 --- a/.env.production +++ b/.env.production @@ -1,3 +1,4 @@ NEXT_PUBLIC_NODE_ENV=production NEXT_PUBLIC_ENCRYPTION_KEY=1 NEXT_PUBLIC_ENCRYPTION_IV=1 +NEXT_PUBLIC_CPL_API_PATH=/CPL diff --git a/components/modales/kueModal/LoopTDRChartActionBar.tsx b/components/modales/kueModal/LoopTDRChartActionBar.tsx index 775d676..3c8a27c 100644 --- a/components/modales/kueModal/LoopTDRChartActionBar.tsx +++ b/components/modales/kueModal/LoopTDRChartActionBar.tsx @@ -2,19 +2,51 @@ import React, { useState } from "react"; import DateRangePicker from "./DateRangePicker"; const LoopTDRChartActionBar: React.FC = () => { - const [vonDatum, setVonDatum] = useState(new Date()); - const [bisDatum, setBisDatum] = useState(new Date()); + // Dynamische Basis-URL + const BASE_URL = + process.env.NODE_ENV === "development" + ? process.env.NEXT_PUBLIC_MOCK_API || + "http://localhost:3001/kabelueberwachung" + : `${window.location.origin}/CPL`; // Automatische Anpassung in Production + + const [vonDatum, setVonDatum] = useState(null); + const [bisDatum, setBisDatum] = useState(null); const handleAktualisieren = () => { - const von = vonDatum.toISOString().split("T")[0]; // Format: YYYY-MM-DD + if (!vonDatum || !bisDatum) { + console.error("❌ Bitte wählen Sie ein gültiges Datum aus."); + return; + } + + // Datum formatieren + const von = vonDatum.toISOString().split("T")[0]; const bis = bisDatum.toISOString().split("T")[0]; - console.log(`Daten abrufen für Zeitraum: ${von} bis ${bis}`); - // API-Call hier mit den neuen Daten (z.B. location.href="...&DIA1=von;bis") - const host = window.location.host; - //const testUrl = `https://${host}?DIA1=${von};${bis}`; - const testUrl = - "https://10.10.0.118/CPL?kabelueberwachung&DIA1=2025;01;01;2025;07;31;2;4"; + const [vonJahr, vonMonat, vonTag] = von.split("-"); + const [bisJahr, bisMonat, bisTag] = bis.split("-"); + + // **Dynamische API-URL für Production und Development** + const apiUrl = `${BASE_URL}?seite.ACP&DIA1=${vonJahr};${vonMonat};${vonTag};${bisJahr};${bisMonat};${bisTag};2;4`; + + console.log("📡 API URL:", apiUrl); + + fetch(apiUrl) + .then((res) => { + if (!res.ok) { + throw new Error(`HTTP Fehler! Status: ${res.status}`); + } + return res.text(); + }) + .then((text) => { + console.log("⬇️ API Antwort (Rohdaten):", text); + try { + const data = JSON.parse(text); + console.log("✅ API Antwort (JSON):", data); + } catch (error) { + console.error("❌ Fehler: Antwort ist kein JSON!", text); + } + }) + .catch((err) => console.error("❌ Fehler beim Abrufen der Daten:", err)); }; return ( diff --git a/config/webVersion.ts b/config/webVersion.ts index 4c28f95..508adf5 100644 --- a/config/webVersion.ts +++ b/config/webVersion.ts @@ -5,5 +5,5 @@ 2: Patch oder Hotfix (Bugfixes oder kleine Änderungen). */ -const webVersion = "1.0.6.5"; +const webVersion = "1.0.6.6"; export default webVersion;