feat: add .env support for coolify deployment

This commit is contained in:
fananazril
2026-06-11 19:27:21 +07:00
parent 0ae2768849
commit 3475cf16b4
4 changed files with 35 additions and 5 deletions
+19 -1
View File
@@ -3,8 +3,26 @@
// Konfigurasi Global Aplikasi
// ================================================================
// Simple .env parser (for local use)
$envFile = __DIR__ . '/../.env';
if (file_exists($envFile)) {
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) continue;
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value, " \t\n\r\0\x0B\"'"); // Strip whitespace and quotes
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
putenv(sprintf('%s=%s', $name, $value));
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
}
// Base URL aplikasi
define('BASE_URL', 'http://localhost/webjir/poverty_map');
$defaultBaseUrl = 'http://localhost/webjir/poverty_map';
define('BASE_URL', getenv('BASE_URL') ?: $defaultBaseUrl);
define('BASE_PATH', dirname(__DIR__));
// Koordinat default peta (Pontianak)
+4 -4
View File
@@ -2,10 +2,10 @@
// ================================================================
// Konfigurasi Database
// ================================================================
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'poverty_map');
define('DB_HOST', getenv('DB_HOST') ?: 'localhost');
define('DB_USER', getenv('DB_USER') ?: 'root');
define('DB_PASS', getenv('DB_PASS') !== false ? getenv('DB_PASS') : '');
define('DB_NAME', getenv('DB_NAME') ?: 'poverty_map');
define('DB_CHARSET','utf8mb4');
function getDB(): PDO {