import mysql from "mysql2"; const db = mysql.createConnection({ host: "db-mysql-nyc1-99306-do-user-12431193-0.b.db.ondigitalocean.com", user: "doadmin", password: "AVNS_EPHqPilzmVjZfm8GH4G", database: "defaultdb", port: "25060", connectTimeout: 20000, // 20 seconds }); // const db = mysql.createConnection({ // host: "localhost", // user: "root", // password: "root", // database: "estates", // port: "3306", // connectTimeout: 20000, // 20 seconds // }); // Connect to MySQL database db.connect((err) => { if (err) { console.error("Database connection failed: " + err.stack); return; } console.log("Connected to the MYSQL database."); }); // Controller function // export const searchMySQL = (req, res) => { // const q = "SELECT * FROM client_information"; // // const q = "SELECT * FROM home_information"; // db.query(q, (err, data) => { // if (err) { // console.log(err); // return res.status(500).json({ error: "Database query failed" }); // } // return res.json(data); // }); // }; export const searchMySQL = (req, res) => { const limit = parseInt(req.query.limit) || 10; // Default to 10 items per page const offset = parseInt(req.query.offset) || 0; // Default to the first page const q = `SELECT * FROM home_information LIMIT ${limit} OFFSET ${offset}`; db.query(q, (err, data) => { if (err) { console.log(err); return res.status(500).json({ error: "Database query failed" }); } // Set cache-control headers to prevent caching res.set('Cache-Control', 'no-store'); return res.json(data); }); };