chore: config.js entfernt – Konfiguration zentral über .env.local

- alle Importe und Aufrufe von config.js entfernt
- Webservices nutzen direkt window.location + NEXT_PUBLIC_API_PORT_MODE
- zentrale Konfigurationsstrategie über .env.local abgeschlossen
This commit is contained in:
ISA
2025-05-22 15:02:57 +02:00
parent ef3c511694
commit b48a5b2b58
8 changed files with 44 additions and 70 deletions

View File

@@ -4,6 +4,27 @@ Alle bedeutenden Änderungen an diesem Projekt werden in dieser Datei dokumentie
--- ---
## [1.1.150] - 2025-05-22
### Removed
- `config.js` vollständig gelöscht keine Abhängigkeiten mehr im Projekt
- Funktion `isMockMode()` entfernt direkter Zugriff auf `process.env.NEXT_PUBLIC_USE_MOCK_API` ersetzt zentrale Hilfsfunktion
### Changed
- `fetchUserRightsService.js`, `fetchGisSystemStaticService.js` und `useMapComponentState.js` angepasst:
- Verwendet dynamisch `window.location` + `.env.local` statt config.js
- Verbesserte Übersichtlichkeit und zentrale Steuerung über `.env.local`
### Architecture
- Konfiguration und API-Port-Steuerung vollständig in `.env.local` ausgelagert
- Einheitliche Struktur für Webservice-Aufrufe (`window.location + mode`)
- Vereinfachtes Debugging, klarere Struktur für neue Entwickler
---
## [1.1.148] - 2025-05-22 ## [1.1.148] - 2025-05-22
### Hinzugefügt ### Hinzugefügt

View File

@@ -261,7 +261,7 @@ NEXT_PUBLIC_USE_MOCK_API=true
### Serverkonfiguration ### Serverkonfiguration
- Port 3000 muss freigegeben sein - Port 3000 muss freigegeben sein
- `.env.local`, `config.js`, `[...]path.js` und `MapComponent.js` müssen IP und API-Endpunkte korrekt konfiguriert haben - .env.local, MapComponent.js und alle Services verwenden dynamische API-Endpunkte basierend auf window.location und NEXT_PUBLIC_API_PORT_MODE
- Die Anwendung wird über einen `nssm` Windows-Service gestartet (optional) - Die Anwendung wird über einen `nssm` Windows-Service gestartet (optional)
- Browser: Chrome ab Version 125.0.6420.142 empfohlen - Browser: Chrome ab Version 125.0.6420.142 empfohlen

View File

@@ -4,7 +4,6 @@ import L from "leaflet";
import "leaflet/dist/leaflet.css"; import "leaflet/dist/leaflet.css";
import "leaflet-contextmenu/dist/leaflet.contextmenu.css"; import "leaflet-contextmenu/dist/leaflet.contextmenu.css";
import "leaflet-contextmenu"; import "leaflet-contextmenu";
import * as config from "../../config/config.js";
import "leaflet.smooth_marker_bouncing"; import "leaflet.smooth_marker_bouncing";
import OverlappingMarkerSpiderfier from "overlapping-marker-spiderfier-leaflet"; //sieht deaktiviert aber ist das nicht so und wird benötigt import OverlappingMarkerSpiderfier from "overlapping-marker-spiderfier-leaflet"; //sieht deaktiviert aber ist das nicht so und wird benötigt
import "react-toastify/dist/ReactToastify.css"; import "react-toastify/dist/ReactToastify.css";

View File

@@ -1,2 +1,2 @@
// /config/appVersion // /config/appVersion
export const APP_VERSION = "1.1.149"; export const APP_VERSION = "1.1.150";

View File

