feat: Dynamische Basis-URL für NEXT_PUBLIC_BASE_URL implementiert
- Protokoll und Hostname dynamisch über window.location abgeleitet. - Basis-URL auf /talas5/devices/ angepasst. - Unterstützt flexible Umgebungskonfiguration (z. B. Entwicklungs- und Produktionsumgebungen).
This commit is contained in:
36
pages/api/talas5/location_device.js
Normal file
36
pages/api/talas5/location_device.js
Normal file
@@ -0,0 +1,36 @@
|
||||
// /pages/api/talas5/location_device.js
|
||||
import getPool from "../../../utils/mysqlPool"; // Import Singleton-Pool
|
||||
|
||||
// API-Handler
|
||||
export default async function handler(req, res) {
|
||||
const pool = getPool(); // Singleton-Pool verwenden
|
||||
|
||||
let connection;
|
||||
try {
|
||||
// SQL-Query, um die Geräteinformationen aus location_device und devices zu erhalten
|
||||
const sql = `
|
||||
SELECT ld.idLD, ld.iddevice, ld.name, d.idsystem_typ
|
||||
FROM location_device ld
|
||||
JOIN devices d ON ld.iddevice = d.iddevice
|
||||
ORDER BY ld.name
|
||||
`;
|
||||
|
||||
connection = await pool.getConnection();
|
||||
|
||||
// Führe die Abfrage durch
|
||||
const [results] = await connection.query(sql);
|
||||
|
||||
if (!results.length) {
|
||||
return res.status(404).json({ error: "Keine Geräte gefunden" });
|
||||
}
|
||||
|
||||
// Geben Sie die Daten zurück
|
||||
res.status(200).json(results);
|
||||
} catch (error) {
|
||||
// Loggen Sie den Fehler und geben Sie ihn zurück
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user