Skip to content

takethelead/laravel-storyblok-file-proxy

Repository files navigation

Laravel Storyblok File Proxy

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Convert Storyblok file urls to local urls and proxy them through your Laravel application. You can easily add extra middlewares to the proxy route, for example to add extra authorization checks.

Installation

You can install the package via composer:

composer require takethelead/laravel-storyblok-file-proxy

You can publish the config file with:

php artisan vendor:publish --provider="TakeTheLead\LaravelStoryblokFileProxy\LaravelStoryblokFileProxyServiceProvider" --tag="config"

This is the contents of the published config file:

return [

    /*
    |--------------------------------------------------------------------------
    | Base url
    |--------------------------------------------------------------------------
    |
    | Define the base url to proxy files through.
    |
    | Ex. 'files' will result in https://appurl.test/files/{fileSlug}
    |
    */

    'base_url' => 'files',

    /*
    |--------------------------------------------------------------------------
    | Middleware
    |--------------------------------------------------------------------------
    |
    | Define the route middleware (groups) where the proxy route should be
    | wrapped in.
    |
    |
    */

    'middleware' => [
        'web',
    ],

    /*
    |--------------------------------------------------------------------------
    | Proxy urls
    |--------------------------------------------------------------------------
    |
    | Define all url types that should be formatted. Each proxy should
    | have at least a "type" and "url" property. The defined base url
    | will be swapped with a local url.
    |
    */

    'proxy_urls' => [
        [
            'type' => 'images',
            'url' => 'https://img2.storyblok.com',
        ],
        [
            'type' => 'other',
            'url' => 'https://a.storyblok.com',
        ],
    ],

];

Usage

Proxy route

The package will proxy files through the application, therefore it registers a route in the application. You can define a custom base slug in the config file, this way you can prevent collision with your existing routes.

Through the config file you can also specify the route middleware (groups) that should be applied to the route.

Convert Storyblok urls to local urls

\StoryblokUrl::toLocal($file['filename']);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.