Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Passthrough excluded uri's in maintenance mode #38041

Merged
merged 4 commits into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions src/Illuminate/Foundation/Console/DownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace Illuminate\Foundation\Console;

use App\Http\Middleware\PreventRequestsDuringMaintenance;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Foundation\Exceptions\RegisterErrorViewPaths;
use Throwable;

class DownCommand extends Command
{
Expand Down Expand Up @@ -69,6 +71,7 @@ public function handle()
protected function getDownFilePayload()
{
return [
'except' => $this->excludedPaths(),
'redirect' => $this->redirectPath(),
'retry' => $this->getRetryTime(),
'refresh' => $this->option('refresh'),
Expand All @@ -78,6 +81,20 @@ protected function getDownFilePayload()
];
}

/**
* Get the paths that should be excluded from maintenance mode.
*
* @return array
*/
protected function excludedPaths()
{
try {
return $this->laravel->make(PreventRequestsDuringMaintenance::class)->getExcludedPaths();
} catch (Throwable $e) {
return [];
}
}

/**
* Get the path that users should be redirected to.
*
Expand Down
23 changes: 23 additions & 0 deletions src/Illuminate/Foundation/Console/stubs/maintenance-mode.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@ if (! isset($data['template'])) {
return;
}

// Allow framework to handle request if request URI is in the exclude list...
if (isset($data['except'])) {
$uri = parse_url($_SERVER['REQUEST_URI'])['path'];

$uri = rawurldecode($uri !== '/' ? trim($uri, '/') : $uri);

foreach ((array) $data['except'] as $except) {
$except = $except !== '/' ? trim($except, '/') : $except;

if ($except == $uri) {
return;
}

$except = preg_quote($except, '#');

$except = str_replace('\*', '.*', $except);

if (preg_match('#^'.$except.'\z#u', $uri) === 1) {
return;
}
}
}

// Allow framework to handle maintenance mode bypass route...
if (isset($data['secret']) && $_SERVER['REQUEST_URI'] === '/'.$data['secret']) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,14 @@ protected function getHeaders($data)

return $headers;
}

/**
* Get the URIs that should be accessible even when maintenance mode is enabled.
*
* @return array
*/
public function getExcludedPaths()
{
return $this->except;
}
}