太阳能投资支持包

v2.1.0 2024-09-25 17:37 UTC

This package is auto-updated.

Last update: 2024-09-25 18:21:33 UTC


README

Packagist Tests Dependencies

为太阳能投资项目提供支持包。

安装

composer require solar-investments/support

中间件

您可以为以下中间件中的任何一个进行注册 register

  • SolarInvestments\Middleware\EnableSecurePaginationLinks
  • SolarInvestments\Middleware\HideFromRobotsOnOrigin
  • SolarInvestments\Middleware\LowerPathCasing
  • SolarInvestments\Middleware\RemoveTrailingSlash
  • SolarInvestments\Middleware\RequireVpn
  • SolarInvestments\Middleware\SetFastlySurrogateKey

启用安全的分页链接

此中间件修复了分页响应中“next”和“prev”链接使用“http”而不是“https”生成的问题。

在原服务器上隐藏给机器人

此中间件将包含值为“none”(等同于“noindex, nofollow”)的“X-Robots-Tag”头添加到响应中,以防止搜索引擎索引页面。这仅发生在直接在源服务器上访问网站时执行,例如使用“http://origin.example.com”而不是“http://www.example.com”。

降低路径大小写

如果已安装Statamic,则控制面板路径不会转换为小写。

此中间件将请求路径转换为小写。

删除尾部斜杠

此中间件从请求路径中删除尾部斜杠。

要求VPN

此中间件限制对特定IP地址的访问。当您只想将应用程序的访问权限限制为VPN上的用户时(或其他任何地方),这很有用。

要使用RequireVpn中间件,请发布配置文件

php artisan vendor:publish --tag=vpn-config

默认情况下,此中间件是“禁用”的,所有IP地址都允许。

要限制来自特定IP地址的访问,请在.env文件中设置VPN_IP_ADDRESSES环境变量,例如

VPN_IP_ADDRESSES=192.168.1.192,10.0.0.1/8

或者,您可以在config/vpn.php文件中指定IP地址。

设置Fastly代理密钥

此中间件将包含配置值的“Surrogate-Key”头添加到响应中,允许您清除特定页面的缓存。

要使用SetFastlySurrogateKey中间件,请发布配置文件

php artisan vendor:publish --tag=fastly-config

然后,在config/fastly.php文件中设置surrogate_keys,例如

return [

    'surrogate_keys' => [

        [
            /*
             * The key to use for requests that match the specified paths.
             *
             * The default key will be prepended to this value.
             */
            'key' => 'meals',

            /*
             * List of paths that should use the specified key.
             *
             * A path is a match if it starts with any of the specified paths.
             * 
             * Note: Paths are case-insensitive. The forward slash is optional.
             */
            'paths' => [
                'breakfast',
                'lunch',
                'dinner',
            ],
        ],

    ],

    // ...

];

URLs

当应用程序在本地运行时,UrlServiceProvider执行以下操作

  1. 强制使用所有由Laravel生成的URL的https方案。
  2. 强制将根URL设置为为APP_URL环境变量设置的值。

测试特性

SkipTestWhenRunningCI

此特性可用于在CI环境中运行时跳过测试。

use SolarInvestments\Testing\SkipTestWhenRunningCI;

class ExampleTest extends TestCase
{
    use SkipTestWhenRunningCI;

    public function test_example()
    {
        // ...
    }
}