Skip to content

Commit 6ac70d6

Browse files
committed
fix: application domains should be http and https only
1 parent ed99db0 commit 6ac70d6

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

app/Livewire/Project/Application/General.php

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\Models\Application;
77
use Illuminate\Support\Collection;
88
use Livewire\Component;
9+
use Spatie\Url\Url;
910
use Visus\Cuid2\Cuid2;
1011

1112
class General extends Component
@@ -183,9 +184,7 @@ public function instantSave()
183184
$storage->save();
184185
});
185186
}
186-
187187
}
188-
189188
}
190189

191190
public function loadComposeFile($isInit = false)
@@ -242,23 +241,6 @@ public function updatedApplicationBaseDirectory()
242241
}
243242
}
244243

245-
public function updatedApplicationFqdn()
246-
{
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-
}
260-
$this->resetDefaultLabels();
261-
}
262244

263245
public function updatedApplicationBuildPack()
264246
{
@@ -332,7 +314,7 @@ public function checkFqdns($showToaster = true)
332314
public function set_redirect()
333315
{
334316
try {
335-
$has_www = collect($this->application->fqdns)->filter(fn ($fqdn) => str($fqdn)->contains('www.'))->count();
317+
$has_www = collect($this->application->fqdns)->filter(fn($fqdn) => str($fqdn)->contains('www.'))->count();
336318
if ($has_www === 0 && $this->application->redirect === 'www') {
337319
$this->dispatch('error', 'You want to redirect to www, but you do not have a www domain set.<br><br>Please add www to your domain list and as an A DNS record (if applicable).');
338320

@@ -349,15 +331,18 @@ public function set_redirect()
349331
public function submit($showToaster = true)
350332
{
351333
try {
352-
if ($this->application->isDirty('redirect')) {
353-
$this->set_redirect();
354-
}
334+
Url::fromString($this->application->fqdn, ['http', 'https']);
355335
$this->application->fqdn = str($this->application->fqdn)->replaceEnd(',', '')->trim();
356336
$this->application->fqdn = str($this->application->fqdn)->replaceStart(',', '')->trim();
357337
$this->application->fqdn = str($this->application->fqdn)->trim()->explode(',')->map(function ($domain) {
358338
return str($domain)->trim()->lower();
359339
});
360340
$this->application->fqdn = $this->application->fqdn->unique()->implode(',');
341+
$this->resetDefaultLabels();
342+
343+
if ($this->application->isDirty('redirect')) {
344+
$this->set_redirect();
345+
}
361346

362347
$this->checkFqdns();
363348

@@ -420,6 +405,10 @@ public function submit($showToaster = true)
420405
$this->application->save();
421406
$showToaster && $this->dispatch('success', 'Application settings updated!');
422407
} catch (\Throwable $e) {
408+
$originalFqdn = $this->application->getOriginal('fqdn');
409+
if ($originalFqdn !== $this->application->fqdn) {
410+
$this->application->fqdn = $originalFqdn;
411+
}
423412
return handleError($e, $this);
424413
} finally {
425414
$this->dispatch('configurationChanged');

app/Livewire/Project/Application/Preview/Form.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ public function resetToDefault()
3131
public function generate_real_url()
3232
{
3333
if (data_get($this->application, 'fqdn')) {
34-
$firstFqdn = str($this->application->fqdn)->before(',');
35-
$url = Url::fromString($firstFqdn);
36-
$host = $url->getHost();
37-
$this->preview_url_template = str($this->application->preview_url_template)->replace('{{domain}}', $host);
34+
try {
35+
$firstFqdn = str($this->application->fqdn)->before(',');
36+
$url = Url::fromString($firstFqdn);
37+
$host = $url->getHost();
38+
$this->preview_url_template = str($this->application->preview_url_template)->replace('{{domain}}', $host);
39+
} catch (\Exception $e) {
40+
$this->dispatch('error', 'Invalid FQDN.');
41+
}
3842
}
3943
}
4044

0 commit comments

Comments
 (0)