Skip to content

Commit 60ed1c1

Browse files
committed
Move BASE_URL set to config bootstrap to fix mixed url issue #2787
1 parent beccd6c commit 60ed1c1

File tree

2 files changed

+35
-33
lines changed

2 files changed

+35
-33
lines changed

app/Core/Bootstrap/LoadConfig.php

+34
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public function bootstrap(Application $app)
6969
//Additional adjustments
7070
$finalConfig->set('APP_DEBUG', $finalConfig->get('debug') ? true : false);
7171

72+
$this->setBaseConstants($finalConfig->get('appUrl'), $app);
73+
7274
if ($finalConfig->get('app.url') == '') {
7375
$url = defined('BASE_URL') ? BASE_URL : 'http://localhost';
7476
$finalConfig->set('app.url', $url);
@@ -93,6 +95,38 @@ public function bootstrap(Application $app)
9395

9496
}
9597

98+
/**
99+
* Sets the URL constants for the application.
100+
*
101+
* If the BASE_URL constant is not defined, it will be set based on the value of $appUrl parameter.
102+
* If $appUrl is empty or not provided, it will be set using the getSchemeAndHttpHost method of the class.
103+
*
104+
* The APP_URL environment variable will be set to the value of $appUrl.
105+
*
106+
* If the CURRENT_URL constant is not defined, it will be set by appending the getRequestUri method result to the BASE_URL.
107+
*
108+
* @param string $appUrl The URL to be used as BASE_URL and APP_URL. Defaults to an empty string.
109+
* @return void
110+
*/
111+
public function setBaseConstants($appUrl, $app) {
112+
113+
if (! defined('BASE_URL')) {
114+
if (isset($appUrl) && ! empty($appUrl)) {
115+
define('BASE_URL', $appUrl);
116+
117+
} else {
118+
define('BASE_URL', request()->getSchemeAndHttpHost());
119+
}
120+
}
121+
122+
putenv('APP_URL='.$appUrl);
123+
124+
if (! defined('CURRENT_URL')) {
125+
define('CURRENT_URL', BASE_URL.request()->getRequestUri());
126+
}
127+
128+
}
129+
96130
/**
97131
* Load the configuration files.
98132
*

app/Core/Http/IncomingRequest.php

+1-33
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,12 @@ public static function capture()
7474
default => parent::createFromGlobals(),
7575
};
7676

77-
$request->setUrlConstants();
77+
//$request->setUrlConstants();
7878

7979
return $request;
8080

8181
}
8282

83-
/**
84-
* Sets the URL constants for the application.
85-
*
86-
* If the BASE_URL constant is not defined, it will be set based on the value of $appUrl parameter.
87-
* If $appUrl is empty or not provided, it will be set using the getSchemeAndHttpHost method of the class.
88-
*
89-
* The APP_URL environment variable will be set to the value of $appUrl.
90-
*
91-
* If the CURRENT_URL constant is not defined, it will be set by appending the getRequestUri method result to the BASE_URL.
92-
*
93-
* @param string $appUrl The URL to be used as BASE_URL and APP_URL. Defaults to an empty string.
94-
* @return void
95-
*/
96-
public function setUrlConstants($appUrl = '')
97-
{
98-
99-
if (! defined('BASE_URL')) {
100-
if (isset($appUrl) && ! empty($appUrl)) {
101-
define('BASE_URL', $appUrl);
102-
103-
} else {
104-
define('BASE_URL', parent::getSchemeAndHttpHost());
105-
}
106-
}
107-
108-
putenv('APP_URL='.$appUrl);
109-
110-
if (! defined('CURRENT_URL')) {
111-
define('CURRENT_URL', BASE_URL.$this->getRequestUri());
112-
}
113-
}
114-
11583
/**
11684
* Gets the full URL including request uri and protocol
11785
*/

0 commit comments

Comments
 (0)