multiple domains

This commit is contained in:
Andras Bacsai 2023-05-16 15:41:23 +02:00
parent 38a45d9816
commit b14612aba5
3 changed files with 19 additions and 13 deletions

View File

@ -4,6 +4,7 @@
use App\Models\Application;
use Livewire\Component;
use Illuminate\Support\Str;
class General extends Component
{
@ -75,6 +76,10 @@ public function submit()
{
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);

View File

@ -378,16 +378,21 @@ private function set_labels_for_applications()
$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;

View File

@ -12,10 +12,6 @@
Delete</x-inputs.button>
<span wire:poll.5000ms='pollingStatus'>
@if ($application->status === 'running')
@if (data_get($application, 'fqdn'))
<a target="_blank" href="{{ data_get($application, 'fqdn') }}">Open URL</a>
@endif
@if (data_get($application, 'ports_mappings_array'))
@foreach ($application->ports_mappings_array as $port)
@if (config('app.env') === 'local')