This is a basic helper for using laravel controllers as proxy servers. It allows you to forward exact requests to another server and return their response. Supports all methods, and also files.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
979 B

<?php
use App\Helpers\ProxyHelperFacade;
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::match(['get', 'post', 'head', 'patch', 'put', 'delete'] , 'proxy/{slug}', function(Request $request){
return ProxyHelperFacade::CreateProxy($request)
->withHeaders(['x-proxy' => 'laravel'])
->withToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6Imp1YW5AZ21haWwuY29tIiwic2oxNTkwMTkyNTE1fQ.db5AZuw3eSAHqjdaRn9AZX8LPbNAxPmuO8BZlEmIGk4')
->preserveQuery(true)
->toHost('http://dockerserver.test','api/proxy');
})->where('slug', '([A-Za-z0-9\-\/]+)');