moneo / laravel-request-forwarder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Laravel Request Forwarder

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Sometimes we need to redirect requests to our application to other addresses. The best example of this is webhooks. Some service providers only send webhooks to a single address. With this package, you can post the requests coming to your application to another address as it is.

In addition to sending to a single URL, you can also send to different destinations by typing a custom provider. In our package you can see an example that sends notifications to Discord!

Installation

You can install the package via composer:

composer require moneo/laravel-request-forwarder

You can publish the config file with:

php artisan vendor:publish --tag="request-forwarder-config"

This is the contents of the published config file:

return [
    // decides which webhook to use if no webhook group name is specified while use middleware
    'default_webhook_group_name' => 'default',

    'webhooks' => [
        'default' => [
            'targets' => [
                [
                    'url' => 'https://some-domain.com/webhook',
                    'method' => 'POST',
                ],
                [
                    'url' => 'https://discord.com/api/webhooks/1209955556656291860/LAaczT-Pg785d5OzBmi6ivx2Vl7wAoruOwcVnZpb2eE2x8tf7fMi6R7_sr0IV0WoK83S',
                    'method' => 'POST',
                    'provider' => \Moneo\RequestForwarder\Providers\Discord::class,
                ],
            ],
        ],
    ],

    'queue_name' => '',

    'queue_class' => Moneo\RequestForwarder\ProcessRequestForwarder::class,
];

Usage

Add middleware to your routes which will be forwarded

Route::middleware('request-forwarder') // default group
    ->get('/endpoint', fn () => 'Some Response');

Route::middleware('request-forwarder:another-group-in-config') // customize targets with group name parameter
    ->get('/endpoint', fn () => 'Some Response');

Testing

composer test

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

About

License:MIT License


Languages

Language:PHP 100.0%