diff --git a/backend/app/Controllers/TestController.php b/backend/app/Controllers/TestController.php index ff761c1..8baa271 100644 --- a/backend/app/Controllers/TestController.php +++ b/backend/app/Controllers/TestController.php @@ -16,23 +16,30 @@ class TestController */ public function testNabeh(Request $request, Response $response): void { + $loadedEnvPath = defined('LOADED_ENV_PATH') ? LOADED_ENV_PATH : 'Undefined'; + $results = [ - 'timestamp' => date('Y-m-d H:i:s'), + 'timestamp' => date('Y-m-d H:i:s'), + 'loaded_env_file' => $loadedEnvPath, 'env_check' => [ - 'NABEH_AUTH_URL' => getenv('NABEH_AUTH_URL') ? '✅ Configured (' . getenv('NABEH_AUTH_URL') . ')' : '❌ Missing', - 'NABEH_SEND_URL' => getenv('NABEH_SEND_URL') ? '✅ Configured (' . getenv('NABEH_SEND_URL') . ')' : '❌ Missing', - 'NABEH_EMAIL' => getenv('NABEH_EMAIL') ? '✅ Configured (' . substr((string)getenv('NABEH_EMAIL'), 0, 3) . '***)' : '❌ Missing', + 'REDIS_HOST' => getenv('REDIS_HOST') ?: '❌ Not Set', + 'REDIS_PORT' => getenv('REDIS_PORT') ?: '❌ Not Set', + 'NABEH_AUTH_URL' => getenv('NABEH_AUTH_URL') ? '✅ ' . getenv('NABEH_AUTH_URL') : '❌ Missing', + 'NABEH_SEND_URL' => getenv('NABEH_SEND_URL') ? '✅ ' . getenv('NABEH_SEND_URL') : '❌ Missing', + 'NABEH_EMAIL' => getenv('NABEH_EMAIL') ? '✅ ' . substr((string)getenv('NABEH_EMAIL'), 0, 4) . '***' : '❌ Missing', 'NABEH_PASSWORD' => getenv('NABEH_PASSWORD') ? '✅ Configured (••••••)' : '❌ Missing', ], 'redis_check' => [ - 'connected' => false, + 'target_host' => getenv('REDIS_HOST'), + 'target_port' => getenv('REDIS_PORT'), + 'connected' => false, 'cached_token_found' => false, - 'token_sample' => null + 'token_sample' => null ], 'nabeh_auth' => [ - 'success' => false, + 'success' => false, 'token_acquired' => false, - 'error' => null + 'error' => null ], 'live_otp_test' => null ]; @@ -116,8 +123,11 @@ class TestController */ public function testSystem(Request $request, Response $response): void { + $loadedEnvPath = defined('LOADED_ENV_PATH') ? LOADED_ENV_PATH : 'Undefined'; + $data = [ 'status' => 'healthy', + 'loaded_env_file' => $loadedEnvPath, 'app' => [ 'name' => getenv('APP_NAME') ?: 'Saqel', 'url' => getenv('APP_URL') ?: 'Not Set', diff --git a/backend/app/bootstrap.php b/backend/app/bootstrap.php index 78e43b1..57d633f 100644 --- a/backend/app/bootstrap.php +++ b/backend/app/bootstrap.php @@ -4,7 +4,7 @@ * Handles PSR-4 Autoloading, security settings, and strict error handling. */ -// Define absolute path to application root +// Define absolute path to application root (saqel/backend) define('APP_ROOT', dirname(__DIR__)); // 1. PSR-4 Autoloader @@ -28,28 +28,36 @@ spl_autoload_register(function ($class) { // 2. Load Environment Variables (Checks local and production server locations) try { $candidatePaths = [ - APP_ROOT . '/.env', - APP_ROOT . '/../.env', - APP_ROOT . '/docker/.env', + APP_ROOT . '/.env', // saqel/backend/.env + APP_ROOT . '/../.env', // saqel/.env + APP_ROOT . '/../../.env', // htdocs/saqel.intaleqapp.com/.env + '/home/intaleqapp-saqel/htdocs/saqel.intaleqapp.com/saqel/.env', + '/home/intaleqapp-saqel/htdocs/saqel.intaleqapp.com/.env', '/home/intaleqapp-saqel/.env', '/home/saqel/.env', + APP_ROOT . '/docker/.env', ]; $env_file = null; foreach ($candidatePaths as $path) { - if (file_exists($path)) { - $env_file = $path; + if (file_exists($path) && is_readable($path) && filesize($path) > 10) { + $env_file = realpath($path) ?: $path; break; } } if ($env_file) { + define('LOADED_ENV_PATH', $env_file); \App\Core\Env::load($env_file); } else { - error_log("⚠️ [Env Warning] No .env file found in candidate paths. Expecting variables from server environment."); + define('LOADED_ENV_PATH', 'NONE_FOUND'); + error_log("⚠️ [Env Warning] No valid .env file found in candidate paths. Expecting variables from server environment."); } } catch (\Exception $e) { error_log('Env Load Error: ' . $e->getMessage()); + if (!defined('LOADED_ENV_PATH')) { + define('LOADED_ENV_PATH', 'ERROR: ' . $e->getMessage()); + } } // 3. Configure Error Reporting based on environment