feat(domains): add inline indexing and redirect controls

Move domain indexing and redirect settings into domain management views and include noindex changes in deployment configuration diffs.
This commit is contained in:
Andras Bacsai committed 2026-08-10 15:10:30 +02:00
1 parent 8c9a7413d0
commit 69ba001e21
22 files changed
+327 -185

No files matched your search

+51 -2
View File
@@ -3,6 +3,7 @@
namespace App\Livewire\Project\Service;
use App\Livewire\Concerns\InteractsWithCloudflareDomainConnect;
use App\Livewire\Project\Shared\ConfigurationChecker;
use App\Models\Server;
use App\Models\Service;
use App\Models\ServiceApplication;
@@ -17,6 +18,8 @@ class Domains extends Component
use AuthorizesRequests;
use InteractsWithCloudflareDomainConnect;
protected bool $notifyRedirectUpdate = true;
public Service $service;
/** @var array<int, array{id: int, name: string, image: ?string, required_port: ?int}> */
@@ -43,6 +46,10 @@ class Domains extends Component
public string $editingDomain = '';
public string $editingDirection = 'both';
public string $editingIndexing = 'index';
public ?int $editingServiceApplicationId = null;
public bool $showEditDomainModal = false;
@@ -95,6 +102,8 @@ class Domains extends Component
return [
'newDomain' => ValidationPatterns::applicationDomainRules(),
'editingDomain' => ValidationPatterns::applicationDomainRules(),
'editingDirection' => 'string|in:both,www,non-www',
'editingIndexing' => 'string|in:index,noindex',
'newServiceApplicationId' => 'nullable|integer',
'serviceRedirects' => 'array',
'serviceRedirects.*' => 'string|in:both,www,non-www',
@@ -114,6 +123,22 @@ class Domains extends Component
$this->loadDomainState();
}
public function toggleNoindexDomain(int $serviceApplicationId, string $domain, string|bool $indexing): void
{
$application = $this->service->applications()->findOrFail($serviceApplicationId);
$this->authorize('update', $application);
$noindex = $indexing === true || $indexing === 'noindex';
$domains = $application->noindexDomains();
$domains = $noindex ? $domains->push($domain) : $domains->reject(fn (string $item) => $item === $domain);
$application->setNoindexDomains($domains);
$application->save();
$this->service->parse();
$this->dispatch('configurationChanged')->to(ConfigurationChecker::class);
$this->dispatch('success', 'Search engine indexing updated.');
}
public function loadDomainState(): void
{
$this->service->loadMissing(['applications', 'server']);
@@ -614,13 +639,16 @@ class Domains extends Component
$this->serviceRedirects[$serviceApplicationId] = $redirect;
$this->pendingRedirectServiceApplicationId = $serviceApplicationId;
$saved = DB::transaction(function () use ($app, $redirect): bool {
$addedDomains = [];
$saved = DB::transaction(function () use ($app, $redirect, &$addedDomains): bool {
// Promote the optional www/non-www suggestion to a real domain for redirects.
if (in_array($redirect, ['www', 'non-www'], true)) {
$domainsBeforePairing = collect($this->splitDomains($app->fqdn));
if (! $this->ensureWwwNonWwwPairsConfigured($app)) {
return false;
}
$app->refresh();
$addedDomains = collect($this->splitDomains($app->fqdn))->diff($domainsBeforePairing)->values()->all();
}
$domains = collect($this->splitDomains($app->fqdn));
@@ -644,10 +672,13 @@ class Domains extends Component
$this->pendingRedirectServiceApplicationId = null;
$this->forceSaveDomains = false;
$this->forceRemovePort = false;
$this->dispatch('success', 'Redirect updated.');
if ($this->notifyRedirectUpdate) {
$this->dispatch('success', 'Redirect updated.');
}
$this->dispatch('configurationChanged');
$this->pruneDomainDnsStatusesToCurrentDomains();
$this->refreshDomains();
$this->checkUrlsDns($addedDomains, $serviceApplicationId);
} catch (\Throwable $e) {
handleError($e, $this);
}
@@ -893,6 +924,9 @@ class Domains extends Component
$this->editingIndex = $index;
$this->editingDomain = $this->domainRows[$index]['url'];
$this->editingServiceApplicationId = (int) $this->domainRows[$index]['service_application_id'];
$app = $this->findServiceApp($this->editingServiceApplicationId);
$this->editingDirection = $this->normalizeRedirect($app?->redirect);
$this->editingIndexing = $app?->isDomainNoindexed($this->editingDomain) ? 'noindex' : 'index';
$this->editDomainDnsFailed = false;
$this->editDomainDnsMessage = '';
$this->forceSaveEditDns = false;
@@ -906,6 +940,8 @@ class Domains extends Component
$this->editingIndex = null;
$this->editingDomain = '';
$this->editingServiceApplicationId = null;
$this->editingDirection = 'both';
$this->editingIndexing = 'index';
$this->editDomainDnsFailed = false;
$this->editDomainDnsMessage = '';
$this->forceSaveEditDns = false;
@@ -963,6 +999,19 @@ class Domains extends Component
return;
}
$noindexDomains = $app->noindexDomains()->reject(fn (string $domain) => $domain === $oldUrl);
if ($this->editingIndexing === 'noindex') {
$noindexDomains->push($newUrl);
}
$app->setNoindexDomains($noindexDomains);
$app->save();
if ($this->editingDirection !== $this->normalizeRedirect($app->redirect)) {
$this->notifyRedirectUpdate = false;
$this->updateServiceRedirect((int) $app->id, $this->editingDirection);
$this->notifyRedirectUpdate = true;
}
$this->cancelEdit();
$this->dispatch('edit-domain-saved');
$this->forceSaveDomains = false;