An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor(domains): rename check_domain_usage to checkDomainUsage and update references across the application
Andras Bacsaie0aa28ba3125
diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.phpindex 2c8ebb9e2c..67731c87d6 100644--- a/app/Livewire/Project/Application/General.php+++ b/app/Livewire/Project/Application/General.php@@ -485,7 +485,7 @@ class General extends Component}}}- check_domain_usage(resource: $this->application);+ checkDomainUsage(resource: $this->application);$this->application->fqdn = $domains->implode(',');$this->resetDefaultLabels(false);}@@ -588,7 +588,7 @@ class General extends Component}}}- check_domain_usage(resource: $this->application);+ checkDomainUsage(resource: $this->application);$this->application->save();$this->resetDefaultLabels();}diff --git a/app/Livewire/Project/Application/Previews.php b/app/Livewire/Project/Application/Previews.phpindex 9164c1475f..cc3c5ea46c 100644--- a/app/Livewire/Project/Application/Previews.php+++ b/app/Livewire/Project/Application/Previews.php@@ -63,7 +63,7 @@ class Previews extends Component$this->dispatch('error', 'Validating DNS failed.', "Make sure you have added the DNS records correctly.<br><br>$preview->fqdn->{$this->application->destination->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");$success = false;}- check_domain_usage(resource: $this->application, domain: $preview->fqdn);+ checkDomainUsage(resource: $this->application, domain: $preview->fqdn);}if (! $preview) {diff --git a/app/Livewire/Project/Service/EditDomain.php b/app/Livewire/Project/Service/EditDomain.phpindex b7f73159e7..1b24dc23a2 100644--- a/app/Livewire/Project/Service/EditDomain.php+++ b/app/Livewire/Project/Service/EditDomain.php@@ -37,7 +37,7 @@ class EditDomain extends Componentif ($warning) {$this->dispatch('warning', __('warning.sslipdomain'));}- check_domain_usage(resource: $this->application);+ checkDomainUsage(resource: $this->application);$this->validate();$this->application->save();updateCompose($this->application);diff --git a/app/Livewire/Project/Service/ServiceApplicationView.php b/app/Livewire/Project/Service/ServiceApplicationView.phpindex 5e178374b4..80fe598912 100644--- a/app/Livewire/Project/Service/ServiceApplicationView.php+++ b/app/Livewire/Project/Service/ServiceApplicationView.php@@ -145,7 +145,7 @@ class ServiceApplicationView extends Componentif ($warning) {$this->dispatch('warning', __('warning.sslipdomain'));}- check_domain_usage(resource: $this->application);+ checkDomainUsage(resource: $this->application);$this->validate();$this->application->save();updateCompose($this->application);diff --git a/app/Livewire/Settings/Index.php b/app/Livewire/Settings/Index.phpindex bce3432248..98e5ce8bdb 100644--- a/app/Livewire/Settings/Index.php+++ b/app/Livewire/Settings/Index.php@@ -108,7 +108,7 @@ class Index extends Component}}if ($this->fqdn) {- check_domain_usage(domain: $this->fqdn);+ checkDomainUsage(domain: $this->fqdn);}$this->instantSave(isSave: false);diff --git a/bootstrap/helpers/domains.php b/bootstrap/helpers/domains.phpnew file mode 100644index 0000000000..36e0443448--- /dev/null+++ b/bootstrap/helpers/domains.php@@ -0,0 +1,78 @@+<?php++use App\Models\Application;+use App\Models\ServiceApplication;++function checkDomainUsage(ServiceApplication|Application|null $resource = null, ?string $domain = null)+{+ if ($resource) {+ if ($resource->getMorphClass() === Application::class && $resource->build_pack === 'dockercompose') {+ $domains = data_get(json_decode($resource->docker_compose_domains, true), '*.domain');+ $domains = collect($domains);+ } else {+ $domains = collect($resource->fqdns);+ }+ } elseif ($domain) {+ $domains = collect([$domain]);+ } else {+ throw new \RuntimeException('No resource or FQDN provided.');+ }+ $domains = $domains->map(function ($domain) {+ if (str($domain)->endsWith('/')) {+ $domain = str($domain)->beforeLast('/');+ }++ return str($domain);+ });+ $apps = Application::all();+ foreach ($apps as $app) {+ $list_of_domains = collect(explode(',', $app->fqdn))->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)) {+ if (data_get($resource, 'uuid')) {+ if ($resource->uuid !== $app->uuid) {+ throw new \RuntimeException("Domain $naked_domain is already in use by another resource: <br><br>Link: <a class='underline' target='_blank' href='{$app->link()}'>{$app->name}</a>");+ }+ } elseif ($domain) {+ throw new \RuntimeException("Domain $naked_domain is already in use by another resource: <br><br>Link: <a class='underline' target='_blank' href='{$app->link()}'>{$app->name}</a>");+ }+ }+ }+ }+ $apps = ServiceApplication::all();+ foreach ($apps as $app) {+ $list_of_domains = collect(explode(',', $app->fqdn))->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)) {+ if (data_get($resource, 'uuid')) {+ if ($resource->uuid !== $app->uuid) {+ throw new \RuntimeException("Domain $naked_domain is already in use by another resource: <br><br>Link: <a class='underline' target='_blank' href='{$app->service->link()}'>{$app->service->name}</a>");+ }+ } elseif ($domain) {+ throw new \RuntimeException("Domain $naked_domain is already in use by another resource: <br><br>Link: <a class='underline' target='_blank' href='{$app->service->link()}'>{$app->service->name}</a>");+ }+ }+ }+ }+ if ($resource) {+ $settings = instanceSettings();+ if (data_get($settings, 'fqdn')) {+ $domain = data_get($settings, 'fqdn');+ if (str($domain)->endsWith('/')) {+ $domain = str($domain)->beforeLast('/');+ }+ $naked_domain = str($domain)->value();+ if ($domains->contains($naked_domain)) {+ throw new \RuntimeException("Domain $naked_domain is already in use by this Coolify instance.");+ }+ }+ }+}diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex 7a9b5df808..4743a811b1 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -1157,79 +1157,6 @@ function checkIfDomainIsAlreadyUsed(Collection|array $domains, ?string $teamId =}}}-function check_domain_usage(ServiceApplication|Application|null $resource = null, ?string $domain = null)-{- if ($resource) {- if ($resource->getMorphClass() === \App\Models\Application::class && $resource->build_pack === 'dockercompose') {- $domains = data_get(json_decode($resource->docker_compose_domains, true), '*.domain');- $domains = collect($domains);- } else {- $domains = collect($resource->fqdns);- }- } elseif ($domain) {- $domains = collect($domain);- } else {- throw new \RuntimeException('No resource or FQDN provided.');- }- $domains = $domains->map(function ($domain) {- if (str($domain)->endsWith('/')) {- $domain = str($domain)->beforeLast('/');- }-- return str($domain);- });- $apps = Application::all();- foreach ($apps as $app) {- $list_of_domains = collect(explode(',', $app->fqdn))->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)) {- if (data_get($resource, 'uuid')) {- if ($resource->uuid !== $app->uuid) {- throw new \RuntimeException("Domain $naked_domain is already in use by another resource: <br><br>Link: <a class='underline' target='_blank' href='{$app->link()}'>{$app->name}</a>");- }- } elseif ($domain) {- throw new \RuntimeException("Domain $naked_domain is already in use by another resource: <br><br>Link: <a class='underline' target='_blank' href='{$app->link()}'>{$app->name}</a>");- }- }- }- }- $apps = ServiceApplication::all();- foreach ($apps as $app) {- $list_of_domains = collect(explode(',', $app->fqdn))->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)) {- if (data_get($resource, 'uuid')) {- if ($resource->uuid !== $app->uuid) {- throw new \RuntimeException("Domain $naked_domain is already in use by another resource: <br><br>Link: <a class='underline' target='_blank' href='{$app->service->link()}'>{$app->service->name}</a>");- }- } elseif ($domain) {- throw new \RuntimeException("Domain $naked_domain is already in use by another resource: <br><br>Link: <a class='underline' target='_blank' href='{$app->service->link()}'>{$app->service->name}</a>");- }- }- }- }- if ($resource) {- $settings = instanceSettings();- if (data_get($settings, 'fqdn')) {- $domain = data_get($settings, 'fqdn');- if (str($domain)->endsWith('/')) {- $domain = str($domain)->beforeLast('/');- }- $naked_domain = str($domain)->value();- if ($domains->contains($naked_domain)) {- throw new \RuntimeException("Domain $naked_domain is already in use by this Coolify instance.");- }- }- }-}function parseCommandsByLineForSudo(Collection $commands, Server $server): array{