Laravel对特定子域的维护模式

问题描述 投票:0回答:1

我知道你可以把你的主程序的一些URI除外,比如你想除外的是 example.com/page,您可以简单地将其添加到 CheckForMaintenanceMode.php,像这样。

In 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.comapp.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'
];

PS: 对不起,我的英语不好

laravel artisan laravel-middleware
1个回答
0
投票

查看 Illuminate\Foundation\Http\Middleware\CheckMaintenanceMode 中间件类。

它检查的元素 $except 属性,使用函数 fullUrlIs() 来自 Illuminate\Http\Request 类,该类本身调用 Str::is() 助手(又称 str_is() 函数(如果你使用的是Laravel辅助函数 globals):

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;
    }

参见 https:/laravel.comdocs7.xhelpers#method-str-is。

然后,你应该可以检查这样的网址,将这个域名排除在维护模式之外(即它将一直处于上升状态)。

protected $except = [
    'https://www.example.com/*'
];
© www.soinside.com 2019 - 2024. All rights reserved.