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] Improved Maintenance Mode #33560

Merged
merged 11 commits into from
Jul 17, 2020
Merged

[8.x] Improved Maintenance Mode #33560

merged 11 commits into from
Jul 17, 2020

Conversation

taylorotwell
Copy link
Member

@taylorotwell taylorotwell commented Jul 16, 2020

This PR implements a much improved maintenance mode.

Prerendered Templates

One main deficiency of the previous implementation was the entire framework has to be booted in order to render the maintenance page. This could cause various problems if Composer was in the middle of updating dependencies, an infrastructure component was down, etc.

The new render option of the down command allows you to prerender a view. In addition, a new bootstrap/maintenance.php file is written. This file is loaded before Composer in the framework's index.php file and is able to render the template and exit with zero dependencies. Composer and Laravel are never loaded.

php artisan down --render="errors::503"

Secret Bypass Instead Of IP Allow List

The IP allow list has been removed in favor of a secret bypass route. The IP white list isn't practical for many applications. You may now use the secret option of the down command:

php artisan down --secret=MvYgEHudaikRaX4JRcyh

Once the application is in maintenance mode, you may navigate to the secret's value as a route. For example:

https://example.com/MvYgEHudaikRaX4JRcyh

The maintenance middleware will intercept this request and issue a maintenance mode bypass cookie to the user and redirect them to /, allowing them to access the application and bypass maintenance mode for 12 hours. The cookie contains a HMAC signed expiration time.

Redirects

A new redirect option has been added to the down command to instruct all paths of the application to redirect to the given path during maintenance:

php artisan down --redirect=/

Status Code

A new status option has been added to the down command to allow the status code to be customized. The default is 503. You can combine this with the redirect and secret options to still show a normal marketing / "coming soon" site but allow the real application to be accessed via the secret...

php artisan down --redirect=/ --status=200 --secret=MvYgEHudaikRaX4JRcyh

@lstables
Copy link

That is awesome Mr @taylorotwell always wanted this kinda thing instead of doing “private” routes.

@GrahamCampbell GrahamCampbell changed the title Improved Maintenance Mode [8.x] Improved Maintenance Mode Jul 16, 2020
@mattstauffer
Copy link
Contributor

I love this so much :)

@stevebauman
Copy link
Contributor

This is awesome 🙌

@fgilio
Copy link
Contributor

fgilio commented Jul 16, 2020

This is fantastic, thanks!

@ademakanaky
Copy link

This is a good one 👍

@georgeboot
Copy link
Contributor

How will this work in environments like Vapor as we can't persist a file to the file system?

* Determine if the incoming request has a maintenance mode bypass cookie.
*
* @param \Illuminate\Http\Request $request
* @return bool
Copy link

@ghost ghost Jul 17, 2020

Choose a reason for hiding this comment

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

Can you add @param array $data

*/
protected function redirectPath()
{
if ($this->option('redirect') && $this->option('redirect') !== '/') {

Choose a reason for hiding this comment

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

Note - looks good but generally not a fan of directly comparing strings, would prefer str cmp methods instead

Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

FTR, there's exactly one strcmp in the entire framework AFAICS. I didn't bother to count the direct string comparison checks 😄

@taylorotwell taylorotwell merged commit 1127c17 into master Jul 17, 2020
@taylorotwell taylorotwell deleted the maintenance branch July 17, 2020 13:13
@jesseleite
Copy link

I can get down with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants