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

[5.6] Define routes that are accessible while in maintenance mode #24731

Closed

Conversation

thannaske
Copy link
Contributor

This pull request adds a minor feature to the artisan down command and the CheckForMaintenanceMode middleware. The user is able to define routes that shall be excluded from maintenance mode which is especially useful when the developer wants to continue to serve e.g. static pages with useful or even required information.

Possible Use Case
Example: To comply with EU-law the service provider of a commercial website is required to make sure that every visitor is able to see who is running the website (Legal information page). To prevent legal actions from competitors they may want to show those (static) pages even when the application is in maintenance mode.

Usage
php artisan down --except=/legal --except=/privacy

This will result in maintenance mode for the whole application but requests to the routes /legal and /privacy won't be filtered out by the maintenance middleware.

Breaking Changes
None! It's an optional parameter for the artisan down command that does not affect the usage of the other commands in any way. Also the specific check in the middleware is only run when the $data['except'] field is set.

Further discussion
see: laravel/ideas#1242

@devcircus
Copy link
Contributor

Seems like that information should be made available on the maintenance page.

@thannaske
Copy link
Contributor Author

thannaske commented Jul 3, 2018

The PR is not about the compliance with any law; it's just a possible use case. But let's push it a litte bit further: You not only need to show who's the service provider but also declare how you handle the users privacy which is (thanks to the GDPR) a very very long page. Sure enough you could display that on your maintenance page too, but this would not be a nice "Be right back" anymore.

Or another idea: Your application consists of some static frontend pages for new users to inform about your app and during maintenance you want your potential new customers to look at those static pages whilst the "customer panel" is down for maintenance.

There are many possible use case I could imagine for this and there is no disadvantage for devs who don't want to use the feature.

@0xK4d1r
Copy link

0xK4d1r commented Jul 3, 2018

I think you should provide some tests for this feature

@taylorotwell
Copy link
Member

The description of the option is a little misleading. It says names of routes but it's actually request URIs?

@thannaske
Copy link
Contributor Author

@taylorotwell The wording was indeed misleading, sorry. You need to provide the URIs because of the way the maintenance mode is currently working in Laravel. The CheckForMaintenance middleware is executed before the request passes the router. Therefore no route name can be used, but the URI.

@@ -45,6 +45,10 @@ public function handle($request, Closure $next)
return $next($request);
}

if (isset($data['except']) && in_array($request->getRequestUri(), (array) $data['except'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would personally expect to have exactly the same feature as \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::inExceptArray.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea, thank you! This is even better.

@thannaske
Copy link
Contributor Author

I'm closing this PR in favor of @lucasmichot's idea to adopt the same behavior of the $except array as used in \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class in the CheckForMaintenanceMode::class middleware. I will file a new pull request with that kind of implementation as I feel that this solution is way better than my initial idea.

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.

5 participants