30 lines
837 B
JavaScript
30 lines
837 B
JavaScript
import getPool from "../../utils/mysqlPool";
|
|
|
|
export default async function handler(req, res) {
|
|
// Nur GET-Anfragen zulassen
|
|
if (req.method !== "GET") {
|
|
return res.status(405).json({ error: "Methode nicht erlaubt" });
|
|
}
|
|
|
|
const pool = getPool(); // Singleton-Pool verwenden
|
|
let connection;
|
|
|
|
try {
|
|
// Verbindung abrufen
|
|
connection = await pool.getConnection();
|
|
|
|
// SQL-Query
|
|
const query = "SELECT idprio, level, name, color FROM prio";
|
|
const [results] = await connection.query(query);
|
|
|
|
// Erfolgreiche Antwort
|
|
res.status(200).json(results);
|
|
} catch (error) {
|
|
console.error("Fehler beim Abrufen der API:", error.message); // Mehr Details
|
|
res.status(500).json({ error: "Interner Serverfehler" });
|
|
} finally {
|
|
// Verbindung freigeben
|
|
if (connection) connection.release();
|
|
}
|
|
}
|