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
improvement: Add link to duplicate domain fix: duplicate domain error fix: remove fqdn constraint from db, because it is checked on app level
Andras Bacsai0e2889b85734
diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.phpindex 787bf879c0..75c8feea62 100644--- a/app/Livewire/Project/Application/General.php+++ b/app/Livewire/Project/Application/General.php@@ -244,12 +244,19 @@ class General extends Componentpublic function updatedApplicationFqdn(){- $this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();- $this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();- $this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {- return str($domain)->trim()->lower();- });- $this->application->fqdn = $this->application->fqdn->unique()->implode(',');+ try {+ $this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();+ $this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();+ $this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {+ return str($domain)->trim()->lower();+ });+ $this->application->fqdn = $this->application->fqdn->unique()->implode(',');+ $this->application->save();+ } catch (\Throwable $e) {+ $originalFqdn = $this->application->getOriginal('fqdn');+ $this->application->fqdn = $originalFqdn;+ return handleError($e, $this);+ }$this->resetDefaultLabels();}@@ -288,18 +295,22 @@ class General extends Componentpublic function resetDefaultLabels(){- if ($this->application->settings->is_container_label_readonly_enabled) {- return;- }- $this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");- $this->ports_exposes = $this->application->ports_exposes;- $this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;- $this->application->custom_labels = base64_encode($this->customLabels);- $this->application->save();- if ($this->application->build_pack === 'dockercompose') {- $this->loadComposeFile();+ try {+ if ($this->application->settings->is_container_label_readonly_enabled) {+ return;+ }+ $this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");+ $this->ports_exposes = $this->application->ports_exposes;+ $this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;+ $this->application->custom_labels = base64_encode($this->customLabels);+ $this->application->save();+ if ($this->application->build_pack === 'dockercompose') {+ $this->loadComposeFile();+ }+ $this->dispatch('configurationChanged');+ } catch (\Throwable $e) {+ return handleError($e, $this);}- $this->dispatch('configurationChanged');}public function checkFqdns($showToaster = true)diff --git a/app/Livewire/Project/Service/EditDomain.php b/app/Livewire/Project/Service/EditDomain.phpindex 70e8006c7f..cdec580bb0 100644--- a/app/Livewire/Project/Service/EditDomain.php+++ b/app/Livewire/Project/Service/EditDomain.php@@ -23,13 +23,17 @@ class EditDomain extends Componentpublic function updatedApplicationFqdn(){- $this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();- $this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();- $this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {- return str($domain)->trim()->lower();- });- $this->application->fqdn = $this->application->fqdn->unique()->implode(',');- $this->application->save();+ try {+ $this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();+ $this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();+ $this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {+ return str($domain)->trim()->lower();+ });+ $this->application->fqdn = $this->application->fqdn->unique()->implode(',');+ $this->application->save();+ } catch(\Throwable $e) {+ return handleError($e, $this);+ }}public function submit()diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.phpindex 487a6f107e..151e15c919 100644--- a/bootstrap/helpers/shared.php+++ b/bootstrap/helpers/shared.php@@ -1174,10 +1174,10 @@ function check_domain_usage(ServiceApplication|Application|null $resource = nullif ($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 called: <br><br>{$app->name}.");+ 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 called: <br><br>{$app->name}.");+ 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>");}}}@@ -1193,10 +1193,10 @@ function check_domain_usage(ServiceApplication|Application|null $resource = nullif ($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 called: <br><br>{$app->name}.");+ 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 called: <br><br>{$app->name}.");+ 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>");}}}diff --git a/database/migrations/2024_10_10_081444_remove_constraint_from_service_applications_fqdn.php b/database/migrations/2024_10_10_081444_remove_constraint_from_service_applications_fqdn.phpnew file mode 100644index 0000000000..feb144de68--- /dev/null+++ b/database/migrations/2024_10_10_081444_remove_constraint_from_service_applications_fqdn.php@@ -0,0 +1,34 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('service_applications', function (Blueprint $table) {+ $table->dropUnique(['fqdn']);+ });+ Schema::table('applications', function (Blueprint $table) {+ $table->dropUnique(['fqdn']);+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('service_applications', function (Blueprint $table) {+ $table->unique('fqdn');+ });+ Schema::table('applications', function (Blueprint $table) {+ $table->unique('fqdn');+ });+ }+};diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.phpindex e2cc92528a..6c93d25b74 100644--- a/resources/views/livewire/project/application/general.blade.php+++ b/resources/views/livewire/project/application/general.blade.php@@ -63,7 +63,7 @@@endif@if ($application->build_pack !== 'dockercompose')<div class="flex items-end gap-2">- <x-forms.input placeholder="https://coolify.io" id="application.fqdn" label="Domains"+ <x-forms.input placeholder="https://coolify.io" wire:model.blur="application.fqdn" label="Domains"helper="You can specify one domain with path or more with comma. You can specify a port to bind the domain to.<br><br><span class='text-helper'>Example</span><br>- http://app.coolify.io,https://cloud.coolify.io/dashboard<br>- http://app.coolify.io/api/v3<br>- http://app.coolify.io:3000 -> app.coolify.io will point to port 3000 inside the container. " /><x-forms.button wire:click="getWildcardDomain">Generate Domain</x-forms.button>