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: realtime connection?!

Andras Bacsai17c88721302b
diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php
index 79994b132f..69e1100f41 100644
--- a/app/Console/Commands/Init.php
+++ b/app/Console/Commands/Init.php
@@ -36,6 +36,7 @@ class Init extends Command
}
$this->cleanup_in_progress_application_deployments();
$this->cleanup_stucked_helper_containers();
+ setup_dynamic_configuration();
}
private function cleanup_stucked_helper_containers()
{
diff --git a/app/Livewire/Settings/Configuration.php b/app/Livewire/Settings/Configuration.php
index 62ade961b5..c2ed5f656c 100644
--- a/app/Livewire/Settings/Configuration.php
+++ b/app/Livewire/Settings/Configuration.php
@@ -93,6 +93,14 @@ class Configuration extends Component
'service' => 'coolify',
'rule' => "Host(`{$host}`)",
],
+ 'coolify-realtime-ws' =>
+ [
+ 'entryPoints' => [
+ 0 => 'http',
+ ],
+ 'service' => 'coolify-realtime',
+ 'rule' => "Host(`{$host}`) && PathPrefix(`/realtime/`)",
+ ],
],
'services' =>
[
@@ -109,6 +117,19 @@ class Configuration extends Component
],
],
],
+ 'coolify-realtime' =>
+ [
+ 'loadBalancer' =>
+ [
+ 'servers' =>
+ [
+ 0 =>
+ [
+ 'url' => 'http://coolify-realtime:6001',
+ ],
+ ],
+ ],
+ ],
],
],
];
@@ -117,6 +138,9 @@ class Configuration extends Component
$traefik_dynamic_conf['http']['routers']['coolify-http']['middlewares'] = [
0 => 'redirect-to-https@docker',
];
+ $traefik_dynamic_conf['http']['routers']['coolify-realtime-wss']['middlewares'] = [
+ 0 => 'redirect-to-https@docker',
+ ];
$traefik_dynamic_conf['http']['routers']['coolify-https'] = [
'entryPoints' => [
0 => 'https',
@@ -127,6 +151,16 @@ class Configuration extends Component
'certresolver' => 'letsencrypt',
],
];
+ $traefik_dynamic_conf['http']['routers']['coolify-realtime-wss'] = [
+ 'entryPoints' => [
+ 0 => 'https',
+ ],
+ 'service' => 'coolify-realtime',
+ 'rule' => "Host(`{$host}`) && PathPrefix(`/realtime/`)",
+ 'tls' => [
+ 'certresolver' => 'letsencrypt',
+ ],
+ ];
}
$this->save_configuration_to_disk($traefik_dynamic_conf, $file);
}
diff --git a/app/Models/InstanceSettings.php b/app/Models/InstanceSettings.php
index 8461481599..2740a4c438 100644
--- a/app/Models/InstanceSettings.php
+++ b/app/Models/InstanceSettings.php
@@ -6,6 +6,7 @@ use App\Notifications\Channels\SendsEmail;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
+use Illuminate\Support\Facades\Request;
use Spatie\Url\Url;
class InstanceSettings extends Model implements SendsEmail
@@ -30,6 +31,18 @@ class InstanceSettings extends Model implements SendsEmail
}
);
}
+ public static function realtimePort() {
+ $envDefined = env('PUSHER_PORT');
+ if ($envDefined != '6001') {
+ return $envDefined;
+ }
+ $url = Url::fromString(Request::getSchemeAndHttpHost());
+ if ($url->getScheme() === 'https') {
+ return 443;
+ } else {
+ return 6001;
+ }
+ }
public static function get()
{
return InstanceSettings::findOrFail(0);
diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.php
index 76fa9cc5a1..9bb5d323e0 100644
--- a/bootstrap/helpers/proxy.php
+++ b/bootstrap/helpers/proxy.php
@@ -2,7 +2,9 @@
use App\Actions\Proxy\SaveConfiguration;
use App\Models\Application;
+use App\Models\InstanceSettings;
use App\Models\Server;
+use Spatie\Url\Url;
use Symfony\Component\Yaml\Yaml;
function get_proxy_path()
@@ -155,7 +157,119 @@ function generate_default_proxy_configuration(Server $server)
SaveConfiguration::run($server, $config);
return $config;
}
+function setup_dynamic_configuration()
+{
+ $dynamic_config_path = get_proxy_path() . "/dynamic";
+ $settings = InstanceSettings::get();
+ $server = Server::findOrFail(0);
+ $file = "$dynamic_config_path/coolify.yaml";
+ if (empty($settings->fqdn)) {
+ instant_remote_process([
+ "rm -f $file",
+ ], $server);
+ } else {
+ $url = Url::fromString($settings->fqdn);
+ $host = $url->getHost();
+ $schema = $url->getScheme();
+ $traefik_dynamic_conf = [
+ 'http' =>
+ [
+ 'routers' =>
+ [
+ 'coolify-http' =>
+ [
+ 'entryPoints' => [
+ 0 => 'http',
+ ],
+ 'service' => 'coolify',
+ 'rule' => "Host(`{$host}`)",
+ ],
+ 'coolify-ws' =>
+ [
+ 'entryPoints' => [
+ 0 => 'http',
+ ],
+ 'service' => 'coolify-realtime',
+ 'rule' => "Host(`{$host}`) && PathPrefix(`/realtime/`)",
+ ],
+ ],
+ 'services' =>
+ [
+ 'coolify' =>
+ [
+ 'loadBalancer' =>
+ [
+ 'servers' =>
+ [
+ 0 =>
+ [
+ 'url' => 'http://coolify:80',
+ ],
+ ],
+ ],
+ ],
+ 'coolify-realtime' =>
+ [
+ 'loadBalancer' =>
+ [
+ 'servers' =>
+ [
+ 0 =>
+ [
+ 'url' => 'http://coolify-realtime:6001',
+ ],
+ ],
+ ],
+ ],
+ ],
+ ],
+ ];
+ if ($schema === 'https') {
+ $traefik_dynamic_conf['http']['routers']['coolify-http']['middlewares'] = [
+ 0 => 'redirect-to-https@docker',
+ ];
+ $traefik_dynamic_conf['http']['routers']['coolify-ws']['middlewares'] = [
+ 0 => 'redirect-to-https@docker',
+ ];
+ $traefik_dynamic_conf['http']['routers']['coolify-https'] = [
+ 'entryPoints' => [
+ 0 => 'https',
+ ],
+ 'service' => 'coolify',
+ 'rule' => "Host(`{$host}`)",
+ 'tls' => [
+ 'certresolver' => 'letsencrypt',
+ ],
+ ];
+ $traefik_dynamic_conf['http']['routers']['coolify-wss'] = [
+ 'entryPoints' => [
+ 0 => 'https',
+ ],
+ 'service' => 'coolify-realtime',
+ 'rule' => "Host(`{$host}`) && PathPrefix(`/realtime/`)",
+ 'tls' => [
+ 'certresolver' => 'letsencrypt',
+ ],
+ ];
+ }
+ $yaml = Yaml::dump($traefik_dynamic_conf, 12, 2);
+ $yaml =
+ "# This file is automatically generated by Coolify.\n" .
+ "# Do not edit it manually (only if you know what are you doing).\n\n" .
+ $yaml;
+
+ $base64 = base64_encode($yaml);
+ instant_remote_process([
+ "mkdir -p $dynamic_config_path",
+ "echo '$base64' | base64 -d > $file",
+ ], $server);
+
+ if (config('app.env') == 'local') {
+ ray($yaml);
+ }
+ }
+}
function setup_default_redirect_404(string|null $redirect_url, Server $server)
{
$traefik_dynamic_conf_path = get_proxy_path() . "/dynamic";
diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml
index 44e51248e3..2bec7be5e7 100644
--- a/docker-compose.dev.yml
+++ b/docker-compose.dev.yml
@@ -57,6 +57,7 @@ services:
- "${FORWARD_SOKETI_PORT:-6001}:6001"
environment:
SOKETI_DEBUG: "true"
+ SOKETI_PATH_PREFIX: "${PUSHER_PATH_PREFIX:-/realtime}"
SOKETI_DEFAULT_APP_ID: "${PUSHER_APP_ID:-coolify}"
SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY:-coolify}"
SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET:-coolify}"
diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml
index 80d1f8a79a..4d71b81802 100644
--- a/docker-compose.prod.yml
+++ b/docker-compose.prod.yml
@@ -124,6 +124,7 @@ services:
- "${SOKETI_PORT:-6001}:6001"
environment:
SOKETI_DEBUG: "${SOKETI_DEBUG:-false}"
+ SOKETI_PATH_PREFIX: "${PUSHER_PATH_PREFIX:-/realtime}"
SOKETI_DEFAULT_APP_ID: "${PUSHER_APP_ID}"
SOKETI_DEFAULT_APP_KEY: "${PUSHER_APP_KEY}"
SOKETI_DEFAULT_APP_SECRET: "${PUSHER_APP_SECRET}"
diff --git a/resources/views/layouts/base.blade.php b/resources/views/layouts/base.blade.php
index 1b8f50a19d..7952410025 100644
--- a/resources/views/layouts/base.blade.php
+++ b/resources/views/layouts/base.blade.php
@@ -49,17 +49,12 @@
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: 'pusher',
- cluster: "{{ env('PUSHER_HOST') }}" ||
- "{{ App\Models\InstanceSettings::get()->public_ipv4 }}" ||
- "{{ App\Models\InstanceSettings::get()->public_ipv6 }}" ||
- window.location.hostname,
+ cluster: "{{ env('PUSHER_HOST') }}" || window.location.hostname,
key: "{{ env('PUSHER_APP_KEY') }}" || 'coolify',
- wsHost: "{{ env('PUSHER_HOST') }}" ||
- "{{ App\Models\InstanceSettings::get()->public_ipv4 }}" ||
- "{{ App\Models\InstanceSettings::get()->public_ipv6 }}" ||
- window.location.hostname,
- wsPort: "{{ env('PUSHER_PORT') }}" || 6001,
- wssPort: "{{ env('PUSHER_PORT') }}" || 6001,
+ wsHost: "{{ env('PUSHER_HOST') }}" || window.location.hostname,
+ wsPort: "{{ App\Models\InstanceSettings::realtimePort() }}",
+ wssPort: "{{ App\Models\InstanceSettings::realtimePort() }}",
+ wsPath: '/realtime',
forceTLS: false,
encrypted: true,
enableStats: false,
diff --git a/versions.json b/versions.json
index 3d32bb83d3..fb9be4be3c 100644
--- a/versions.json
+++ b/versions.json
@@ -4,7 +4,7 @@
"version": "3.12.36"
},
"v4": {
- "version": "4.0.0-beta.157"
+ "version": "4.0.0-beta.153"
}
}
}