application.rb 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. # zeitwerk:check will only check preloaded paths. To make sure that also lib/ gets validated,
  38. # add it to the eager_load_paths only if zeitwerk:check is running.
  39. Rails.autoloaders.main.do_not_eager_load(config.root.join('lib')) if ArgvHelper.argv[0] != 'zeitwerk:check'
  40. config.active_job.queue_adapter = :delayed_job
  41. config.active_record.use_yaml_unsafe_load = true
  42. # Use custom logger to log Thread id next to Process pid
  43. config.log_formatter = ::Logger::Formatter.new
  44. # REST api path
  45. config.api_path = '/api/v1'
  46. # define cache store
  47. if ENV['MEMCACHE_SERVERS'].present? && !Zammad::SafeMode.enabled?
  48. require 'dalli' # Only load this gem when it is really used.
  49. config.cache_store = [:mem_cache_store, ENV['MEMCACHE_SERVERS'], { expires_in: 7.days }]
  50. else
  51. config.cache_store = [:zammad_file_store, Rails.root.join('tmp', "cache_file_store_#{Rails.env}"), { expires_in: 7.days }]
  52. end
  53. # define websocket session store
  54. # The web socket session store will fall back to localhost Redis usage if REDIS_URL is not set.
  55. # In this case, or if forced via ZAMMAD_WEBSOCKET_SESSION_STORE_FORCE_FS_BACKEND, the FS back end will be used.
  56. legacy_ws_use_redis = ENV['REDIS_URL'].present? && ENV['ZAMMAD_WEBSOCKET_SESSION_STORE_FORCE_FS_BACKEND'].blank? && !Zammad::SafeMode.enabled?
  57. config.websocket_session_store = legacy_ws_use_redis ? :redis : :file
  58. end
  59. end