application.rb 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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.0
  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_paths += %W[#{config.root}/lib]
  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. config.eager_load_paths += %W[#{config.root}/lib] if ArgvHelper.argv[0].eql? 'zeitwerk:check'
  40. config.active_job.queue_adapter = :delayed_job
  41. config.active_record.use_yaml_unsafe_load = true
  42. # Remove PDF from the allowed inline content types so they have to be downloaded first (#4479).
  43. config.active_storage.content_types_allowed_inline.delete('application/pdf')
  44. # Use custom logger to log Thread id next to Process pid
  45. config.log_formatter = ::Logger::Formatter.new
  46. # REST api path
  47. config.api_path = '/api/v1'
  48. # define cache store
  49. if ENV['MEMCACHE_SERVERS'].present? && !Zammad::SafeMode.enabled?
  50. require 'dalli' # Only load this gem when it is really used.
  51. config.cache_store = [:mem_cache_store, ENV['MEMCACHE_SERVERS'], { expires_in: 7.days }]
  52. else
  53. config.cache_store = [:zammad_file_store, Rails.root.join('tmp', "cache_file_store_#{Rails.env}"), { expires_in: 7.days }]
  54. end
  55. # define websocket session store
  56. # The web socket session store will fall back to localhost Redis usage if REDIS_URL is not set.
  57. # In this case, or if forced via ZAMMAD_WEBSOCKET_SESSION_STORE_FORCE_FS_BACKEND, the FS back end will be used.
  58. legacy_ws_use_redis = ENV['REDIS_URL'].present? && ENV['ZAMMAD_WEBSOCKET_SESSION_STORE_FORCE_FS_BACKEND'].blank? && !Zammad::SafeMode.enabled?
  59. config.websocket_session_store = legacy_ws_use_redis ? :redis : :file
  60. end
  61. end