Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Cake\Datasource\ConnectionManager;
use Cake\Error\ErrorTrap;
use Cake\Error\ExceptionTrap;
use Cake\Http\Exception\ForbiddenException;
use Cake\Http\ServerRequest;
use Cake\Log\Log;
use Cake\Mailer\Mailer;
Expand Down Expand Up @@ -165,21 +166,19 @@
*/
$fullBaseUrl = Configure::read('App.fullBaseUrl');
if (!$fullBaseUrl) {
$httpHost = env('HTTP_HOST');

/*
* Development mode fallback: Use HTTP_HOST for convenience.
* WARNING: This is ONLY safe in development. In production, the
* HostHeaderMiddleware will reject requests when fullBaseUrl is not configured.
*/
if ($httpHost) {
$s = null;
if (env('HTTPS') || env('HTTP_X_FORWARDED_PROTO') === 'https') {
$s = 's';
if (Configure::read('debug')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no fan of that $s variable.

Wouldn't something like this be more readable ? 🤖

$fullBaseUrl = Configure::read('App.fullBaseUrl');

if (!$fullBaseUrl && Configure::read('debug')) {
    $httpHost = env('HTTP_HOST');
    if ($httpHost) {
        $scheme = (
            env('HTTPS') || env('HTTP_X_FORWARDED_PROTO') === 'https'
        ) ? 'https' : 'http';

        $fullBaseUrl = $scheme . '://' . $httpHost;
    }
    unset($httpHost, $scheme);
}

if ($fullBaseUrl) {
    Router::fullBaseUrl($fullBaseUrl);
}
unset($fullBaseUrl);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

$httpHost = env('HTTP_HOST');
if ($httpHost) {
$scheme = env('HTTPS') || env('HTTP_X_FORWARDED_PROTO') === 'https' ? 'https' : 'http';
$fullBaseUrl = $scheme . '://' . $httpHost;
}
$fullBaseUrl = 'http' . $s . '://' . $httpHost;
unset($httpHost, $scheme);
}
unset($httpHost, $s);
}
if ($fullBaseUrl) {
Router::fullBaseUrl($fullBaseUrl);
Expand Down