.env
...
+ PROXY_AUTH_KEY=Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2
routes/proxy.php
use Zounar\PHPProxy\Proxy;
/*
* Dedicate a routes file to 'routes/proxy.php'
* Register it with prexix 'proxy' --> http://localhost:8000/proxy
*/
Proxy::$AUTH_KEY = getenv('PROXY_AUTH_KEY');
Proxy::run();
die();
routes/web.php routes/api.php
use Zounar\PHPProxy\Proxy;
/**
* This approach isn't recommended since
* the web, api route groups already have various middlewares attached to them.
*/
Route::any('/proxy', function () {
Proxy::$AUTH_KEY = getenv('PROXY_AUTH_KEY');
Proxy::run();
die();
});
curl --location --request GET 'http://localhost:8000/proxy' \
--header 'Proxy-Auth: Bj5pnZEX6DkcG6Nz6AjDUT1bvcGRVhRaXDuKDX9CjsEs2' \
--header 'Proxy-Target-URL: https://jsonplaceholder.typicode.com/todos/1'
Run as a standalone script