fix(api): include docker_compose_domains in domain conflict check

This commit is contained in:
peaklabs-dev
2026-01-13 20:28:08 +01:00
parent 5f5c26d841
commit fb56959418

View File

@@ -158,8 +158,7 @@ function checkIfDomainIsAlreadyUsedViaAPI(Collection|array $domains, ?string $te
return str($domain); return str($domain);
}); });
// Check applications within the same team $applications = Application::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid', 'name', 'id', 'docker_compose_domains', 'build_pack']);
$applications = Application::ownedByCurrentTeamAPI($teamId)->get(['fqdn', 'uuid', 'name', 'id']);
$serviceApplications = ServiceApplication::ownedByCurrentTeamAPI($teamId)->with('service:id,name')->get(['fqdn', 'uuid', 'id', 'service_id']); $serviceApplications = ServiceApplication::ownedByCurrentTeamAPI($teamId)->with('service:id,name')->get(['fqdn', 'uuid', 'id', 'service_id']);
if ($uuid) { if ($uuid) {
@@ -168,23 +167,51 @@ function checkIfDomainIsAlreadyUsedViaAPI(Collection|array $domains, ?string $te
} }
foreach ($applications as $app) { foreach ($applications as $app) {
if (is_null($app->fqdn)) { if (! is_null($app->fqdn)) {
continue; $list_of_domains = collect(explode(',', $app->fqdn))->filter(fn ($fqdn) => $fqdn !== '');
} foreach ($list_of_domains as $domain) {
$list_of_domains = collect(explode(',', $app->fqdn))->filter(fn ($fqdn) => $fqdn !== ''); if (str($domain)->endsWith('/')) {
foreach ($list_of_domains as $domain) { $domain = str($domain)->beforeLast('/');
if (str($domain)->endsWith('/')) { }
$domain = str($domain)->beforeLast('/'); $naked_domain = str($domain)->value();
if ($domains->contains($naked_domain)) {
$conflicts[] = [
'domain' => $naked_domain,
'resource_name' => $app->name,
'resource_uuid' => $app->uuid,
'resource_type' => 'application',
'message' => "Domain $naked_domain is already in use by application '{$app->name}'",
];
}
} }
$naked_domain = str($domain)->value(); }
if ($domains->contains($naked_domain)) {
$conflicts[] = [ if ($app->build_pack === 'dockercompose' && ! empty($app->docker_compose_domains)) {
'domain' => $naked_domain, $dockerComposeDomains = json_decode($app->docker_compose_domains, true);
'resource_name' => $app->name, if (is_array($dockerComposeDomains)) {
'resource_uuid' => $app->uuid, foreach ($dockerComposeDomains as $serviceName => $domainConfig) {
'resource_type' => 'application', $domainValue = data_get($domainConfig, 'domain');
'message' => "Domain $naked_domain is already in use by application '{$app->name}'", if (empty($domainValue)) {
]; continue;
}
$list_of_domains = collect(explode(',', $domainValue))->filter(fn ($fqdn) => $fqdn !== '');
foreach ($list_of_domains as $domain) {
if (str($domain)->endsWith('/')) {
$domain = str($domain)->beforeLast('/');
}
$naked_domain = str($domain)->value();
if ($domains->contains($naked_domain)) {
$conflicts[] = [
'domain' => $naked_domain,
'resource_name' => $app->name,
'resource_uuid' => $app->uuid,
'resource_type' => 'application',
'service_name' => $serviceName,
'message' => "Domain $naked_domain is already in use by application '{$app->name}' (service: {$serviceName})",
];
}
}
}
} }
} }
} }