Browse Source

Feature: Mobile - Add action cable support with reverse proxies.

Martin Gruner 2 years ago
parent
commit
d873b2a04b

+ 12 - 0
config/initializers/action_cable_preferences.rb

@@ -26,4 +26,16 @@ if ENV['ENABLE_EXPERIMENTAL_MOBILE_FRONTEND'] == 'true'
     warn e.inspect
     exit! # rubocop:disable Rails/Exit
   end
+
+  if Rails.env.production?
+    Rails.application.reloader.to_prepare do
+      begin
+        request_origins = ['http://localhost:3000']
+        request_origins << "#{Setting.get('http_type')}://#{Setting.get('fqdn')}"
+        Rails.application.config.action_cable.allowed_request_origins = request_origins
+      rescue ActiveRecord::NoDatabaseError
+        Rails.logger.debug("Database doesn't exist. Skipping allowed_request_origins configuration.")
+      end
+    end
+  end
 end

+ 3 - 0
contrib/apache2/zammad.conf

@@ -29,7 +29,10 @@ ServerTokens Prod
     ProxyPass /favicon.ico !
     ProxyPass /apple-touch-icon.png !
     ProxyPass /robots.txt !
+    # legacy web socket server
     ProxyPass /ws ws://127.0.0.1:6042/
+    # action cable
+    ProxyPass /cable ws://127.0.0.1:3000/cable
     ProxyPass / http://127.0.0.1:3000/
 
     # change this line in an SSO setup

+ 4 - 0
contrib/apache2/zammad_ssl.conf

@@ -45,7 +45,10 @@ ServerTokens Prod
     ProxyPass /favicon.ico !
     ProxyPass /apple-touch-icon.png !
     ProxyPass /robots.txt !
+    # legacy web socket server
     ProxyPass /ws ws://127.0.0.1:6042/
+    # action cable
+    ProxyPass /cable ws://127.0.0.1:3000/cable
     ProxyPass / http://127.0.0.1:3000/
 
     # change this line in an SSO setup
@@ -55,6 +58,7 @@ ServerTokens Prod
     # if you use the settings below, make sure to comment out the above two options
     # This may not apply to all systems, applies to openSuse
     #ProxyPass /ws ws://127.0.0.1:6042/ "retry=1 acque=3000 timeout=600 keepalive=On"
+    #ProxyPass /cable ws://127.0.0.1:3000/cable "retry=1 acque=3000 timeout=600 keepalive=On"
     #ProxyPass / http://127.0.0.1:3000/ "retry=1 acque=3000 timeout=600 keepalive=On"
 
     DocumentRoot "/opt/zammad/public"

+ 13 - 0
contrib/nginx/zammad.conf

@@ -31,6 +31,7 @@ server {
         expires max;
     }
 
+    # legacy web socket server
     location /ws {
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
@@ -42,6 +43,18 @@ server {
         proxy_pass http://zammad-websocket;
     }
 
+    # action cable
+    location /cable {
+        proxy_http_version 1.1;
+        proxy_set_header Upgrade $http_upgrade;
+        proxy_set_header Connection "Upgrade";
+        proxy_set_header CLIENT_IP $remote_addr;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header X-Forwarded-Proto $scheme;
+        proxy_read_timeout 86400;
+        proxy_pass http://zammad-railsserver;
+    }
+
     location / {
         proxy_set_header Host $http_host;
         proxy_set_header CLIENT_IP $remote_addr;

+ 14 - 1
contrib/nginx/zammad_ssl.conf

@@ -88,17 +88,30 @@ server {
     expires max;
   }
 
+  # legacy web socket server
   location /ws {
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "Upgrade";
     proxy_set_header CLIENT_IP $remote_addr;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-    proxy_set_header X-Forwarded-Proto	$scheme;
+    proxy_set_header X-Forwarded-Proto $scheme;
     proxy_read_timeout 86400;
     proxy_pass http://zammad-websocket;
   }
 
+  # action cable
+  location /cable {
+    proxy_http_version 1.1;
+    proxy_set_header Upgrade $http_upgrade;
+    proxy_set_header Connection "Upgrade";
+    proxy_set_header CLIENT_IP $remote_addr;
+    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+    proxy_set_header X-Forwarded-Proto $scheme;
+    proxy_read_timeout 86400;
+    proxy_pass http://zammad-railsserver;
+  }
+
   location / {
     proxy_set_header Host $http_host;
     proxy_set_header CLIENT_IP $remote_addr;