Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Nov 21, 2024
1 parent 31b0037 commit 849f315
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
31 changes: 31 additions & 0 deletions app/Http/Middleware/SetCloudfrontHeaders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class SetCloudfrontHeaders
{
protected string $header = 'Cloudfront-Forwarded-Proto';

/**
* Handle an incoming request.
*
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
*/
public function handle(Request $request, Closure $next): Response
{
if ($request->hasHeader($this->header)) {
$request->headers->add([
'X-Forwarded-Proto' => $request->header($this->header),
'X-Forwarded-Port' => '443',
]);
}

return $next($request);
}
}
4 changes: 3 additions & 1 deletion bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use App\Http\Middleware\SetCloudfrontHeaders;
use Filament\Facades\Filament;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Application;
Expand All @@ -19,7 +20,8 @@
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->trustProxies('*');
$middleware->trustProxies('*')
->append(SetCloudfrontHeaders::class);

// Fix for `Route [login] not defined` exception
// @see https://github.com/filamentphp/filament/discussions/5226#discussioncomment-10555366
Expand Down

0 comments on commit 849f315

Please sign in to comment.