Skip to content

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.

fix: respect server fqdn

Andras Bacsai3d43f2127a85
diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php
index b4e122ec83..b87f82bd7d 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 @@ class General extends Component
$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 @@ class General extends Component
$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 15f137bc2c..c7c6c84d3d 100644
--- a/app/Http/Livewire/Project/New/GithubPrivateRepository.php
+++ b/app/Http/Livewire/Project/New/GithubPrivateRepository.php
@@ -11,6 +11,7 @@ use App\Traits\SaveFromRedirect;
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 @@ class GithubPrivateRepository extends Component
$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 db6f4ad89a..72709f3676 100644
--- a/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php
+++ b/app/Http/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php
@@ -112,8 +112,8 @@ class GithubPrivateRepositoryDeployKey extends Component
$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 8c8b257460..371a14f0ba 100644
--- a/app/Http/Livewire/Project/New/PublicGitRepository.php
+++ b/app/Http/Livewire/Project/New/PublicGitRepository.php
@@ -156,8 +156,8 @@ class PublicGitRepository extends Component
$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 6a5d40b680..be65475a31 100644
--- a/app/Http/Livewire/Project/New/SimpleDockerfile.php
+++ b/app/Http/Livewire/Project/New/SimpleDockerfile.php
@@ -60,10 +60,10 @@ CMD ["nginx", "-g", "daemon off;"]
'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 f58529c487..883a2a784d 100644
--- a/app/Models/Service.php
+++ b/app/Models/Service.php
@@ -350,8 +350,7 @@ class Service extends BaseModel
}
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 @@ class Service extends BaseModel
} else {
$generatedServiceFQDNS->put($key->value(), $fqdn);
}
- $fqdn = "http://$containerName.$sslip$path";
+ $fqdn = "$fqdn$path";
}
if (!$isDatabase) {
$savedService->fqdn = $fqdn;
@@ -385,8 +384,7 @@ class Service extends BaseModel
$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 5c19b408d6..01f9d55aef 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 c901da0e61..7d67778b8d 100644
--- a/resources/views/livewire/project/application/general.blade.php
+++ b/resources/views/livewire/project/application/general.blade.php
@@ -15,16 +15,8 @@
<div class="flex items-end gap-2">
<x-forms.input placeholder="https://coolify.io" id="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. " />
- @if ($wildcard_domain)
- @if ($global_wildcard_domain)
- <x-forms.button wire:click="generateGlobalRandomDomain">Set Global Wildcard
- </x-forms.button>
- @endif
- @if ($server_wildcard_domain)
- <x-forms.button wire:click="generateServerRandomDomain">Set Server Wildcard
- </x-forms.button>
- @endif
- @endif
+ <x-forms.button wire:click="getWildcardDomain">Generate Domain
+ </x-forms.button>
</div>
@if (!$application->dockerfile)
<div class="flex items-end gap-2">