diff --git a/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php b/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php index aee61f7de..a9c01daed 100644 --- a/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php +++ b/app/Livewire/Server/Proxy/DynamicConfigurationNavbar.php @@ -15,8 +15,16 @@ public function delete(string $fileName) { $server = Server::ownedByCurrentTeam()->whereId($this->server_id)->first(); $proxy_path = $server->proxyPath(); + $proxy_type = $server->proxyType(); $file = str_replace('|', '.', $fileName); + if ($proxy_type === 'CADDY' && $file === "Caddyfile") { + $this->dispatch('error', 'Cannot delete Caddyfile.'); + return; + } instant_remote_process(["rm -f {$proxy_path}/dynamic/{$file}"], $server); + if ($proxy_type === 'CADDY') { + $server->reloadCaddy(); + } $this->dispatch('success', 'File deleted.'); $this->dispatch('loadDynamicConfigurations'); $this->dispatch('refresh'); diff --git a/app/Livewire/Server/Proxy/NewDynamicConfiguration.php b/app/Livewire/Server/Proxy/NewDynamicConfiguration.php index 302e603b3..06180d947 100644 --- a/app/Livewire/Server/Proxy/NewDynamicConfiguration.php +++ b/app/Livewire/Server/Proxy/NewDynamicConfiguration.php @@ -29,7 +29,6 @@ public function addDynamicConfiguration() 'fileName' => 'required', 'value' => 'required', ]); - if (data_get($this->parameters, 'server_uuid')) { $this->server = Server::ownedByCurrentTeam()->whereUuid(data_get($this->parameters, 'server_uuid'))->first(); } @@ -39,14 +38,21 @@ public function addDynamicConfiguration() if (is_null($this->server)) { return redirect()->route('server.index'); } - if (!str($this->fileName)->endsWith('.yaml') && !str($this->fileName)->endsWith('.yml')) { - $this->fileName = "{$this->fileName}.yaml"; + $proxy_type = $this->server->proxyType(); + if ($proxy_type === 'TRAEFIK_V2') { + if (!str($this->fileName)->endsWith('.yaml') && !str($this->fileName)->endsWith('.yml')) { + $this->fileName = "{$this->fileName}.yaml"; + } + if ($this->fileName === 'coolify.yaml') { + $this->dispatch('error', 'File name is reserved.'); + return; + } + } else if ($proxy_type === 'CADDY') { + if (!str($this->fileName)->endsWith('.caddy')) { + $this->fileName = "{$this->fileName}.caddy"; + } } - if ($this->fileName === 'coolify.yaml') { - $this->dispatch('error', 'File name is reserved.'); - return; - } - $proxy_path = $this->proxyPath(); + $proxy_path = $this->server->proxyPath(); $file = "{$proxy_path}/dynamic/{$this->fileName}"; if ($this->newFile) { $exists = instant_remote_process(["test -f $file && echo 1 || echo 0"], $this->server); @@ -55,11 +61,18 @@ public function addDynamicConfiguration() return; } } - $yaml = Yaml::parse($this->value); - $yaml = Yaml::dump($yaml, 10, 2); - $this->value = $yaml; + if ($proxy_type === 'TRAEFIK_V2') { + $yaml = Yaml::parse($this->value); + $yaml = Yaml::dump($yaml, 10, 2); + $this->value = $yaml; + } $base64_value = base64_encode($this->value); - instant_remote_process(["echo '{$base64_value}' | base64 -d > {$file}"], $this->server); + instant_remote_process([ + "echo '{$base64_value}' | base64 -d > {$file}", + ], $this->server); + if ($proxy_type === 'CADDY') { + $this->server->reloadCaddy(); + } $this->dispatch('loadDynamicConfigurations'); $this->dispatch('dynamic-configuration-added'); $this->dispatch('success', 'Dynamic configuration saved.'); diff --git a/app/Models/Server.php b/app/Models/Server.php index d2c412d9e..3cf20d7ae 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -249,8 +249,9 @@ public function setupDynamicProxyConfiguration() if (empty($settings->fqdn)) { instant_remote_process([ "rm -f $file", - "docker exec coolify-proxy caddy reload --config /dynamic/Caddyfile", ], $this); + $this->reloadCaddy(); + } else { $url = Url::fromString($settings->fqdn); $host = $url->getHost(); @@ -262,12 +263,17 @@ public function setupDynamicProxyConfiguration() $base64 = base64_encode($caddy_file); instant_remote_process([ "echo '$base64' | base64 -d > $file", - "docker exec coolify-proxy caddy reload --config /dynamic/Caddyfile", ], $this); + $this->reloadCaddy(); } } } } + public function reloadCaddy() { + return instant_remote_process([ + "docker exec coolify-proxy caddy reload --config /dynamic/Caddyfile", + ], $this); + } public function proxyPath() { $base_path = config('coolify.base_config_path'); diff --git a/resources/views/components/server/sidebar.blade.php b/resources/views/components/server/sidebar.blade.php index 94c8c9755..ef2b4b8e7 100644 --- a/resources/views/components/server/sidebar.blade.php +++ b/resources/views/components/server/sidebar.blade.php @@ -5,12 +5,12 @@ @if ($server->proxyType() !== 'NONE') - @if ($server->proxyType() === 'TRAEFIK_V2') + {{-- @if ($server->proxyType() === 'TRAEFIK_V2') --}} - @endif + {{-- @endif --}} diff --git a/resources/views/livewire/server/proxy/dynamic-configurations.blade.php b/resources/views/livewire/server/proxy/dynamic-configurations.blade.php index cb788dda4..0fd92f41e 100644 --- a/resources/views/livewire/server/proxy/dynamic-configurations.blade.php +++ b/resources/views/livewire/server/proxy/dynamic-configurations.blade.php @@ -19,7 +19,7 @@ class="font-normal text-white normal-case border-none rounded btn btn-primary bt Add -
You can add dynamic Traefik configurations here.
+
You can add dynamic proxy configurations here.
@@ -29,7 +29,7 @@ class="font-normal text-white normal-case border-none rounded btn btn-primary bt @if ($contents?->isNotEmpty()) @foreach ($contents as $fileName => $value)
- @if (str_replace('|', '.', $fileName) === 'coolify.yaml') + @if (str_replace('|', '.', $fileName) === 'coolify.yaml' ||str_replace('|', '.', $fileName) === 'Caddyfile' )

File: {{ str_replace('|', '.', $fileName) }}

diff --git a/resources/views/livewire/server/proxy/new-dynamic-configuration.blade.php b/resources/views/livewire/server/proxy/new-dynamic-configuration.blade.php index 9e98b0ed4..110ba289c 100644 --- a/resources/views/livewire/server/proxy/new-dynamic-configuration.blade.php +++ b/resources/views/livewire/server/proxy/new-dynamic-configuration.blade.php @@ -1,5 +1,5 @@
- + Save