diff --git a/.env.development b/.env.development index 4589ba657..6f6b5b750 100644 --- a/.env.development +++ b/.env.development @@ -23,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.352 +NEXT_PUBLIC_APP_VERSION=1.1.353 diff --git a/.env.production b/.env.production index d850fe7b8..807e42b3f 100644 --- a/.env.production +++ b/.env.production @@ -24,4 +24,4 @@ NEXT_PUBLIC_USE_MOCKS=false # basePath wird jetzt in public/config.json gepflegt # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.1.352 +NEXT_PUBLIC_APP_VERSION=1.1.353 diff --git a/package-lock.json b/package-lock.json index 004bc6921..59d72757f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "nodemap", - "version": "1.1.352", + "version": "1.1.353", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "nodemap", - "version": "1.1.352", + "version": "1.1.353", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", diff --git a/package.json b/package.json index c2dbac1dc..ec7bc19b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nodemap", - "version": "1.1.352", + "version": "1.1.353", "dependencies": { "@emotion/react": "^11.13.3", "@emotion/styled": "^11.13.0", diff --git a/pages/api/testDbConnection.js b/pages/api/testDbConnection.js new file mode 100644 index 000000000..434f81b03 --- /dev/null +++ b/pages/api/testDbConnection.js @@ -0,0 +1,18 @@ +// pages/api/testDbConnection.js +import getPool from "../../utils/mysqlPool"; + +export default async function handler(req, res) { + const pool = getPool(); + let connection; + try { + connection = await pool.getConnection(); + const [rows] = await connection.query("SELECT 1 AS test"); + console.log("DB-Verbindung erfolgreich! Ergebnis:", rows); + res.status(200).json({ success: true, result: rows }); + } catch (error) { + console.error("DB-Verbindungsfehler:", error); + res.status(500).json({ success: false, error: error.message }); + } finally { + if (connection) connection.release(); + } +} diff --git a/utils/mysqlPool.js b/utils/mysqlPool.js index f53742ffe..01d55746f 100644 --- a/utils/mysqlPool.js +++ b/utils/mysqlPool.js @@ -1,9 +1,7 @@ import mysql from "mysql2/promise"; -// Variablen für den Singleton-Pool let cachedPool; -let connectionCount = 0; // Zähler für die aktiven Verbindungen +let connectionCount = 0; -// Funktion zum Abrufen des Pools function getPool() { if (!cachedPool) { cachedPool = mysql.createPool({ @@ -12,12 +10,11 @@ function getPool() { password: process.env.DB_PASSWORD, database: process.env.DB_NAME, port: process.env.DB_PORT, - connectionLimit: 20, // Setze ein Limit für gleichzeitige Verbindungen + connectionLimit: 20, waitForConnections: true, - queueLimit: 10, // Warteschlangenlimit für Verbindungen - connectTimeout: 5000, // Timeout für Verbindungsversuche (5 Sekunden) - //acquireTimeout: 10000, // Timeout für Verbindungsanforderungen aus dem Pool (10 Sekunden) - idleTimeout: 60000, // 1 Minute + queueLimit: 10, + connectTimeout: 5000, + idleTimeout: 60000, }); // Ereignisse für das Protokollieren der Verbindungsstatistiken @@ -25,46 +22,27 @@ function getPool() { cachedPool.on("acquire", () => { connectionCount++; - if (process.env.NODE_ENV === "development") { - if (getDebugLog()) { - console.log("\x1b[36m%s\x1b[0m", `➕ Connection acquired (${connectionCount} total)`); - } - if (connectionCount > maxUsed) { - maxUsed = connectionCount; - if (getDebugLog()) { - console.log(`📈 Neue Höchstzahl aktiver gleichzeitiger Verbindungen: ${maxUsed}`); - } - } + // Debug-Logging entfernt + if (connectionCount > maxUsed) { + maxUsed = connectionCount; } }); cachedPool.on("release", () => { connectionCount--; - if (process.env.NODE_ENV === "development") { - if (getDebugLog()) { - console.log("\x1b[32m%s\x1b[0m", `➖ Connection released (${connectionCount} total)`); - } - } }); - cachedPool.on("enqueue", () => { - if (process.env.NODE_ENV === "development") { - if (getDebugLog()) { - console.warn("\x1b[33m%s\x1b[0m", "⏳ Pool voll – Anfrage in Warteschlange"); - } - } + // Debug-Logging entfernt }); } - return cachedPool; } -// Optionale Funktion zum Schließen aller Verbindungen im Pool (manuell aufzurufen) export function closePool() { if (cachedPool) { cachedPool.end(() => { console.log("All pool connections closed."); }); - cachedPool = null; // Setze den Pool auf null, um sicherzustellen, dass er neu erstellt wird, falls benötigt. + cachedPool = null; } }