Skip to content

Commit 0e2889b

Browse files
committed
improvement: Add link to duplicate domain
fix: duplicate domain error fix: remove fqdn constraint from db, because it is checked on app level
1 parent df9b2eb commit 0e2889b

File tree

5 files changed

+78
-29
lines changed

5 files changed

+78
-29
lines changed

app/Livewire/Project/Application/General.php

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,19 @@ public function updatedApplicationBaseDirectory()
244244

245245
public function updatedApplicationFqdn()
246246
{
247-
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
248-
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
249-
$this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
250-
return str($domain)->trim()->lower();
251-
});
252-
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
247+
try {
248+
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
249+
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
250+
$this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
251+
return str($domain)->trim()->lower();
252+
});
253+
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
254+
$this->application->save();
255+
} catch (\Throwable $e) {
256+
$originalFqdn = $this->application->getOriginal('fqdn');
257+
$this->application->fqdn = $originalFqdn;
258+
return handleError($e, $this);
259+
}
253260
$this->resetDefaultLabels();
254261
}
255262

@@ -288,18 +295,22 @@ public function getWildcardDomain()
288295

289296
public function resetDefaultLabels()
290297
{
291-
if ($this->application->settings->is_container_label_readonly_enabled) {
292-
return;
293-
}
294-
$this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");
295-
$this->ports_exposes = $this->application->ports_exposes;
296-
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
297-
$this->application->custom_labels = base64_encode($this->customLabels);
298-
$this->application->save();
299-
if ($this->application->build_pack === 'dockercompose') {
300-
$this->loadComposeFile();
298+
try {
299+
if ($this->application->settings->is_container_label_readonly_enabled) {
300+
return;
301+
}
302+
$this->customLabels = str(implode('|coolify|', generateLabelsApplication($this->application)))->replace('|coolify|', "\n");
303+
$this->ports_exposes = $this->application->ports_exposes;
304+
$this->is_container_label_escape_enabled = $this->application->settings->is_container_label_escape_enabled;
305+
$this->application->custom_labels = base64_encode($this->customLabels);
306+
$this->application->save();
307+
if ($this->application->build_pack === 'dockercompose') {
308+
$this->loadComposeFile();
309+
}
310+
$this->dispatch('configurationChanged');
311+
} catch (\Throwable $e) {
312+
return handleError($e, $this);
301313
}
302-
$this->dispatch('configurationChanged');
303314
}
304315

305316
public function checkFqdns($showToaster = true)

app/Livewire/Project/Service/EditDomain.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ public function mount()
2323

2424
public function updatedApplicationFqdn()
2525
{
26-
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
27-
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
28-
$this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
29-
return str($domain)->trim()->lower();
30-
});
31-
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
32-
$this->application->save();
26+
try {
27+
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
28+
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
29+
$this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
30+
return str($domain)->trim()->lower();
31+
});
32+
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
33+
$this->application->save();
34+
} catch(\Throwable $e) {
35+
return handleError($e, $this);
36+
}
3337
}
3438

3539
public function submit()

bootstrap/helpers/shared.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,10 +1174,10 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null
11741174
if ($domains->contains($naked_domain)) {
11751175
if (data_get($resource, 'uuid')) {
11761176
if ($resource->uuid !== $app->uuid) {
1177-
throw new \RuntimeException("Domain $naked_domain is already in use by another resource called: <br><br>{$app->name}.");
1177+
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>");
11781178
}
11791179
} elseif ($domain) {
1180-
throw new \RuntimeException("Domain $naked_domain is already in use by another resource called: <br><br>{$app->name}.");
1180+
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>");
11811181
}
11821182
}
11831183
}
@@ -1193,10 +1193,10 @@ function check_domain_usage(ServiceApplication|Application|null $resource = null
11931193
if ($domains->contains($naked_domain)) {
11941194
if (data_get($resource, 'uuid')) {
11951195
if ($resource->uuid !== $app->uuid) {
1196-
throw new \RuntimeException("Domain $naked_domain is already in use by another resource called: <br><br>{$app->name}.");
1196+
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>");
11971197
}
11981198
} elseif ($domain) {
1199-
throw new \RuntimeException("Domain $naked_domain is already in use by another resource called: <br><br>{$app->name}.");
1199+
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>");
12001200
}
12011201
}
12021202
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('service_applications', function (Blueprint $table) {
15+
$table->dropUnique(['fqdn']);
16+
});
17+
Schema::table('applications', function (Blueprint $table) {
18+
$table->dropUnique(['fqdn']);
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*/
25+
public function down(): void
26+
{
27+
Schema::table('service_applications', function (Blueprint $table) {
28+
$table->unique('fqdn');
29+
});
30+
Schema::table('applications', function (Blueprint $table) {
31+
$table->unique('fqdn');
32+
});
33+
}
34+
};

resources/views/livewire/project/application/general.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
@endif
6464
@if ($application->build_pack !== 'dockercompose')
6565
<div class="flex items-end gap-2">
66-
<x-forms.input placeholder="https://coolify.io" id="application.fqdn" label="Domains"
66+
<x-forms.input placeholder="https://coolify.io" wire:model.blur="application.fqdn" label="Domains"
6767
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. " />
6868
<x-forms.button wire:click="getWildcardDomain">Generate Domain
6969
</x-forms.button>

0 commit comments

Comments
 (0)