Skip to content

Commit

Permalink
Add possibility to disable maintenance middleware for specific URIs v…
Browse files Browse the repository at this point in the history
…ia array
  • Loading branch information
thannaske committed Jul 3, 2018
1 parent 1ce5f49 commit e535b30
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class CheckForMaintenanceMode
*/
protected $app;

/**
* The URIs that should be accessible while maintenance mode is enabled.
*
* @var array
*/
protected $except = [];

/**
* Create a new middleware instance.
*
Expand Down Expand Up @@ -45,9 +52,35 @@ public function handle($request, Closure $next)
return $next($request);
}

if ($this->inExceptArray($request)) {
return $next($request);
}

throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']);
}

return $next($request);
}

/**
* Determine if the request has a URI that should be accessible in maintenance mode.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function inExceptArray($request)
{
foreach ($this->except as $except) {
if ($except !== '/') {
$except = trim($except, '/');
}

if ($request->fullUrlIs($except) || $request->is($except)) {
return true;
}
}

return false;
}

}

0 comments on commit e535b30

Please sign in to comment.