32 lines
926 B
JavaScript
32 lines
926 B
JavaScript
// /pages/api/talas_v5_DB/station/getStationNameByIdLD.js
|
|
import mysql from "mysql2/promise";
|
|
|
|
// Verbindungspool-Konfiguration
|
|
const pool = mysql.createPool({
|
|
host: process.env.DB_HOST,
|
|
user: process.env.DB_USER,
|
|
password: process.env.DB_PASSWORD,
|
|
database: process.env.DB_NAME,
|
|
port: process.env.DB_PORT,
|
|
waitForConnections: true,
|
|
connectionLimit: 10,
|
|
queueLimit: 0,
|
|
});
|
|
|
|
export default async function handler(req, res) {
|
|
if (req.method !== "GET") {
|
|
res.setHeader("Allow", ["GET"]);
|
|
return res.status(405).end(`Method ${req.method} Not Allowed`);
|
|
}
|
|
|
|
try {
|
|
// Verwenden des Verbindungspools, um die Abfrage auszuführen
|
|
const [results] = await pool.query("SELECT * FROM location_device");
|
|
|
|
res.status(200).json(results);
|
|
} catch (err) {
|
|
console.error("Fehler beim Abrufen der Daten:", err);
|
|
res.status(500).json({ error: "Error retrieving data from the database" });
|
|
}
|
|
}
|