48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
const https = require('https');
|
|
const fs = require('fs');
|
|
const express = require('express');
|
|
const mariadb = require('mariadb');
|
|
|
|
const app = express();
|
|
|
|
// Serve the "SevAlternance - Site en construction" message
|
|
app.get('/', (req, res) => {
|
|
res.send('SevAlternance - Site en construction');
|
|
});
|
|
|
|
// Check the connection to the MariaDB database using custom SSL options
|
|
async function checkDatabaseConnection() {
|
|
const pool = mariadb.createPool({
|
|
host: 'ip_du_serveur_de_bdd',
|
|
user: 'sevalternance',
|
|
password: 'MonSuperMotdePasse',
|
|
database: 'sevalternance',
|
|
port: '3306',
|
|
connectionLimit: 5,
|
|
});
|
|
|
|
let conn;
|
|
try {
|
|
conn = await pool.getConnection();
|
|
console.log('Connected to the database!');
|
|
} catch (err) {
|
|
console.error('Failed to connect to the database:', err);
|
|
} finally {
|
|
if (conn) conn.release();
|
|
if (pool) pool.end();
|
|
}
|
|
}
|
|
|
|
// Start the HTTPS server
|
|
const options = {
|
|
key: fs.readFileSync('/etc/ssl/private/wildcard.key'),
|
|
cert: fs.readFileSync('/etc/ssl/certs/wildcard.pem'),
|
|
};
|
|
|
|
https.createServer(options, app).listen(443, () => {
|
|
console.log('Server started on port 443');
|
|
});
|
|
|
|
// Check the database connection after starting the server
|
|
checkDatabaseConnection().catch(err => console.error('Error while checking database connection:', err));
|