2024-05-31 16:36:58 +02:00
43 changed files with 388 additions and 264 deletions

View File

@@ -0,0 +1,8 @@
// config.js
module.exports = {
host: '127.0.0.1',
user: 'fitbot',
password: 'fitbot123',
database: 'fitbot',
port: 3306, // Default MariaDB port
};

View File

@@ -0,0 +1,35 @@
const express = require('express');
const mariadb = require('mariadb');
const config = require('./config');
const app = express();
const port = 443; // Use port 443
const pool = mariadb.createPool({
host: config.host,
user: config.user,
password: config.password,
database: config.database,
connectionLimit: 5,
acquireTimeout: 30000, // Increase timeout to 30 seconds
});
app.get('/', async (req, res) => {
let conn;
try {
conn = await pool.getConnection();
console.log("Connected to MariaDB!");
const rows = await conn.query("SELECT * FROM Exercise ORDER BY RAND() LIMIT 1");
console.log(rows); // [{val: 1}]
res.json(rows); // Send the result as JSON response
} catch (err) {
console.error("Unable to connect to MariaDB:", err);
res.status(500).send("Unable to connect to MariaDB");
} finally {
if (conn) conn.release(); // Release the connection back to the pool
}
});
app.listen(port, '145.92.8.132', () => {
console.log(`Server is listening on http://145.92.8.132:${port}`);
});