fix: forcer HTTPS pour eviter mixed content en prod
Derriere reverse proxy, Laravel voyait les requetes en http et generait des URLs d'assets http:// sur une page https:// (bloque par le navigateur). Trust des headers X-Forwarded-* + forceScheme quand APP_URL est en https.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Illuminate\Support\Facades\Vite;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
@@ -23,5 +24,9 @@ class AppServiceProvider extends ServiceProvider
|
||||
Vite::prefetch(concurrency: 3);
|
||||
\Illuminate\Support\Facades\Route::model('commande', \App\Models\Order::class);
|
||||
\Illuminate\Support\Facades\Route::model('materiel', \App\Models\Hardware::class);
|
||||
|
||||
if (str_starts_with(config('app.url'), 'https://')) {
|
||||
URL::forceScheme('https');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -4,6 +4,7 @@ use Illuminate\Foundation\Application;
|
||||
use Illuminate\Foundation\Configuration\Exceptions;
|
||||
use Illuminate\Foundation\Configuration\Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
||||
|
||||
return Application::configure(basePath: dirname(__DIR__))
|
||||
->withRouting(
|
||||
@@ -17,7 +18,13 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
\Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class,
|
||||
]);
|
||||
|
||||
//
|
||||
$middleware->trustProxies(
|
||||
at: '*',
|
||||
headers: SymfonyRequest::HEADER_X_FORWARDED_FOR
|
||||
| SymfonyRequest::HEADER_X_FORWARDED_HOST
|
||||
| SymfonyRequest::HEADER_X_FORWARDED_PORT
|
||||
| SymfonyRequest::HEADER_X_FORWARDED_PROTO,
|
||||
);
|
||||
})
|
||||
->withExceptions(function (Exceptions $exceptions): void {
|
||||
$exceptions->shouldRenderJsonWhen(
|
||||
|
||||
Reference in New Issue
Block a user