【发布时间】:2020-08-30 22:08:18
【问题描述】:
我知道您可以排除主应用程序的某些 URI,例如,如果您想排除 example.com/page,您只需将其添加到 CheckForMaintenanceMode.php,如下所示:
在app/Http/Middleware/CheckForMaintenanceMode.php
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode as Middleware;
class CheckForMaintenanceMode extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
*/
protected $except = [
'/page'
];
}
现在,我的应用有几个子域使用一个应用;我的主应用程序有一个子域:app.example.com,我的 API 端点有一个子域:api.example.com,主网站:www.example.com
我怎么可能 except 特定的子域而不是维护模式的 URI?就像在维护模式下拥有 api.example.com 和 app.example.com 而不是主网站 www.example.com?
我正在尝试自己解决这个问题,甚至制作自己的中间件只是为了做到这一点,但是是否可以使用 laravel 的内置维护模式和php artisan:down 来做到这一点?
类似:
// app.example.com and api.example.com is in maintenance mode except:
protected $except = [
'example.com'
'www.example.com'
];
【问题讨论】:
-
你不能只将
'www.example.com/*'添加到 except 数组吗? -
@Flame 我这样做了,它不起作用。我猜
$except对象仅适用于 URI -
调查
CheckForMaintenanceMode类,它调用了$request->fullUrlIs($except)函数。我还没有测试过它的内部工作原理,但我认为它应该与完整的 url 一起工作。您显然必须以不在浏览器中使用http://localhost的方式进行测试。 -
@Flame 它实际上适用于协议。请将其添加到答案中,以便我接受。谢谢。
标签: laravel laravel-artisan laravel-middleware