This commit is contained in:
Andras Bacsai
2023-06-22 14:18:17 +02:00
parent 3af354b343
commit 448fa200a4
5 changed files with 166 additions and 82 deletions

View File

@@ -15,8 +15,13 @@ class Proxy extends Component
public ProxyTypes $selectedProxy = ProxyTypes::TRAEFIK_V2;
public $proxy_settings = null;
public string|null $redirect_url = null;
protected $listeners = ['serverValidated', 'saveConfiguration'];
public function mount()
{
$this->redirect_url = $this->server->proxy->redirect_url;
}
public function serverValidated()
{
$this->server->refresh();
@@ -52,17 +57,20 @@ class Proxy extends Component
$this->server->proxy->status = 'exited';
$this->server->save();
}
public function saveConfiguration(Server $server)
public function saveConfiguration()
{
try {
$proxy_path = config('coolify.proxy_config_path');
$this->proxy_settings = Str::of($this->proxy_settings)->trim()->value;
$docker_compose_yml_base64 = base64_encode($this->proxy_settings);
$server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
$server->save();
$this->server->proxy->last_saved_settings = Str::of($docker_compose_yml_base64)->pipe('md5')->value;
$this->server->proxy->redirect_url = $this->redirect_url;
$this->server->save();
instant_remote_process([
"echo '$docker_compose_yml_base64' | base64 -d > $proxy_path/docker-compose.yml",
], $server);
], $this->server);
$this->server->refresh();
setup_default_redirect_404(redirect_url: $this->server->proxy->redirect_url, server: $this->server);
$this->emit('success', 'Proxy configuration saved.');
} catch (\Exception $e) {
return general_error_handler(err: $e);

View File

@@ -15,7 +15,7 @@ class Configuration extends Component
public $do_not_track;
public $is_auto_update_enabled;
public $is_registration_enabled;
protected string $dynamic_config_path;
protected string $dynamic_config_path = '/data/coolify/proxy/dynamic';
protected Server $server;
protected $rules = [
@@ -117,9 +117,6 @@ class Configuration extends Component
"rm -f $file",
], $this->server);
} else {
$url = Url::fromString($this->settings->default_redirect_404);
$host = $url->getHost();
$schema = $url->getScheme();
$traefik_dynamic_conf = [
'http' =>
[
@@ -200,10 +197,9 @@ class Configuration extends Component
$this->validate();
$this->settings->save();
$this->dynamic_config_path = '/data/coolify/proxy/dynamic';
$this->server = Server::findOrFail(0);
$this->setup_instance_fqdn();
$this->setup_default_redirect_404();
setup_default_redirect_404(redirect_url: $this->settings->default_redirect_404, server: $this->server);
if ($this->settings->fqdn || $this->settings->default_redirect_404) {
dispatch(new InstanceProxyCheckJob());
}