Skip to content

Commit 9a378f4

Browse files
committed
feat: initial reverse proxy
1 parent 61abfee commit 9a378f4

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\Http;
7+
use Illuminate\Support\Str;
8+
9+
class ShowDocController extends Controller
10+
{
11+
/**
12+
* @throws \Illuminate\Http\Client\ConnectionException
13+
*/
14+
public function __invoke(Request $request)
15+
{
16+
$rootUrl = 'https://laravel.com/docs/';
17+
$initialPath = Str::remove('docs/', $request->path());
18+
19+
$response = Http::withOptions(['allow_redirects' => false])->get($rootUrl.$initialPath);
20+
21+
if ($response->redirect()) {
22+
$redirectUrl = $response->header('Location');
23+
\Log::info('Redirecting to: '.$redirectUrl);
24+
25+
$parsedUrl = parse_url($redirectUrl);
26+
$redirectPath = $parsedUrl['path'] ?? '/';
27+
28+
return redirect()->to($redirectPath);
29+
}
30+
31+
return $response->body();
32+
}
33+
}

routes/web.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

3+
use App\Http\Controllers\ShowDocController;
34
use Illuminate\Support\Facades\Route;
45

5-
Route::get('/', function () {
6-
return view('welcome');
7-
});
6+
7+
Route::get('{any?}', ShowDocController::class)->where('any', '.*');

0 commit comments

Comments
 (0)