diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index b4e122ec8..b87f82bd7 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -22,9 +22,6 @@ class General extends Component public string $git_branch; public string|null $git_commit_sha; public string $build_pack; - public string|null $wildcard_domain = null; - public string|null $server_wildcard_domain = null; - public string|null $global_wildcard_domain = null; public bool $is_static; public bool $is_git_submodules_enabled; @@ -91,18 +88,20 @@ public function instantSave() $this->application->settings->save(); $this->application->save(); $this->application->refresh(); - $this->checkWildCardDomain(); $this->emit('success', 'Application settings updated!'); } - protected function checkWildCardDomain() - { - $coolify_instance_settings = InstanceSettings::get(); - $this->server_wildcard_domain = data_get($this->application, 'destination.server.settings.wildcard_domain'); - $this->global_wildcard_domain = data_get($coolify_instance_settings, 'wildcard_domain'); - $this->wildcard_domain = $this->server_wildcard_domain ?? $this->global_wildcard_domain ?? null; - } + public function getWildcardDomain() { + $server = data_get($this->application, 'destination.server'); + if ($server) { + $fqdn = generateFqdn($server, $this->application->uuid); + ray($fqdn); + $this->application->fqdn = $fqdn; + $this->application->save(); + $this->emit('success', 'Application settings updated!'); + } + } public function mount() { $this->is_static = $this->application->settings->is_static; @@ -112,31 +111,6 @@ public function mount() $this->is_preview_deployments_enabled = $this->application->settings->is_preview_deployments_enabled; $this->is_auto_deploy_enabled = $this->application->settings->is_auto_deploy_enabled; $this->is_force_https_enabled = $this->application->settings->is_force_https_enabled; - $this->checkWildCardDomain(); - } - - public function generateGlobalRandomDomain() - { - // Set wildcard domain based on Global wildcard domain - $url = Url::fromString($this->global_wildcard_domain); - $host = $url->getHost(); - $path = $url->getPath() === '/' ? '' : $url->getPath(); - $scheme = $url->getScheme(); - $this->application->fqdn = $scheme . '://' . $this->application->uuid . '.' . $host . $path; - $this->application->save(); - $this->emit('success', 'Application settings updated!'); - } - - public function generateServerRandomDomain() - { - // Set wildcard domain based on Server wildcard domain - $url = Url::fromString($this->server_wildcard_domain); - $host = $url->getHost(); - $path = $url->getPath() === '/' ? '' : $url->getPath(); - $scheme = $url->getScheme(); - $this->application->fqdn = $scheme . '://' . $this->application->uuid . '.' . $host . $path; - $this->application->save(); - $this->emit('success', 'Application settings updated!'); } public function submit() diff --git a/app/Http/Livewire/Project/New/GithubPrivateRepository.php b/app/Http/Livewire/Project/New/GithubPrivateRepository.php index 15f137bc2..c7c6c84d3 100644 --- a/app/Http/Livewire/Project/New/GithubPrivateRepository.php +++ b/app/Http/Livewire/Project/New/GithubPrivateRepository.php @@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Route; use Livewire\Component; +use Spatie\Url\Url; class GithubPrivateRepository extends Component { @@ -144,8 +145,9 @@ public function submit() $application->settings->is_static = $this->is_static; $application->settings->save(); - $sslip = sslip($destination->server); - $application->fqdn = "http://{$application->uuid}.$sslip"; + $fqdn = generateFqdn($destination->server, $application->uuid); + $application->fqdn = $fqdn; + $application->name = generate_application_name($this->selected_repository_owner . '/' . $this->selected_repository_repo, $this->selected_branch_name, $application->uuid); $application->save(); diff --git a/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php b/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php index db6f4ad89..72709f367 100644 --- a/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php +++ b/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php @@ -112,8 +112,8 @@ public function submit() $application->settings->is_static = $this->is_static; $application->settings->save(); - $sslip = sslip($destination->server); - $application->fqdn = "http://{$application->uuid}.$sslip"; + $fqdn = generateFqdn($destination->server, $application->uuid); + $application->fqdn = $fqdn; $application->name = generate_random_name($application->uuid); $application->save(); diff --git a/app/Http/Livewire/Project/New/PublicGitRepository.php b/app/Http/Livewire/Project/New/PublicGitRepository.php index 8c8b25746..371a14f0b 100644 --- a/app/Http/Livewire/Project/New/PublicGitRepository.php +++ b/app/Http/Livewire/Project/New/PublicGitRepository.php @@ -156,8 +156,8 @@ public function submit() $application->settings->is_static = $this->is_static; $application->settings->save(); - $sslip = sslip($destination->server); - $application->fqdn = "http://{$application->uuid}.$sslip"; + $fqdn = generateFqdn($destination->server, $application->uuid); + $application->fqdn = $fqdn; $application->name = generate_application_name($this->git_repository, $this->git_branch, $application->uuid); $application->save(); diff --git a/app/Http/Livewire/Project/New/SimpleDockerfile.php b/app/Http/Livewire/Project/New/SimpleDockerfile.php index 6a5d40b68..be65475a3 100644 --- a/app/Http/Livewire/Project/New/SimpleDockerfile.php +++ b/app/Http/Livewire/Project/New/SimpleDockerfile.php @@ -60,10 +60,10 @@ public function submit() 'source_type' => GithubApp::class ]); - $sslip = sslip($destination->server); + $fqdn = generateFqdn($destination->server, $application->uuid); $application->update([ 'name' => 'dockerfile-' . $application->uuid, - 'fqdn' => "http://{$application->uuid}.$sslip" + 'fqdn' => $fqdn ]); redirect()->route('project.application.configuration', [ diff --git a/app/Models/Service.php b/app/Models/Service.php index f58529c48..883a2a784 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -350,8 +350,7 @@ public function parse(bool $isNew = false): Collection } if ($key->startsWith('SERVICE_FQDN')) { if (is_null(data_get($savedService, 'fqdn'))) { - $sslip = sslip($this->server); - $fqdn = "http://$containerName.$sslip"; + $fqdn = generateFqdn($this->server, $containerName); if (substr_count($key->value(), '_') === 2 && $key->contains("=")) { $path = $value->value(); if ($generatedServiceFQDNS->count() > 0) { @@ -364,7 +363,7 @@ public function parse(bool $isNew = false): Collection } else { $generatedServiceFQDNS->put($key->value(), $fqdn); } - $fqdn = "http://$containerName.$sslip$path"; + $fqdn = "$fqdn$path"; } if (!$isDatabase) { $savedService->fqdn = $fqdn; @@ -385,8 +384,7 @@ public function parse(bool $isNew = false): Collection $forService = $value->afterLast('_'); $generatedValue = null; if ($command->value() === 'FQDN' || $command->value() === 'URL') { - $sslip = sslip($this->server); - $fqdn = "http://$containerName.$sslip"; + $fqdn = generateFqdn($this->server, $containerName); if ($foundEnv) { $fqdn = data_get($foundEnv, 'value'); } else { diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 5c19b408d..01f9d55ae 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -395,16 +395,29 @@ function data_get_str($data, $key, $default = null): Stringable return Str::of($str); } +function generateFqdn(Server $server, string $random) +{ + $wildcard = data_get($server, 'settings.wildcard_domain'); + if (is_null($wildcard) || $wildcard === '') { + $wildcard = sslip($server); + } + $url = Url::fromString($wildcard); + $host = $url->getHost(); + $path = $url->getPath() === '/' ? '' : $url->getPath(); + $scheme = $url->getScheme(); + $finalFqdn = "$scheme://{$random}.$host$path" ; + return $finalFqdn; +} function sslip(Server $server) { if (isDev()) { - return "127.0.0.1.sslip.io"; + return "http://127.0.0.1.sslip.io"; } if ($server->ip === 'host.docker.internal') { $baseIp = base_ip(); - return "$baseIp.sslip.io"; + return "http://$baseIp.sslip.io"; } - return "{$server->ip}.sslip.io"; + return "http://{$server->ip}.sslip.io"; } function getServiceTemplates() diff --git a/resources/views/livewire/project/application/general.blade.php b/resources/views/livewire/project/application/general.blade.php index c901da0e6..7d67778b8 100644 --- a/resources/views/livewire/project/application/general.blade.php +++ b/resources/views/livewire/project/application/general.blade.php @@ -15,16 +15,8 @@