Merge branch 'main' of https://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-4/muupooviixee66
This commit is contained in:
8
code/server/test/config.js
Normal file
8
code/server/test/config.js
Normal 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
|
||||
};
|
35
code/server/test/testConnection.js
Normal file
35
code/server/test/testConnection.js
Normal 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}`);
|
||||
});
|
Reference in New Issue
Block a user