From 3896381a8fe5a6571788fce417887b98d4d3b87d Mon Sep 17 00:00:00 2001 From: ISA Date: Fri, 22 Aug 2025 11:10:40 +0200 Subject: [PATCH] Debug-Logging zentralisiert: Nutzung von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt und auf getDebugLog() mit config.json umgestellt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Alle Vorkommen von process.env.NEXT_PUBLIC_DEBUG_LOG entfernt - Debug-Konfiguration erfolgt jetzt ausschließlich über public/config.json - getDebugLog()-Utility überall verwendet - .env-Dateien werden für Debug-Logging nicht mehr benötigt - Alle betroffenen Komponenten, Services und API --- .env.development | 3 +-- .env.production | 3 +-- components/area/hooks/useAreaMarkersLayer.js | 3 ++- components/contextmenu/useMapContextMenu.js | 3 ++- components/mainComponent/MapComponent.js | 15 ++++++----- .../MapLayersControlPanel.js | 5 ++-- deployment/.env.production | 4 --- lib/OverlappingMarkerSpiderfier.js | 3 ++- package-lock.json | 4 +-- package.json | 2 +- pages/api/talas_v5_DB/area/updateArea.js | 3 ++- .../gisLines/updateLineCoordinates.js | 3 ++- pages/api/talas_v5_DB/pois/addPoi.js | 3 ++- public/config.json | 4 ++- .../webservice/fetchGisLinesStatusService.js | 5 ++-- .../fetchGisStationsMeasurementsService.js | 5 ++-- .../fetchGisStationsStaticDistrictService.js | 14 +++------- .../fetchGisStationsStatusDistrictService.js | 14 +++------- .../webservice/fetchGisSystemStaticService.js | 14 +++------- services/webservice/fetchUserRightsService.js | 16 ++++-------- utils/configUtils.js | 26 +++++++++++++++++++ utils/mapUtils.js | 6 ++--- utils/mysqlPool.js | 8 +++--- utils/openInNewTab.js | 2 +- utils/polylines/polylineSubscription.js | 2 +- utils/polylines/setupPolylines.js | 2 +- utils/setupDevices.js | 6 +++-- 27 files changed, 94 insertions(+), 84 deletions(-) create mode 100644 utils/configUtils.js diff --git a/.env.development b/.env.development index 95c1ca7c3..bcb5456e0 100644 --- a/.env.development +++ b/.env.development @@ -7,7 +7,6 @@ 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_DEBUG_LOG=true @@ -24,4 +23,4 @@ NEXT_PUBLIC_USE_MOCKS=true # z.B. http://10.10.0.13/xyz/index.aspx -> basePath in config.json auf /xyz setzen # basePath wird jetzt in public/config.json gepflegt # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.1.343 +NEXT_PUBLIC_APP_VERSION=1.1.344 diff --git a/.env.production b/.env.production index 18c34730d..9eaed8de8 100644 --- a/.env.production +++ b/.env.production @@ -7,7 +7,6 @@ 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_DEBUG_LOG=false @@ -25,4 +24,4 @@ NEXT_PUBLIC_USE_MOCKS=false # basePath wird jetzt in public/config.json gepflegt # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.1.343 +NEXT_PUBLIC_APP_VERSION=1.1.344 diff --git a/components/area/hooks/useAreaMarkersLayer.js b/components/area/hooks/useAreaMarkersLayer.js index 7d891e1c9..f0d69b696 100644 --- a/components/area/hooks/useAreaMarkersLayer.js +++ b/components/area/hooks/useAreaMarkersLayer.js @@ -1,3 +1,4 @@ +import { getDebugLog } from "@/utils/configUtils.js"; // /hooks/layers/useAreaMarkersLayer.js import { useEffect, useState, useRef } from "react"; import L from "leaflet"; @@ -100,7 +101,7 @@ const useAreaMarkersLayer = (map, oms, apiUrl, onUpdateSuccess) => { newCoords: { x: lat, y: lng }, }) ).unwrap(); - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("✔️ Koordinaten erfolgreich aktualisiert:", { lat, lng }); } onUpdateSuccess?.(); // optionaler Callback diff --git a/components/contextmenu/useMapContextMenu.js b/components/contextmenu/useMapContextMenu.js index 7ccd85712..6122070ef 100644 --- a/components/contextmenu/useMapContextMenu.js +++ b/components/contextmenu/useMapContextMenu.js @@ -1,3 +1,4 @@ +import { getDebugLog } from "@/utils/configUtils.js"; // components/contextmenu/useMapContextMenu.js import { toast } from "react-toastify"; import { zoomIn, zoomOut, centerHere } from "../../utils/zoomAndCenterUtils"; @@ -71,7 +72,7 @@ const addItemsToMapContextMenu = ( if (!menuItemAdded && map && map.contextmenu) { const editMode = localStorage.getItem("editMode") === "true"; if (editMode) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("editMode localStorage:", localStorage.getItem("editMode")); } diff --git a/components/mainComponent/MapComponent.js b/components/mainComponent/MapComponent.js index 6aa44d927..0946680f9 100644 --- a/components/mainComponent/MapComponent.js +++ b/components/mainComponent/MapComponent.js @@ -88,6 +88,7 @@ import { monitorHeapWithRedux } from "@/utils/common/monitorMemory"; import { io } from "socket.io-client"; import { setGisStationsStaticDistrict } from "@/redux/slices/webservice/gisStationsStaticDistrictSlice.js"; +import { getDebugLog } from "../../utils/configUtils"; //----------------------------------------------------------------------------------------------------- const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { //------------------------------- @@ -509,7 +510,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { //Test in useEffect useEffect(() => { if (map) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🗺️ Map-Einstellungen werden wiederhergestellt..."); } restoreMapSettings(map); @@ -518,7 +519,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { //-------------------------------------------- useEffect(() => { if (map) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("map in MapComponent: ", map); } const handleMapMoveEnd = event => { @@ -551,7 +552,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { const station = points.find(s => s.Area_Name === selectedArea); if (station) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("📌 Gefundene Station:", station); } map.flyTo([station.X, station.Y], 14); @@ -597,7 +598,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { //-------------------------------------------- useEffect(() => { if (map) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("6- Karteninstanz (map) wurde jetzt erfolgreich initialisiert"); } } @@ -610,7 +611,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { map.whenReady(() => { timeoutId = setTimeout(() => { if (map.contextmenu) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Contextmenu ist vorhanden"); } } else { @@ -641,7 +642,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { const handleLocationUpdate = async (idLocation, idMap, newCoords) => { try { await dispatch(updateAreaThunk({ idLocation, idMap, newCoords })).unwrap(); - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Koordinaten erfolgreich aktualisiert:", result); } } catch (error) { @@ -810,7 +811,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => { // console.log(`⏳ Redux Countdown: ${countdown} Sekunden`); if (countdown <= 2) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🚀 Kontextmenü wird wegen Countdown < 2 geschlossen."); } dispatch(closePolylineContextMenu()); diff --git a/components/uiWidgets/mapLayersControlPanel/MapLayersControlPanel.js b/components/uiWidgets/mapLayersControlPanel/MapLayersControlPanel.js index fe3f9770a..b7d6bd88f 100644 --- a/components/uiWidgets/mapLayersControlPanel/MapLayersControlPanel.js +++ b/components/uiWidgets/mapLayersControlPanel/MapLayersControlPanel.js @@ -1,4 +1,5 @@ // /components/uiWidgets/mapLayersControlPanel/MapLayersControlPanel.js +import { getDebugLog } from "../../../utils/configUtils"; import React, { useEffect, useState } from "react"; import { setSelectedArea } from "@/redux/slices/selectedAreaSlice"; import EditModeToggle from "@/components/uiWidgets/mapLayersControlPanel/EditModeToggle"; @@ -218,7 +219,7 @@ function MapLayersControlPanel() { //------------------------------ useEffect(() => { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { window.__debug = window.__debug || {}; window.__debug.gisStations = GisStationsStaticDistrict; } @@ -250,7 +251,7 @@ function MapLayersControlPanel() { } return isUnique; }); - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("📌 stationListing aktualisiert:", filteredAreas); } }, [GisStationsStaticDistrict, GisSystemStatic]); diff --git a/deployment/.env.production b/deployment/.env.production index 5552a5de9..0a3e334c1 100644 --- a/deployment/.env.production +++ b/deployment/.env.production @@ -6,10 +6,6 @@ DB_PASSWORD="root#$" 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_DEBUG_LOG=false - - #auf dem Entwicklungsrechner dev läuft auf Port 3000 und auf dem Server prod auf Port 80, aber der WebService ist immer auf PORT 80 NEXT_PUBLIC_API_PORT_MODE=prod diff --git a/lib/OverlappingMarkerSpiderfier.js b/lib/OverlappingMarkerSpiderfier.js index 6116e243b..a55c0bcf7 100644 --- a/lib/OverlappingMarkerSpiderfier.js +++ b/lib/OverlappingMarkerSpiderfier.js @@ -1,4 +1,5 @@ import L from "leaflet"; +import { getDebugLog } from "../utils/configUtils"; export class OverlappingMarkerSpiderfier { constructor(map, options = {}) { @@ -118,7 +119,7 @@ export class OverlappingMarkerSpiderfier { // 🔥 Künstliches Click-Event auslösen, um die UI zu aktualisieren setTimeout(() => { this.map.fire("click"); - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Click-Event ausgelöst in OverlappingMarkerspiderfier.js in unspiderfy "); } }, 10); // Kurze Verzögerung, um sicherzustellen, dass die UI neu gerendert wird diff --git a/package-lock.json b/package-lock.json index f7f1d98f8..8d7804081 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nodemap", - "version": "1.1.343", + "version": "1.1.344", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "nodemap", - "version": "1.1.343", + "version": "1.1.344", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", diff --git a/package.json b/package.json index b78dfc59d..e0e041152 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodemap", - "version": "1.1.343", + "version": "1.1.344", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", diff --git a/pages/api/talas_v5_DB/area/updateArea.js b/pages/api/talas_v5_DB/area/updateArea.js index b7d23c316..441d1f043 100644 --- a/pages/api/talas_v5_DB/area/updateArea.js +++ b/pages/api/talas_v5_DB/area/updateArea.js @@ -1,8 +1,9 @@ // /pages/api/talas_v5_DB/area/updateArea.js import getPool from "../../../../utils/mysqlPool"; +import { getDebugLog } from "../../../../utils/configUtils"; export default async function handler(req, res) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Request erhalten:", req.method, req.body); // Debugging } diff --git a/pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js b/pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js index ddca05e28..28376b7d8 100644 --- a/pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js +++ b/pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js @@ -1,5 +1,6 @@ // /pages/api/talas_v5_DB/gisLines/updateLineCoordinates.js import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren +import { getDebugLog } from "../../../../utils/configUtils"; export default async function handler(req, res) { const pool = getPool(); // Singleton-Pool verwenden @@ -34,7 +35,7 @@ export default async function handler(req, res) { // Commit der Transaktion await connection.commit(); - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Transaction Complete."); } res.status(200).json({ diff --git a/pages/api/talas_v5_DB/pois/addPoi.js b/pages/api/talas_v5_DB/pois/addPoi.js index 8585a634f..fbcf51929 100644 --- a/pages/api/talas_v5_DB/pois/addPoi.js +++ b/pages/api/talas_v5_DB/pois/addPoi.js @@ -1,12 +1,13 @@ // pages/api/talas_v5_DB/pois/addPoi.js import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren +import { getDebugLog } from "../../../../utils/configUtils"; export default async function handler(req, res) { const pool = getPool(); // Singleton-Pool verwenden if (req.method === "POST") { const { name, poiTypeId, latitude, longitude, idLD } = req.body; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Received data:", req.body); // Überprüfen der empfangenen Daten } diff --git a/public/config.json b/public/config.json index 11d00de99..66664da51 100644 --- a/public/config.json +++ b/public/config.json @@ -28,5 +28,7 @@ "_comment_zoomOutCenter": "Zielkoordinaten für Herauszoomen (lat, lng)", "basePath": "/talas5", - "_comment_basePath": "Basis-URL für API und Routing" + "_comment_basePath": "Basis-URL für API und Routing", + "debugLog": false, + "_comment_debugLog": "Debug-Logging für Client " } diff --git a/services/webservice/fetchGisLinesStatusService.js b/services/webservice/fetchGisLinesStatusService.js index 5c283f960..025a92b9c 100644 --- a/services/webservice/fetchGisLinesStatusService.js +++ b/services/webservice/fetchGisLinesStatusService.js @@ -1,3 +1,4 @@ +import { getDebugLog } from "../../utils/configUtils"; // /services/webservice/fetchGisLinesStatusService.js let __configCache; async function getConfig() { @@ -16,7 +17,7 @@ export const fetchGisLinesStatusService = async () => { if (useMocks) { const mockBasePath = "/api/mocks/webservice/gisLinesStatus"; const mockURL = `${window.location.origin}${mockBasePath}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🧪 Mock-Modus aktiviert: fetchGisLinesStatusService ", mockURL); } @@ -37,7 +38,7 @@ export const fetchGisLinesStatusService = async () => { const idMap = params.get("m"); const url = `${baseUrl}/GisLinesStatus?idMap=${idMap}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("📡 fetchGisLinesStatusService URL:", url); } diff --git a/services/webservice/fetchGisStationsMeasurementsService.js b/services/webservice/fetchGisStationsMeasurementsService.js index 95c548fe6..7ae388a0d 100644 --- a/services/webservice/fetchGisStationsMeasurementsService.js +++ b/services/webservice/fetchGisStationsMeasurementsService.js @@ -1,3 +1,4 @@ +import { getDebugLog } from "../../utils/configUtils"; let __configCache; async function getConfig() { if (__configCache) return __configCache; @@ -15,7 +16,7 @@ export const fetchGisStationsMeasurementsService = async () => { if (useMocks) { const mockBasePath = "/api/mocks/webservice/gisStationsMeasurements"; const mockURL = `${window.location.origin}${mockBasePath}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🧪 Mock-Modus aktiviert: fetchGisStationsMeasurementsService ", mockURL); } @@ -38,7 +39,7 @@ export const fetchGisStationsMeasurementsService = async () => { const idUser = params.get("u"); const url = `${baseUrl}/GisStationsMeasurements?idMap=${idMap}&idUser=${idUser}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("📡 fetchGisStationsMeasurementsService URL:", url); } diff --git a/services/webservice/fetchGisStationsStaticDistrictService.js b/services/webservice/fetchGisStationsStaticDistrictService.js index 75b8043e3..b45db22fc 100644 --- a/services/webservice/fetchGisStationsStaticDistrictService.js +++ b/services/webservice/fetchGisStationsStaticDistrictService.js @@ -5,14 +5,8 @@ * @returns {Promise} Liste mit Points[] * @throws {Error} bei Fehler oder ungültiger Antwortstruktur */ -let __configCache; -async function getConfig() { - if (__configCache) return __configCache; - const res = await fetch("/config.json"); - if (!res.ok) throw new Error("config.json konnte nicht geladen werden"); - __configCache = await res.json(); - return __configCache; -} + +import { getDebugLog, getConfig } from "../../utils/configUtils"; export const fetchGisStationsStaticDistrictService = async () => { const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true"; @@ -22,7 +16,7 @@ export const fetchGisStationsStaticDistrictService = async () => { if (useMocks) { const mockBasePath = "/api/mocks/webservice/gisStationsStaticDistrict"; const mockURL = `${window.location.origin}${mockBasePath}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🧪 Mock-Modus aktiviert: fetchGisStationsStaticDistrictService ", mockURL); } @@ -45,7 +39,7 @@ export const fetchGisStationsStaticDistrictService = async () => { const idUser = params.get("u"); const url = `${baseUrl}/GisStationsStaticDistrict?idMap=${idMap}&idUser=${idUser}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("📡 fetchGisStationsStaticDistrictService URL:", url); } diff --git a/services/webservice/fetchGisStationsStatusDistrictService.js b/services/webservice/fetchGisStationsStatusDistrictService.js index 3bb03c83c..1f3779a86 100644 --- a/services/webservice/fetchGisStationsStatusDistrictService.js +++ b/services/webservice/fetchGisStationsStatusDistrictService.js @@ -5,14 +5,8 @@ * @returns {Promise} Liste mit Statis[] * @throws {Error} bei Fehler oder ungültiger Antwortstruktur */ -let __configCache; -async function getConfig() { - if (__configCache) return __configCache; - const res = await fetch("/config.json"); - if (!res.ok) throw new Error("config.json konnte nicht geladen werden"); - __configCache = await res.json(); - return __configCache; -} + +import { getDebugLog, getConfig } from "../../utils/configUtils"; export const fetchGisStationsStatusDistrictService = async () => { const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true"; @@ -22,7 +16,7 @@ export const fetchGisStationsStatusDistrictService = async () => { if (useMocks) { const mockBasePath = "/api/mocks/webservice/gisStationsStatusDistrict"; const mockURL = `${window.location.origin}${mockBasePath}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🧪 Mock-Modus aktiviert: fetchGisStationsStatusDistrictService ", mockURL); } @@ -45,7 +39,7 @@ export const fetchGisStationsStatusDistrictService = async () => { const idUser = params.get("u"); const url = `${baseUrl}/GisStationsStatusDistrict?idMap=${idMap}&idUser=${idUser}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("📡 fetchGisStationsStatusDistrictService URL:", url); } diff --git a/services/webservice/fetchGisSystemStaticService.js b/services/webservice/fetchGisSystemStaticService.js index 7d162f3d8..4209e1914 100644 --- a/services/webservice/fetchGisSystemStaticService.js +++ b/services/webservice/fetchGisSystemStaticService.js @@ -4,14 +4,8 @@ * @returns {Promise} Liste mit Systems[] * @throws {Error} bei Fehler oder ungültiger Antwortstruktur */ -let __configCache; -async function getConfig() { - if (__configCache) return __configCache; - const res = await fetch("/config.json"); - if (!res.ok) throw new Error("config.json konnte nicht geladen werden"); - __configCache = await res.json(); - return __configCache; -} + +import { getDebugLog, getConfig } from "../../utils/configUtils"; export const fetchGisSystemStaticService = async () => { const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true"; @@ -21,7 +15,7 @@ export const fetchGisSystemStaticService = async () => { if (useMocks) { const mockBasePath = "/api/mocks/webservice/gisSystemStatic"; const mockURL = `${window.location.origin}${mockBasePath}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🧪 Mock-Modus aktiviert: fetchGisSystemStaticService ", mockURL); } @@ -44,7 +38,7 @@ export const fetchGisSystemStaticService = async () => { const idUser = params.get("u"); const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("📡 fetchGisSystemStaticService von service URL:", url); } diff --git a/services/webservice/fetchUserRightsService.js b/services/webservice/fetchUserRightsService.js index 89fbc74e9..5e9c6a531 100644 --- a/services/webservice/fetchUserRightsService.js +++ b/services/webservice/fetchUserRightsService.js @@ -4,14 +4,8 @@ * @returns {Promise} Rechte-Array * @throws {Error} bei Lade- oder Strukturfehler */ -let __configCache; -async function getConfig() { - if (__configCache) return __configCache; - const res = await fetch("/config.json"); - if (!res.ok) throw new Error("config.json konnte nicht geladen werden"); - __configCache = await res.json(); - return __configCache; -} + +import { getDebugLog, getConfig } from "../../utils/configUtils"; export const fetchUserRightsService = async () => { const useMocks = process.env.NEXT_PUBLIC_USE_MOCKS === "true"; @@ -21,7 +15,7 @@ export const fetchUserRightsService = async () => { if (useMocks) { const mockBasePath = "/api/mocks/webservice/gisSystemStatic"; const mockURL = `${window.location.origin}${mockBasePath}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🧪 Mock-Modus aktiviert: fetchUserRightsService ", mockURL); } @@ -40,7 +34,7 @@ export const fetchUserRightsService = async () => { const idUser = params.get("u"); const url = `${baseUrl}/GisSystemStatic?idMap=${idMap}&idUser=${idUser}`; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🔍 Rechte-Fetch URL:", url); } @@ -56,7 +50,7 @@ export const fetchUserRightsService = async () => { } const json = await response.json(); - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("👤 Rechte-Response JSON:", json); } diff --git a/utils/configUtils.js b/utils/configUtils.js new file mode 100644 index 000000000..7de1be5a0 --- /dev/null +++ b/utils/configUtils.js @@ -0,0 +1,26 @@ +// utils/configUtils.js +let __configCache; +export async function getConfig() { + if (__configCache) return __configCache; + const res = await fetch("/config.json"); + if (!res.ok) throw new Error("config.json konnte nicht geladen werden"); + __configCache = await res.json(); + return __configCache; +} + +// Sync helper for debugLog (for use in event handlers etc.) +let debugLogValue; +export function getDebugLog() { + if (debugLogValue !== undefined) return debugLogValue; + // Try to read from window.__appConfig if available (set at app start) + if ( + typeof window !== "undefined" && + window.__appConfig && + typeof window.__appConfig.debugLog !== "undefined" + ) { + debugLogValue = !!window.__appConfig.debugLog; + return debugLogValue; + } + // Fallback: default false + return false; +} diff --git a/utils/mapUtils.js b/utils/mapUtils.js index 7413ecb99..6a981477f 100644 --- a/utils/mapUtils.js +++ b/utils/mapUtils.js @@ -62,7 +62,7 @@ export const checkOverlappingMarkers = (map, markers, plusIcon, oms) => { export const handlePlusIconClick = (map, markers, oms, clickedLatLng) => { // Debugging-Ausgabe - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Plus-Icon Position:", clickedLatLng); } @@ -72,7 +72,7 @@ export const handlePlusIconClick = (map, markers, oms, clickedLatLng) => { ); // Debugging-Ausgabe - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Gefundene Marker in der Nähe:", nearbyMarkers); } @@ -80,7 +80,7 @@ export const handlePlusIconClick = (map, markers, oms, clickedLatLng) => { // Spiderfy die gefundenen Marker oms.spiderfy(nearbyMarkers); } else { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Keine überlappenden Marker gefunden."); } } diff --git a/utils/mysqlPool.js b/utils/mysqlPool.js index d88971953..f53742ffe 100644 --- a/utils/mysqlPool.js +++ b/utils/mysqlPool.js @@ -26,12 +26,12 @@ function getPool() { cachedPool.on("acquire", () => { connectionCount++; if (process.env.NODE_ENV === "development") { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("\x1b[36m%s\x1b[0m", `➕ Connection acquired (${connectionCount} total)`); } if (connectionCount > maxUsed) { maxUsed = connectionCount; - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log(`📈 Neue Höchstzahl aktiver gleichzeitiger Verbindungen: ${maxUsed}`); } } @@ -40,7 +40,7 @@ function getPool() { cachedPool.on("release", () => { connectionCount--; if (process.env.NODE_ENV === "development") { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("\x1b[32m%s\x1b[0m", `➖ Connection released (${connectionCount} total)`); } } @@ -48,7 +48,7 @@ function getPool() { cachedPool.on("enqueue", () => { if (process.env.NODE_ENV === "development") { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.warn("\x1b[33m%s\x1b[0m", "⏳ Pool voll – Anfrage in Warteschlange"); } } diff --git a/utils/openInNewTab.js b/utils/openInNewTab.js index 202acffaa..c47b7458d 100644 --- a/utils/openInNewTab.js +++ b/utils/openInNewTab.js @@ -30,7 +30,7 @@ export async function openInNewTab(e, target) { } if (link) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🟢 Öffne Link:", link); } window.open(link, "_blank"); diff --git a/utils/polylines/polylineSubscription.js b/utils/polylines/polylineSubscription.js index 92c8861b1..77e715cff 100644 --- a/utils/polylines/polylineSubscription.js +++ b/utils/polylines/polylineSubscription.js @@ -6,7 +6,7 @@ export function subscribeToPolylineContextMenu() { store.subscribe(() => { const state = store.getState(); // Redux-Toolkit empfohlene Methode if (state.polylineContextMenu.forceClose) { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("🚀 Redux-Event erkannt - Kontextmenü wird geschlossen."); } store.dispatch(closePolylineContextMenu()); diff --git a/utils/polylines/setupPolylines.js b/utils/polylines/setupPolylines.js index ac1fafbeb..1ddfa982f 100644 --- a/utils/polylines/setupPolylines.js +++ b/utils/polylines/setupPolylines.js @@ -113,7 +113,7 @@ export const setupPolylines = async ( .dispatch(updatePolylineCoordinatesThunk(requestData)) .unwrap() .then(data => { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("Koordinaten erfolgreich aktualisiert:", data); } }) diff --git a/utils/setupDevices.js b/utils/setupDevices.js index d6a5a82a7..37281093f 100644 --- a/utils/setupDevices.js +++ b/utils/setupDevices.js @@ -1,17 +1,19 @@ // utils/setupDevices.js + import { setSelectedDevice, clearSelectedDevice } from "../redux/slices/selectedDeviceSlice"; +import { getDebugLog } from "./configUtils"; export const setupDevices = async (map, deviceMarkers, dispatch) => { for (const marker of deviceMarkers) { marker.on("mouseover", function () { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("✅ Gerät ausgewählt:", marker); } dispatch(setSelectedDevice(marker.options)); // Gerät in Redux speichern }); marker.on("mouseout", function () { - if (process.env.NEXT_PUBLIC_DEBUG_LOG === "true") { + if (getDebugLog()) { console.log("❌ Gerät abgewählt"); } dispatch(clearSelectedDevice()); // Gerät aus Redux entfernen