Support package for Solar Investments

v3.0.0 2024-10-25 17:27 UTC

This package is auto-updated.

Last update: 2024-10-25 17:29:32 UTC


README

Packagist Tests Dependencies

Support package for Solar Investments projects.

Installation

composer require solar-investments/support

Middleware

You can register any of the following middleware:

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

Enable Secure Pagination Links

This middleware fixes an issue where the next and prev links in the pagination response are generated using http instead of https.

Force Root URL

This middleware forces the root URL based on the incoming request.

For example, if the request is made from the origin server (origin.example.com), the middleware will adjust the application’s root URL accordingly.

It defaults to the APP_URL environment variable unless the request host differs, allowing URLs to dynamically adjust between public and origin URLs.

Hide From Robots On Origin

This middleware adds the X-Robots-Tag header to the response with the value none (same as noindex, nofollow) to prevent search engines from indexing the page. This is only done when the site is accessed directly on the origin server, e.g. http://origin.example.com instead of http://www.example.com.

Lower Path Casing

If Statamic is installed, control panel paths are not converted to lowercase.

This middleware converts the path of the request to lowercase.

Remove Trailing Slash

This middleware removes the trailing slash from the path of the request.

Require VPN

This middleware restricts access to the application to specific IP addresses. This is useful when you want to restrict access to the application to only users on a VPN (or anywhere really).

To use the RequireVpn middleware, publish the configuration file:

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

By default, this middleware is "disabled" and all IP addresses are allowed.

To restrict access from specific IP addresses, set the VPN_IP_ADDRESSES environment variable in your .env file, e.g.:

VPN_IP_ADDRESSES=192.168.1.192,10.0.0.1/8

Alternatively, you can specify the IP addresses in the config/vpn.php file.

Set Fastly Surrogate Key

This middleware adds the Surrogate-Key header to the response with the configured value, allowing you to purge the cache for specific pages.

To use the SetFastlySurrogateKey middleware, publish the configuration file:

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

Then, set the surrogate_keys in the config/fastly.php file, e.g.:

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

When the application is not running locally, the UrlServiceProvider forces the https scheme for all URLs generated by Laravel.

Testing Traits

SkipTestWhenRunningCI

This trait can be used to skip tests when running in a CI environment.

use SolarInvestments\Testing\SkipTestWhenRunningCI;

class ExampleTest extends TestCase
{
    use SkipTestWhenRunningCI;

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