1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* Check for Maintenance Mode Middleware. |
4
|
|
|
* |
5
|
|
|
* @package App\Http\Middleware |
6
|
|
|
* @author Taylor Otwell <[email protected]> |
7
|
|
|
* @copyright 2018-2019 Nick Menke |
8
|
|
|
* @link https://github.com/nlmenke/vertebrae |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace App\Http\Middleware; |
12
|
|
|
|
13
|
|
|
use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException; |
14
|
|
|
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware; |
15
|
|
|
use Illuminate\Http\JsonResponse; |
16
|
|
|
use Illuminate\Http\Request; |
17
|
|
|
use Illuminate\Http\Response; |
18
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The Check for Maintenance Mode middleware class. |
22
|
|
|
* |
23
|
|
|
* This class checks for maintenance mode. If maintenance is being done on the |
24
|
|
|
* application, a page will be displayed letting the user know the page is |
25
|
|
|
* unavailable. Some pages may be reachable while in maintenance mode. |
26
|
|
|
* |
27
|
|
|
* @since 0.0.0-framework introduced |
28
|
|
|
*/ |
29
|
|
|
class CheckForMaintenanceMode extends Middleware |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* The URIs that should be reachable while maintenance mode is enabled. |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
protected $except = [ |
37
|
|
|
// |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Handle an incoming request. |
42
|
|
|
* |
43
|
|
|
* @param Request $request |
44
|
|
|
* @param \Closure $next |
45
|
|
|
* @return JsonResponse|mixed |
46
|
|
|
* @throws HttpException |
47
|
|
|
*/ |
48
|
|
|
public function handle($request, \Closure $next) |
49
|
|
|
{ |
50
|
|
|
try { |
51
|
|
|
parent::handle($request, $next); |
52
|
|
|
} catch (MaintenanceModeException $e) { |
53
|
|
|
if ($request->expectsJson() || $request->wantsJson()) { |
54
|
|
|
return JsonResponse::create([ |
55
|
|
|
'message' => $e->getMessage(), |
56
|
|
|
], Response::HTTP_SERVICE_UNAVAILABLE); |
57
|
|
|
} else { |
58
|
|
|
throw $e; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $next($request); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|