30 lines
1003 B
JavaScript
30 lines
1003 B
JavaScript
// API in /api/talas_v5_DB/locationDevice/locationDevices.js
|
|
import getPool from "../../../../utils/mysqlPool"; // Singleton-Pool importieren
|
|
|
|
export default async function handler(req, res) {
|
|
const pool = getPool(); // Singleton-Pool verwenden
|
|
|
|
if (req.method !== "GET") {
|
|
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
|
|
}
|
|
|
|
//const query = "SELECT * FROM location_device WHERE iddevice = 160";
|
|
const query = "SELECT * FROM location_device ORDER BY name";
|
|
|
|
let connection;
|
|
|
|
try {
|
|
connection = await pool.getConnection(); // Hole eine Verbindung aus dem Pool
|
|
|
|
// Ausführen der Abfrage
|
|
const [results] = await connection.query(query);
|
|
|
|
res.status(200).json(results);
|
|
} catch (error) {
|
|
console.error("Fehler beim Abrufen der Geräteinformationen:", error);
|
|
res.status(500).json({ error: "Fehler beim Abrufen der Geräteinformationen" });
|
|
} finally {
|
|
if (connection) connection.release(); // Gib die Verbindung in den Pool zurück
|
|
}
|
|
}
|