clusev/app/Providers/AppServiceProvider.php

54 lines
2.2 KiB
PHP

<?php
namespace App\Providers;
use App\Http\Middleware\EnsureSecurityOnboarded;
use App\Services\DeploymentService;
use Illuminate\Support\ServiceProvider;
use Livewire\Livewire;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
//
}
/**
* Apply the effective panel domain (dashboard override in DB, else install-time
* APP_DOMAIN) to runtime config at boot. boot() runs every request, so a domain
* change takes effect on the next request after the operator restarts the stack —
* nothing is switched mid-session, which is what makes it safe.
*
* - Server -> Reverb publishing is pinned to the INTERNAL reverb service (both dev
* and prod compose name it `reverb`), so realtime keeps working right after a
* domain change and never depends on the new public cert. The browser endpoint is
* injected by the layout from DeploymentService::reverbClient().
* - app.url -> https://<domain> so absolute URL generation matches how the panel is
* served. With no domain (bare IP / dev) the env-derived app.url is left as is.
*/
public function boot(DeploymentService $deployment): void
{
// Re-apply the onboarding gate to EVERY Livewire component update, not just the
// initial page GET. Livewire only re-runs route middleware that is registered as
// persistent; without this, a component mounted while onboarded could keep running
// destructive actions (hardening, SSH-key provisioning, credential changes) over
// /livewire/update after the account is reverted to must_change_password mid-session.
Livewire::addPersistentMiddleware([
EnsureSecurityOnboarded::class,
]);
config([
'broadcasting.connections.reverb.options.host' => 'reverb',
'broadcasting.connections.reverb.options.port' => 8080,
'broadcasting.connections.reverb.options.scheme' => 'http',
'broadcasting.connections.reverb.options.useTLS' => false,
]);
$domain = $deployment->domain();
if ($domain !== null) {
config(['app.url' => 'https://'.$domain]);
}
}
}