link geändert für prio API
This commit is contained in:
29
pages/api/prio.js
Normal file
29
pages/api/prio.js
Normal 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user