Feb 28, 2015
0
Level 48
Middleware to White list IPs while app is down
Some times we need to do some verifications while the Applications is Down, here is an implementation.
In your .env file add:
WHEN_DOWN_WHITELIST_THIS_IPS=your_pulic_ip,other_ip
add a middleware
public function __construct(Application $app)
{
$this->app = $app;
}
...
public function handle($request, Closure $next)
{
if ($this->app->isDownForMaintenance() && ! $this->isIpWhiteListed()) {
throw new HttpException(503);
}
return $next($request);
}
private function isIpWhiteListed()
{
$ip = Request::getClientIp();
$allowed = explode(',', getenv('WHEN_DOWN_WHITELIST_THIS_IPS'));
return in_array($ip, $allowed);
}
comment the Laravel 5 default chek for maintenance mode in the Kernel and add your own.
// 'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'App\Http\Middleware\CheckForMaintenanceMode',
Please or to participate in this conversation.