application.rb 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require_relative 'boot'
  3. require 'rails/all'
  4. require_relative '../lib/zammad/safe_mode'
  5. # DO NOT REMOVE THIS LINE - see issue #2037
  6. Bundler.setup
  7. # Require the gems listed in Gemfile, including any gems
  8. # you've limited to :test, :development, or :production.
  9. Bundler.require(*Rails.groups)
  10. # Initializers for before the app gets set up.
  11. Pathname(__dir__).glob('pre_initializers/*.rb').each do |file|
  12. require file
  13. end
  14. module Zammad
  15. class Application < Rails::Application
  16. # Initialize configuration defaults for originally generated Rails version.
  17. config.load_defaults 7.1
  18. Rails.autoloaders.each do |autoloader|
  19. autoloader.ignore "#{config.root}/app/frontend"
  20. autoloader.do_not_eager_load "#{config.root}/lib/core_ext"
  21. autoloader.collapse "#{config.root}/lib/omniauth"
  22. autoloader.collapse "#{config.root}/lib/generators"
  23. autoloader.inflector.inflect(
  24. 'github_database' => 'GithubDatabase',
  25. 'otrs' => 'OTRS',
  26. 'db' => 'DB',
  27. 'pgp' => 'PGP',
  28. )
  29. end
  30. # Settings in config/environments/* take precedence over those specified here.
  31. # Application configuration can go into files in config/initializers
  32. # -- all .rb files in that directory are automatically loaded after loading
  33. # the framework and any gems in your application.
  34. # Custom directories with classes and modules you want to be autoloadable.
  35. config.add_autoload_paths_to_load_path = false
  36. config.autoload_lib(ignore: %w[tasks templates])
  37. config.active_job.queue_adapter = :delayed_job
  38. config.active_record.use_yaml_unsafe_load = true
  39. # Use custom logger to log Thread id next to Process pid
  40. config.log_formatter = ::Logger::Formatter.new
  41. # REST api path
  42. config.api_path = '/api/v1'
  43. # define cache store
  44. if ENV['MEMCACHE_SERVERS'].present? && !Zammad::SafeMode.enabled?
  45. require 'dalli' # Only load this gem when it is really used.
  46. config.cache_store = [:mem_cache_store, ENV['MEMCACHE_SERVERS'], { expires_in: 7.days }]
  47. else
  48. config.cache_store = [:zammad_file_store, Rails.root.join('tmp', "cache_file_store_#{Rails.env}"), { expires_in: 7.days }]
  49. end
  50. # define websocket session store
  51. # The web socket session store will fall back to localhost Redis usage if REDIS_URL is not set.
  52. # In this case, or if forced via ZAMMAD_WEBSOCKET_SESSION_STORE_FORCE_FS_BACKEND, the FS back end will be used.
  53. legacy_ws_use_redis = ENV['REDIS_URL'].present? && ENV['ZAMMAD_WEBSOCKET_SESSION_STORE_FORCE_FS_BACKEND'].blank? && !Zammad::SafeMode.enabled?
  54. config.websocket_session_store = legacy_ws_use_redis ? :redis : :file
  55. end
  56. end