refactor: Move API-Endpoint-Functions to /api/talas_v5_DB/ folder for better organization
This commit is contained in:
35
pages/api/talas_v5_DB/locationDevice/locationDevices.js
Normal file
35
pages/api/talas_v5_DB/locationDevice/locationDevices.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// API in /api/talas_v5_DB/locationDevice/locationDevices.js
|
||||
import mysql from "mysql";
|
||||
|
||||
const dbConfig = {
|
||||
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,
|
||||
};
|
||||
|
||||
const connection = mysql.createConnection(dbConfig);
|
||||
connection.connect((err) => {
|
||||
if (err) {
|
||||
console.error("Fehler beim Verbinden:", err.stack);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
export default function handler(req, res) {
|
||||
if (req.method !== "GET") {
|
||||
return res.status(405).json({ error: "Nur GET Methode erlaubt" });
|
||||
}
|
||||
|
||||
const query = "SELECT * FROM location_device WHERE iddevice = 160";
|
||||
connection.query(query, (error, results) => {
|
||||
if (error) {
|
||||
console.error("Fehler beim Abrufen der Geräteinformationen:", error);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "Fehler beim Abrufen der Geräteinformationen" });
|
||||
}
|
||||
res.json(results);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user