Sans TrustProxies, Laravel ignore X-Forwarded-Proto derrière un proxy qui termine le TLS et génère les URLs d'assets en http://, provoquant des erreurs de contenu mixte sur les pages servies en https://. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
38 lines
1.5 KiB
PHP
38 lines
1.5 KiB
PHP
<?php
|
|
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Foundation\Configuration\Exceptions;
|
|
use Illuminate\Foundation\Configuration\Middleware;
|
|
use Illuminate\Http\Request;
|
|
|
|
return Application::configure(basePath: dirname(__DIR__))
|
|
->withRouting(
|
|
web: __DIR__.'/../routes/web.php',
|
|
commands: __DIR__.'/../routes/console.php',
|
|
health: '/up',
|
|
)
|
|
->withMiddleware(function (Middleware $middleware): void {
|
|
// The app runs behind a reverse proxy that terminates TLS and forwards
|
|
// plain HTTP — without this, Laravel doesn't know the original request
|
|
// was HTTPS and generates asset/URL links as http://, which browsers
|
|
// then block as mixed content on an https:// page.
|
|
$middleware->trustProxies(at: '*');
|
|
|
|
$middleware->alias([
|
|
'org.ip_access' => \App\Http\Middleware\CheckOrganizationIpAccess::class,
|
|
'role' => \Spatie\Permission\Middleware\RoleMiddleware::class,
|
|
'permission' => \Spatie\Permission\Middleware\PermissionMiddleware::class,
|
|
]);
|
|
|
|
// The OnlyOffice Document Server calls this server-to-server, without
|
|
// a session/CSRF token; it authenticates via a JWT bearer token instead.
|
|
$middleware->validateCsrfTokens(except: [
|
|
'onlyoffice/documents/*/callback',
|
|
]);
|
|
})
|
|
->withExceptions(function (Exceptions $exceptions): void {
|
|
$exceptions->shouldRenderJsonWhen(
|
|
fn (Request $request) => $request->is('api/*'),
|
|
);
|
|
})->create();
|