From b14612aba5b69b8f0ed16af09f6e903ed4af2241 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 16 May 2023 15:41:23 +0200 Subject: [PATCH] multiple domains --- .../Livewire/Project/Application/General.php | 5 ++++ app/Jobs/DeployApplicationJob.php | 23 +++++++++++-------- .../project/application/deploy.blade.php | 4 ---- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/app/Http/Livewire/Project/Application/General.php b/app/Http/Livewire/Project/Application/General.php index b9b14cb18..bdf5e2dfa 100644 --- a/app/Http/Livewire/Project/Application/General.php +++ b/app/Http/Livewire/Project/Application/General.php @@ -4,6 +4,7 @@ namespace App\Http\Livewire\Project\Application; use App\Models\Application; use Livewire\Component; +use Illuminate\Support\Str; class General extends Component { @@ -75,6 +76,10 @@ class General extends Component { try { $this->validate(); + $domains = Str::of($this->application->fqdn)->trim()->explode(',')->map(function ($domain) { + return Str::of($domain)->trim()->lower(); + }); + $this->application->fqdn = $domains->implode(','); $this->application->save(); } catch (\Exception $e) { return generalErrorHandler($e, $this); diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index 243101863..941077ec2 100644 --- a/app/Jobs/DeployApplicationJob.php +++ b/app/Jobs/DeployApplicationJob.php @@ -378,16 +378,21 @@ COPY --from={$this->application->uuid}:{$this->git_commit}-build /app/{$this->ap $labels[] = 'coolify.type=application'; $labels[] = 'coolify.name=' . $this->application->name; if ($this->application->fqdn) { - $url = Url::fromString($this->application->fqdn); - $host = $url->getHost(); - $path = $url->getPath(); + $domains = Str::of($this->application->fqdn)->explode(','); $labels[] = 'traefik.enable=true'; - if ($path === '/') { - $labels[] = "traefik.http.routers.{$this->application->uuid}.rule=Host(`{$host}`) && Path(`{$path}`)"; - } else { - $labels[] = "traefik.http.routers.{$this->application->uuid}.rule=Host(`{$host}`) && PathPrefix(`{$path}`)"; - $labels[] = "traefik.http.routers.{$this->application->uuid}.middlewares={$this->application->uuid}-stripprefix"; - $labels[] = "traefik.http.middlewares.{$this->application->uuid}-stripprefix.stripprefix.prefixes={$path}"; + foreach ($domains as $domain) { + $url = Url::fromString($domain); + $host = $url->getHost(); + $path = $url->getPath(); + $slug = Str::slug($url); + $label_id = "{$this->application->uuid}-{$slug}"; + if ($path === '/') { + $labels[] = "traefik.http.routers.{$label_id}.rule=Host(`{$host}`) && Path(`{$path}`)"; + } else { + $labels[] = "traefik.http.routers.{$label_id}.rule=Host(`{$host}`) && PathPrefix(`{$path}`)"; + $labels[] = "traefik.http.routers.{$label_id}.middlewares={$label_id}-stripprefix"; + $labels[] = "traefik.http.middlewares.{$label_id}-stripprefix.stripprefix.prefixes={$path}"; + } } } return $labels; diff --git a/resources/views/livewire/project/application/deploy.blade.php b/resources/views/livewire/project/application/deploy.blade.php index d2e2cec6d..6ad3f5a71 100644 --- a/resources/views/livewire/project/application/deploy.blade.php +++ b/resources/views/livewire/project/application/deploy.blade.php @@ -12,10 +12,6 @@ Delete @if ($application->status === 'running') - @if (data_get($application, 'fqdn')) - Open URL - @endif - @if (data_get($application, 'ports_mappings_array')) @foreach ($application->ports_mappings_array as $port) @if (config('app.env') === 'local')