link geändert für prio API

This commit is contained in:
ISA
2024-12-27 14:33:42 +01:00
parent 54c458ef5f
commit 6f7c60d341
2 changed files with 31 additions and 2 deletions

29
pages/api/prio.js Normal file
View File

@@ -0,0 +1,29 @@
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();
}
}