zzz_action_cable_preferences.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. # If REDIS_URL is not set, fall back to default port / localhost, to ease configuration
  3. # for simple installations.
  4. redis_url = ENV['REDIS_URL'].presence || 'redis://localhost:6379'
  5. Rails.application.config.action_cable.cable = {
  6. adapter: :redis,
  7. driver: :hiredis,
  8. url: redis_url,
  9. channel_prefix: "zammad_#{Rails.env}",
  10. }
  11. begin
  12. Redis.new(driver: :hiredis, url: redis_url).ping
  13. Rails.logger.info { "ActionCable is using the redis instance at #{redis_url}." }
  14. rescue Redis::CannotConnectError => e
  15. warn "There was an error trying to connect to Redis via #{redis_url}."
  16. if ENV['REDIS_URL'].present?
  17. warn 'Please make sure Redis is available.'
  18. else
  19. warn 'Please provide a Redis instance at localhost:6379 or set REDIS_URL to point to a different location.'
  20. end
  21. warn e.inspect
  22. Zammad::SafeMode.continue_or_exit!
  23. end
  24. Rails.application.reloader.to_prepare do
  25. begin
  26. request_origins = ['http://localhost:3000']
  27. request_origins << "#{Setting.get('http_type')}://#{Setting.get('fqdn')}"
  28. Rails.application.config.action_cable.allowed_request_origins = request_origins
  29. Rails.application.config.action_cable.disable_request_forgery_protection = true if !Rails.env.production?
  30. Rails.logger.info { "ActionCable is configured to accept requests from #{request_origins.join(', ')}." }
  31. rescue ActiveRecord::NoDatabaseError, ActiveRecord::StatementInvalid
  32. Rails.logger.warn { "Database doesn't exist. Skipping allowed_request_origins configuration." }
  33. end
  34. end