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();