server: add Dockerfile and environment variables

The Dockerfile (and docker-compose) simplify the server's deployment.
The environment variables avoid secrets in the code.
This commit is contained in:
dario-cfpt
2024-10-02 10:24:59 +02:00
parent 318a2a0b17
commit 068158ede9
3 changed files with 51 additions and 9 deletions

View File

@ -7,20 +7,14 @@ class database
private static $instance = null;
private $conn;
private $host = 'localhost';
private $user = 'root';
private $pass = '';
private $name = 'fe_charts';
private $port = '';
// The db connection is established in the private constructor.
private function __construct()
{
try {
$this->conn = new PDO(
"mysql:host={$this->host};dbname={$this->name};port={$this->port}",
$this->user,
$this->pass
'mysql:host=' . getenv('MYSQL_HOST') . ';dbname=' . getenv('MYSQL_DATABASE') . ';port=' . getenv('MYSQL_PORT'),
getenv('MYSQL_USER'),
getenv('MYSQL_PASSWORD')
);
} catch (PDOException $e) {
die('Connection failed: ' . $e->getMessage());