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(deployment): enhance COOLIFY_URL and COOLIFY_FQDN variable generation for better compatibility

Andras Bacsai085529dc6396
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php
index f3ad4383cc..c4a71d599e 100644
--- a/app/Jobs/ApplicationDeploymentJob.php
+++ b/app/Jobs/ApplicationDeploymentJob.php
@@ -1347,9 +1347,16 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue
$fqdn = $this->preview->fqdn;
}
if (isset($fqdn)) {
- $this->coolify_variables .= "COOLIFY_FQDN={$fqdn} ";
- $url = str($fqdn)->replace('http://', '')->replace('https://', '');
- $this->coolify_variables .= "COOLIFY_URL={$url} ";
+ $fqdnWithoutPort = str($fqdn)->after('://')->before(':')->prepend(str($fqdn)->before('://')->append('://'));
+ $url = str($fqdn)->replace('http://', '')->replace('https://', '')->before(':');
+ if ((int) $this->application->compose_parsing_version >= 3) {
+ $this->coolify_variables .= "COOLIFY_URL={$fqdnWithoutPort} ";
+ $this->coolify_variables .= "COOLIFY_FQDN={$url} ";
+ } else {
+ $this->coolify_variables .= "COOLIFY_URL={$fqdnWithoutPort} ";
+ $this->coolify_variables .= "COOLIFY_FQDN={$url} ";
+ }
+
}
if (isset($this->application->git_branch)) {
$this->coolify_variables .= "COOLIFY_BRANCH={$this->application->git_branch} ";
diff --git a/app/Models/Service.php b/app/Models/Service.php
index 8f0c16d401..da6c34fbbd 100644
--- a/app/Models/Service.php
+++ b/app/Models/Service.php
@@ -1264,7 +1264,6 @@ class Service extends BaseModel
foreach ($sorted as $env) {
$envs->push("{$env->key}={$env->real_value}");
}
- ray($envs);
if ($envs->count() === 0) {
$commands[] = 'touch .env';
} else {
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index 2fcc44ac9f..b8497e2d5e 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -3716,10 +3716,13 @@ function newParser(Application|Service $resource, int $pull_request_id = 0, ?int
}
// Add COOLIFY_FQDN & COOLIFY_URL to environment
if (! $isDatabase && $fqdns instanceof Collection && $fqdns->count() > 0) {
- $coolifyEnvironments->put('COOLIFY_URL', $fqdns->implode(','));
+ $fqdnsWithoutPort = $fqdns->map(function ($fqdn) {
+ return str($fqdn)->after('://')->before(':')->prepend(str($fqdn)->before('://')->append('://'));
+ });
+ $coolifyEnvironments->put('COOLIFY_URL', $fqdnsWithoutPort->implode(','));
$urls = $fqdns->map(function ($fqdn) {
- return str($fqdn)->replace('http://', '')->replace('https://', '');
+ return str($fqdn)->replace('http://', '')->replace('https://', '')->before(':');
});
$coolifyEnvironments->put('COOLIFY_FQDN', $urls->implode(','));
}