Files
jeremy bayseandClaude Sonnet 5 25363adde9 Trust reverse proxy headers to fix mixed-content asset URLs
Behind the prod TLS-terminating proxy, Laravel only saw the internal
HTTP hop and generated http:// URLs for Vite assets, which browsers
block as mixed content on an https:// page (suivicpt.trankil.net).

Configured trustProxies in bootstrap/app.php to honor X-Forwarded-*
headers, defaulting to trust any upstream (TRUSTED_PROXIES env var
to restrict to a specific IP if the app is ever reachable directly
over HTTP). .env.production reference updated with the real APP_URL
and the new TRUSTED_PROXIES setting.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-26 11:43:29 +02:00

37 lines
1.4 KiB
PHP

<?php
use App\Http\Middleware\EnsureHouseholdSelected;
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) {
$middleware->alias([
'household' => EnsureHouseholdSelected::class,
]);
// Behind a reverse proxy (nginx/Caddy) terminating TLS, Laravel only
// sees the internal HTTP hop unless it trusts X-Forwarded-* headers —
// otherwise every generated URL (including @vite asset URLs) comes
// back as http:// and gets blocked as mixed content on an https:// page.
$trustedProxies = env('TRUSTED_PROXIES', '*');
$middleware->trustProxies(
at: $trustedProxies === '*' ? '*' : array_filter(explode(',', (string) $trustedProxies)),
headers: Request::HEADER_X_FORWARDED_FOR
| Request::HEADER_X_FORWARDED_HOST
| Request::HEADER_X_FORWARDED_PORT
| Request::HEADER_X_FORWARDED_PROTO,
);
})
->withExceptions(function (Exceptions $exceptions) {
//
})->create();