@@ -1,43 +0,0 @@
// Datei: /config/config.js
import { BASE_URL } from "../config/paths";
// Prüfen, ob Mock-Modus aktiv ist
function isMockMode() {
return process.env.NEXT_PUBLIC_USE_MOCK_API === "true";
}
// Definieren der grundlegenden Umgebungseinstellungen und Konfigurationen der Karte
const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
let serverURL = "";
if (typeof window !== "undefined") {
serverURL = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80` : `${window.location.origin}`;
}
if (typeof window !== "undefined" && !serverURL && !isMockMode()) {
throw new Error("Die Umgebungsvariable ist nicht gesetzt!");
}
if (typeof window !== "undefined") {
console.log("%c 1- serverURL in config:", "color: #006400;", serverURL);
}
// Initialisieren von Variablen, die später im Browserkontext gesetzt werden
let windowHeight, url_string, url, idMap, idUser;
// URL-Setup - dynamisch abhängig von Mock oder Echtbetrieb
if (typeof window !== "undefined") {
windowHeight = window.innerHeight;
url_string = window.location.href;
url = new URL(url_string);
console.log("%c 2- URL in config:", "color: #006400; font-size: 16px; background-color: #f0f0f0;", url);
idMap = url.searchParams.get("m");
idUser = url.searchParams.get("u");
console.log(`4- Parameter 'idMap' : ${idMap}`);
console.log(`5- Parameter 'idUser': ${idUser}`);
}
// Export der Variablen und URLs
export { serverURL, windowHeight, url_string, url, idMap, idUser, isMockMode };

View File

@@ -2,7 +2,6 @@
// POI -> Kontextmenü -> POI bearbeiten -> Dropdown Geräteauswahl // POI -> Kontextmenü -> POI bearbeiten -> Dropdown Geräteauswahl
import { useState, useEffect } from "react"; import { useState, useEffect } from "react";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { isMockMode } from "../config/config";
export const useMapComponentState = () => { export const useMapComponentState = () => {
const [poiTypData, setPoiTypData] = useState([]); const [poiTypData, setPoiTypData] = useState([]);
@@ -17,7 +16,7 @@ export const useMapComponentState = () => {
useEffect(() => { useEffect(() => {
const fetchPoiTypData = async () => { const fetchPoiTypData = async () => {
if (isMockMode()) { if (process.env.NEXT_PUBLIC_USE_MOCK_API === "true") {
console.log("⚠️ Mock-API: POI Typen geladen (Mock)"); console.log("⚠️ Mock-API: POI Typen geladen (Mock)");
const mockData = [ const mockData = [

View File

@@ -1,26 +1,25 @@
// /services/webservice/fetchUserRightsService.js // /services/webservice/fetchUserRightsService.js
import * as config from "../../config/config";
export const fetchUserRightsService = async () => { export const fetchUserRightsService = async () => {
if (config.USE_MOCK_API) { const mode = process.env.NEXT_PUBLIC_API_PORT_MODE;
console.log("⚠️ Mock-API: Benutzerrechte geladen"); const apiBaseUrl = mode === "dev" ? `${window.location.protocol}//${window.location.hostname}:80/talas5/ClientData/WebServiceMap.asmx` : `${window.location.origin}/talas5/ClientData/WebServiceMap.asmx`;
return [56, 57, 58]; // Beispielrechte
const params = new URLSearchParams(window.location.search);
const idMap = params.get("m");
const idUser = params.get("u");
const url = `${apiBaseUrl}/GetUserRights?idMap=${idMap}&idUser=${idUser}`;
const response = await fetch(url, {
method: "GET",
headers: {
Connection: "close",
},
});
if (!response.ok) {
throw new Error("Fehler beim Abrufen der Benutzerrechte");
} }
try { const json = await response.json();
const response = await fetch(`${config.serverURL}/talas5/ClientData/WebserviceMap.asmx/GisSystemStatic?idMap=${config.idMap}&idUser=${config.idUser}`, { return json.Rights || [];
method: "GET",
headers: { Connection: "close" },
});
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const data = await response.json();
if (!data || !data.Rights || !Array.isArray(data.Rights)) throw new Error("Invalid response structure");
return data.Rights.map((right) => right.IdRight);
} catch (error) {
console.error("Fehler beim Abrufen der Benutzerrechte:", error);
return [];
}
}; };

View File

@@ -5,7 +5,6 @@ import { redrawPolyline } from "./polylines/redrawPolyline.js";
import L from "leaflet"; import L from "leaflet";
import "leaflet.smooth_marker_bouncing"; import "leaflet.smooth_marker_bouncing";
import { toast } from "react-toastify"; import { toast } from "react-toastify";
import * as config from "../config/config.js";
export const insertNewPOI = (closestPoints, newPoint, lineData, map) => { export const insertNewPOI = (closestPoints, newPoint, lineData, map) => {
const newMarker = L.marker(newPoint, { const newMarker = L.marker(newPoint, {