fix: application domains should be http and https only

This commit is contained in:
Andras Bacsai
2024-10-11 09:56:45 +02:00
parent ed99db0a73
commit 6ac70d6e1b
2 changed files with 20 additions and 27 deletions

View File

@@ -6,6 +6,7 @@ use App\Actions\Application\GenerateConfig;
use App\Models\Application;
use Illuminate\Support\Collection;
use Livewire\Component;
use Spatie\Url\Url;
use Visus\Cuid2\Cuid2;
class General extends Component
@@ -183,9 +184,7 @@ class General extends Component
$storage->save();
});
}
}
}
public function loadComposeFile($isInit = false)
@@ -242,23 +241,6 @@ class General extends Component
}
}
public function updatedApplicationFqdn()
{
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();
}
public function updatedApplicationBuildPack()
{
@@ -332,7 +314,7 @@ class General extends Component
public function set_redirect()
{
try {
$has_www = collect($this->application->fqdns)->filter(fn ($fqdn) => str($fqdn)->contains('www.'))->count();
$has_www = collect($this->application->fqdns)->filter(fn($fqdn) => str($fqdn)->contains('www.'))->count();
if ($has_www === 0 && $this->application->redirect === 'www') {
$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).');
@@ -349,15 +331,18 @@ class General extends Component
public function submit($showToaster = true)
{
try {
if ($this->application->isDirty('redirect')) {
$this->set_redirect();
}
Url::fromString($this->application->fqdn, ['http', 'https']);
$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->resetDefaultLabels();
if ($this->application->isDirty('redirect')) {
$this->set_redirect();
}
$this->checkFqdns();
@@ -420,6 +405,10 @@ class General extends Component
$this->application->save();
$showToaster && $this->dispatch('success', 'Application settings updated!');
} catch (\Throwable $e) {
$originalFqdn = $this->application->getOriginal('fqdn');
if ($originalFqdn !== $this->application->fqdn) {
$this->application->fqdn = $originalFqdn;
}
return handleError($e, $this);
} finally {
$this->dispatch('configurationChanged');

View File

@@ -31,10 +31,14 @@ class Form extends Component
public function generate_real_url()
{
if (data_get($this->application, 'fqdn')) {
$firstFqdn = str($this->application->fqdn)->before(',');
$url = Url::fromString($firstFqdn);
$host = $url->getHost();
$this->preview_url_template = str($this->application->preview_url_template)->replace('{{domain}}', $host);
try {
$firstFqdn = str($this->application->fqdn)->before(',');
$url = Url::fromString($firstFqdn);
$host = $url->getHost();
$this->preview_url_template = str($this->application->preview_url_template)->replace('{{domain}}', $host);
} catch (\Exception $e) {
$this->dispatch('error', 'Invalid FQDN.');
}
}
}