30 lines
693 B
Plaintext
30 lines
693 B
Plaintext
const express = require('express');
|
|
const mariadb = require('mariadb');
|
|
const app = express();
|
|
const port = 3000;
|
|
|
|
const pool = mariadb.createPool({
|
|
host: 'localhost',
|
|
user: 'fitbot',
|
|
password: 'fitbot123',
|
|
database: 'fitbot',
|
|
connectionLimit: 5
|
|
});
|
|
|
|
app.get('/data', async (req, res) => {
|
|
let conn;
|
|
try {
|
|
conn = await pool.getConnection();
|
|
const rows = await conn.query('SELECT * FROM Exercise');
|
|
res.json(rows);
|
|
} catch (err) {
|
|
res.status(500).json({ error: err.message });
|
|
} finally {
|
|
if (conn) conn.release();
|
|
}
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Server running on http://localhost:${port}`);
|
|
});
|