From 30bbb61f1c8c7e27e66539902ba033bac4ef05bf Mon Sep 17 00:00:00 2001 From: Ismail Ali Date: Sat, 17 May 2025 00:33:04 +0200 Subject: [PATCH] refactor+docs: serverURL dynamisch, NEXT_PUBLIC_SERVER_URL entfernt (v1.1.76) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - config.js verwendet nun window.location und API_PORT_MODE zur URL-Ermittlung - feste Konfiguration aus .env.local entfällt (bereinigt) - neue Dokumentation: docs/frontend/config/config.md - CHANGELOG.md aktualisiert (v1.1.76) --- .env.local | 2 +- CHANGELOG.md | 16 +++++++ components/mainComponent/MapComponent.js | 2 +- config/appVersion.js | 2 +- config/config.js | 5 +- docs/frontend/config/config.md | 58 ++++++++++++++++++++++++ 6 files changed, 81 insertions(+), 4 deletions(-) create mode 100644 docs/frontend/config/config.md diff --git a/.env.local b/.env.local index 6760c225d..926b980f6 100644 --- a/.env.local +++ b/.env.local @@ -7,7 +7,7 @@ DB_NAME=talas_v5 DB_PORT=3306 # Public Settings (Client braucht IP/Domain) , Variablen mit dem Präfix "NEXT_PUBLIC" ist in Browser sichtbar -NEXT_PUBLIC_SERVER_URL="http://10.10.0.70" +NEXT_PUBLIC_SERVER_URL="http://192.168.10.33" NEXT_PUBLIC_ENABLE_GEOCODER=true NEXT_PUBLIC_USE_MOCK_API=false NEXT_PUBLIC_DEBUG_LOG=true diff --git a/CHANGELOG.md b/CHANGELOG.md index 85030bd4f..72660352c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,22 @@ Alle bedeutenden Änderungen an diesem Projekt werden in dieser Datei dokumentie --- +## [1.1.76] – 2025-05-17 + +### Changed + +- `config.js` angepasst: + - Entfernt: `NEXT_PUBLIC_SERVER_URL` aus `.env.local` + - Dynamische Berechnung von `serverURL` anhand `window.location` + `NEXT_PUBLIC_API_PORT_MODE` + - Zugriff auf Webservices funktioniert jetzt automatisch abhängig von Entwicklungs-/Produktionsumgebung + +### Added + +- Dokumentation ergänzt: + - `docs/frontend/config/config.md` + +--- + ## [1.1.75] – 2025-05-17 ### Changed diff --git a/components/mainComponent/MapComponent.js b/components/mainComponent/MapComponent.js index 7a7d22447..309f283a6 100644 --- a/components/mainComponent/MapComponent.js +++ b/components/mainComponent/MapComponent.js @@ -15,7 +15,7 @@ import { InformationCircleIcon } from "@heroicons/react/20/solid"; import PoiUpdateModal from "../pois/PoiUpdateModal.js"; import { ToastContainer, toast } from "react-toastify"; import plusRoundIcon from "../PlusRoundIcon.js"; -import { createAndSetDevices } from "../../utils/createAndSetDevices.js"; +import { createAndSetDevices } from "../../utils/devices/createAndSetDevices.js"; import { restoreMapSettings, checkOverlappingMarkers } from "../../utils/mapUtils.js"; import { APP_VERSION } from "../../config/appVersion.js"; import * as layers from "../../config/layers.js"; diff --git a/config/appVersion.js b/config/appVersion.js index a1c560fc4..711bafd18 100644 --- a/config/appVersion.js +++ b/config/appVersion.js @@ -1,2 +1,2 @@ // /config/appVersion -export const APP_VERSION = "1.1.76"; +export const APP_VERSION = "1.1.77"; diff --git a/config/config.js b/config/config.js index c8c63a324..4d3a6f8c9 100644 --- a/config/config.js +++ b/config/config.js @@ -7,7 +7,10 @@ const standardSideMenu = true; const fullSideMenu = false; // Server-URL aus Umgebungsvariable holen (nur bei echter API benötigt) -const serverURL = process.env.NEXT_PUBLIC_SERVER_URL || ""; +const mode = process.env.NEXT_PUBLIC_API_PORT_MODE; + +const serverURL = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80` : `${window.location.origin}`; + if (!serverURL && !isMockMode()) { throw new Error("Die Umgebungsvariable NEXT_PUBLIC_SERVER_URL ist nicht gesetzt!"); } diff --git a/docs/frontend/config/config.md b/docs/frontend/config/config.md new file mode 100644 index 000000000..0d83f1ddb --- /dev/null +++ b/docs/frontend/config/config.md @@ -0,0 +1,58 @@ +# ⚙️ config.js – zentrale Konfiguration und Umgebungssteuerung + +## Zweck + +Diese Datei enthält zentrale Konfigurationswerte, die abhängig von der Umgebung +(Entwicklung oder Produktion) dynamisch erzeugt werden. + +--- + +## Ersetzungen von Umgebungsvariablen + +Vorher wurden folgende `.env.local` Variablen verwendet: + +- `NEXT_PUBLIC_BASE_URL` +- `NEXT_PUBLIC_SERVER_URL` + +Diese wurden ersetzt durch dynamische Berechnung anhand von: + +```env +NEXT_PUBLIC_API_PORT_MODE=dev +``` + +--- + +## Dynamische Berechnung von `serverURL` + +Die Konfiguration entscheidet anhand des Modus: + +```js +const mode = process.env.NEXT_PUBLIC_API_PORT_MODE; + +const serverURL = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80` : `${window.location.origin}`; +``` + +→ Dadurch funktioniert der Code ohne Anpassung bei IP-/Server-Wechseln oder Portunterschieden. + +--- + +## Konfigurationswerte + +- `USE_MOCK_API`: aktiviert lokale Mock-Daten +- `serverURL`: Basis für Webservice-Aufrufe (`/talas5/...`) +- `mapGisStationsStaticDistrictUrl`: komplette zusammengesetzte URL +- `useMockStationData`: true/false aus `.env.local` + +--- + +## Vorteile + +| Punkt | Vorteil | +| ------------------------------- | ---------------------------------------- | +| Keine festen IPs oder Ports | ✅ Weniger Fehler, einfacher Umzug | +| Einheitlich mit anderen Dateien | ✅ Gleiche Struktur wie Webservice-Setup | +| Lesbar & leicht anpassbar | ✅ Auch ohne Doku sofort verständlich | + +--- + +📄 Pfad: `/docs/frontend/config/config.md`