application.rb 3.1 KB

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