Skip to content

Commit

Permalink
Move BASE_URL set to config bootstrap to fix mixed url issue #2787
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Nov 18, 2024
1 parent beccd6c commit 60ed1c1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
34 changes: 34 additions & 0 deletions app/Core/Bootstrap/LoadConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public function bootstrap(Application $app)
//Additional adjustments
$finalConfig->set('APP_DEBUG', $finalConfig->get('debug') ? true : false);

$this->setBaseConstants($finalConfig->get('appUrl'), $app);

if ($finalConfig->get('app.url') == '') {
$url = defined('BASE_URL') ? BASE_URL : 'http://localhost';
$finalConfig->set('app.url', $url);
Expand All @@ -93,6 +95,38 @@ public function bootstrap(Application $app)

}

/**
* Sets the URL constants for the application.
*
* If the BASE_URL constant is not defined, it will be set based on the value of $appUrl parameter.
* If $appUrl is empty or not provided, it will be set using the getSchemeAndHttpHost method of the class.
*
* The APP_URL environment variable will be set to the value of $appUrl.
*
* If the CURRENT_URL constant is not defined, it will be set by appending the getRequestUri method result to the BASE_URL.
*
* @param string $appUrl The URL to be used as BASE_URL and APP_URL. Defaults to an empty string.
* @return void
*/
public function setBaseConstants($appUrl, $app) {

if (! defined('BASE_URL')) {
if (isset($appUrl) && ! empty($appUrl)) {
define('BASE_URL', $appUrl);

} else {
define('BASE_URL', request()->getSchemeAndHttpHost());
}
}

putenv('APP_URL='.$appUrl);

if (! defined('CURRENT_URL')) {
define('CURRENT_URL', BASE_URL.request()->getRequestUri());
}

}

/**
* Load the configuration files.
*
Expand Down
34 changes: 1 addition & 33 deletions app/Core/Http/IncomingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,44 +74,12 @@ public static function capture()
default => parent::createFromGlobals(),
};

$request->setUrlConstants();
//$request->setUrlConstants();

return $request;

}

/**
* Sets the URL constants for the application.
*
* If the BASE_URL constant is not defined, it will be set based on the value of $appUrl parameter.
* If $appUrl is empty or not provided, it will be set using the getSchemeAndHttpHost method of the class.
*
* The APP_URL environment variable will be set to the value of $appUrl.
*
* If the CURRENT_URL constant is not defined, it will be set by appending the getRequestUri method result to the BASE_URL.
*
* @param string $appUrl The URL to be used as BASE_URL and APP_URL. Defaults to an empty string.
* @return void
*/
public function setUrlConstants($appUrl = '')
{

if (! defined('BASE_URL')) {
if (isset($appUrl) && ! empty($appUrl)) {
define('BASE_URL', $appUrl);

} else {
define('BASE_URL', parent::getSchemeAndHttpHost());
}
}

putenv('APP_URL='.$appUrl);

if (! defined('CURRENT_URL')) {
define('CURRENT_URL', BASE_URL.$this->getRequestUri());
}
}

/**
* Gets the full URL including request uri and protocol
*/
Expand Down

0 comments on commit 60ed1c1

Please sign in to comment.