git commit -m "fix: Fehlerbehandlung für fehlende gis_lines-Tabelle und Verwendung des DB-Namens aus .env
- Verhindert Absturz der Anwendung, wenn die gis_lines-Tabelle fehlt - Gibt stattdessen eine Warnung in der Konsole aus - Stellt sicher, dass der Datenbankname dynamisch aus der .env-Datei geladen wird"
This commit is contained in:
15
.env.local
15
.env.local
@@ -1,17 +1,18 @@
|
||||
#.env.local
|
||||
#je nach dem Mysql Server, ob localhost freigegeben ist oder die IP Adresse des Servers, manchmal die beide und manchmal nur eine
|
||||
|
||||
DB_HOST=127.0.0.1
|
||||
DB_USER=root
|
||||
DB_PASSWORD="root#$"
|
||||
DB_NAME=talas_v5
|
||||
DB_PORT=3306
|
||||
######################### Karte die ist in /config/url.js
|
||||
#NEXT_PUBLIC_ONLINE_TILE_LAYER="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
######################### Offline Karte
|
||||
#NEXT_PUBLIC_ONLINE_TILE_LAYER="http://127.0.0.1:3000/mapTiles/{z}/{x}/{y}.png"
|
||||
#NEXT_PUBLIC_ONLINE_TILE_LAYER="http://10.10.0.13:3000/mapTiles/{z}/{x}/{y}.png"
|
||||
####################
|
||||
|
||||
|
||||
NEXT_PUBLIC_SERVER_URL="http://10.10.0.70"
|
||||
NEXT_PUBLIC_ENABLE_GEOCODER=true
|
||||
|
||||
=======
|
||||
|
||||
#########################
|
||||
NEXT_PUBLIC_DB_NAME=talas_v5
|
||||
|
||||
|
||||
|
||||
@@ -299,7 +299,35 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
}, [dispatch, mapGisStationsStaticDistrictUrl]);
|
||||
|
||||
//--------------------------------------------------------
|
||||
useDrawLines(setLinePositions); // Linien auf die Karte zeichnen
|
||||
useEffect(() => {
|
||||
const endpoint = "/api/talas_v5_DB/gisLines/readGisLines";
|
||||
|
||||
fetch(endpoint)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
if (data.message) {
|
||||
console.warn(data.message);
|
||||
return; // Falls die Tabelle nicht existiert, keine weitere Verarbeitung
|
||||
}
|
||||
|
||||
const newLinePositions = data.map((item) => {
|
||||
if (item.points && Array.isArray(item.points)) {
|
||||
return {
|
||||
coordinates: item.points.map((point) => [point.x, point.y]),
|
||||
idModul: item.idModul,
|
||||
idLD: item.idLD,
|
||||
};
|
||||
}
|
||||
throw new Error("Points missing or not an array");
|
||||
});
|
||||
|
||||
setLinePositions(newLinePositions);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching data:", error.message);
|
||||
});
|
||||
}, []);
|
||||
|
||||
//--------------------------------------------
|
||||
// POIs Popup Informationen anzeigen
|
||||
useEffect(() => {
|
||||
@@ -487,7 +515,12 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
|
||||
const colorsByModule = {};
|
||||
reversedData.forEach((stat) => {
|
||||
const matchingLine = data2.find((item) => item.idLD === stat.IdLD && item.idModul === stat.Modul);
|
||||
if (!Array.isArray(data2)) {
|
||||
console.warn("WARNUNG: gis_lines ist kein Array, wird ignoriert.");
|
||||
return;
|
||||
}
|
||||
const matchingLine = data2.find((item) => item.idLD === statis.IdLD && item.idModul === statis.Modul);
|
||||
|
||||
if (matchingLine) {
|
||||
colorsByModule[matchingLine.idModul] = stat.PrioColor;
|
||||
//console.log("Übereinstimmung gefunden für: ", stat);
|
||||
|
||||
@@ -20,6 +20,11 @@ const useLineData = (webserviceGisLinesStatusUrl, setLineStatusData) => {
|
||||
const response2 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/gisLines/readGisLines`);
|
||||
const data2 = await response2.json();
|
||||
|
||||
if (!Array.isArray(data2)) {
|
||||
console.warn("gis_lines Daten sind nicht in der erwarteten Form. Wird ignoriert.");
|
||||
return;
|
||||
}
|
||||
|
||||
const response3 = await fetch(`${SERVER_URL}:3000/api/talas_v5_DB/device/getAllStationsNames`);
|
||||
const namesData = await response3.json();
|
||||
|
||||
|
||||
@@ -2,29 +2,34 @@
|
||||
import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const pool = getPool(); // Singleton-Pool verwenden
|
||||
const pool = getPool();
|
||||
let connection;
|
||||
|
||||
if (req.method !== "GET") {
|
||||
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
|
||||
}
|
||||
|
||||
const query = "SELECT * FROM talas_v5.gis_lines;";
|
||||
const databaseName = process.env.NEXT_PUBLIC_DB_NAME; //talas_v5
|
||||
const query = `SELECT * FROM ${databaseName}.gis_lines;`;
|
||||
|
||||
try {
|
||||
// Verbindung aus dem Pool holen
|
||||
connection = await pool.getConnection();
|
||||
// Abfrage ausführen
|
||||
const [results] = await connection.query(query);
|
||||
|
||||
if (results.length > 0) {
|
||||
res.status(200).json(results);
|
||||
return res.status(200).json(results);
|
||||
} else {
|
||||
res.status(404).json({ error: "Gerät nicht gefunden" });
|
||||
console.warn(`WARNUNG: Die Tabelle ${databaseName}.gis_lines ist leer oder existiert nicht.`);
|
||||
return res.status(200).json({ message: `Die Tabelle ${databaseName}.gis_lines ist leer oder existiert nicht.` });
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.code === "ER_NO_SUCH_TABLE") {
|
||||
console.warn(`WARNUNG: Die Tabelle ${databaseName}.gis_lines existiert nicht.`);
|
||||
return res.status(200).json({ message: `Die Tabelle ${databaseName}.gis_lines existiert nicht.` });
|
||||
}
|
||||
console.error("Fehler beim Abrufen der gis_lines:", error);
|
||||
res.status(500).json({ error: "Fehler beim Abrufen der gis_lines" });
|
||||
return res.status(500).json({ error: "Fehler beim Abrufen der gis_lines" });
|
||||
} finally {
|
||||
if (connection) connection.release(); // Verbindung freigeben
|
||||
if (connection) connection.release();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user