fix(config): dynamically resolve baseURL from request HTTP_HOST to prevent CORS errors on live servers

This commit is contained in:
DevSoftTech Server 2026-08-28 02:46:01 +05:30
parent 69f0e1fa45
commit 863c17f9bc

View File

@ -27,11 +27,13 @@ class App extends BaseConfig
$this->allowedHostnames = $envAllowedHostnames;
}
if ($this->baseURL === '') {
$isHttps = ! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off';
$envBaseUrl = (string) env('app.baseURL', '');
if ($envBaseUrl !== '') {
$this->baseURL = rtrim($envBaseUrl, '/') . '/';
} elseif (! empty($_SERVER['HTTP_HOST'])) {
$isHttps = (! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || ($_SERVER['HTTP_X_FORWARDED_PROTO'] ?? '') === 'https';
$scheme = $isHttps ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? 'localhost';
$host = $_SERVER['HTTP_HOST'];
$this->baseURL = $scheme . '://' . $host . '/';
}
}