From 6f7f0973dbd8601ef748e4fbd98323a5df769408 Mon Sep 17 00:00:00 2001 From: Kevin McConnell Date: Wed, 24 Sep 2025 14:37:13 +0100 Subject: [PATCH] Allow serving cable traffic under `$SCRIPT_NAME` If deploying Campfire to a path other than the root (for example, using Kamal's path-based routing) then the Action Cable endpoint needs to be adjusted to include that path. Prepending the script name to the cable path means it will be adjusted to the path in the same way that the application routes are. When script name is the default, the behaviour is unchanged. --- app/helpers/cable_helper.rb | 7 +++++++ app/views/layouts/application.html.erb | 1 + 2 files changed, 8 insertions(+) create mode 100644 app/helpers/cable_helper.rb diff --git a/app/helpers/cable_helper.rb b/app/helpers/cable_helper.rb new file mode 100644 index 0000000..e715806 --- /dev/null +++ b/app/helpers/cable_helper.rb @@ -0,0 +1,7 @@ +module CableHelper + def script_aware_action_cable_meta_tag + tag.meta \ + name: "action-cable-url", + content: "#{request.script_name}#{ActionCable.server.config.mount_path}" + end +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index fc9db75..00f7e5b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -12,6 +12,7 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= current_user_meta_tags %> + <%= script_aware_action_cable_meta_tag %> <%= tag.meta name: "vapid-public-key", content: Rails.configuration.x.vapid.public_key %> <%= tag.meta name: "turbo-prefetch", content: "true" %>