application.rb 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright (C) 2012-2023 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. # EmailAddress gem clashes with EmailAddress model.
  11. # https://github.com/afair/email_address#namespace-conflict-resolution
  12. EmailAddressValidator = EmailAddress
  13. Object.send(:remove_const, :EmailAddress)
  14. # Only load gems for asset compilation if they are needed to avoid
  15. # having unneeded runtime dependencies like NodeJS.
  16. if ArgvHelper.argv.any? { |e| e.start_with? 'assets:' } || Rails.groups.exclude?('production')
  17. Bundler.load.current_dependencies.select do |dep|
  18. require dep.name if dep.groups.include?(:assets)
  19. end
  20. end
  21. Zammad::SafeMode.hint
  22. module Zammad
  23. class Application < Rails::Application
  24. # Initialize configuration defaults for originally generated Rails version.
  25. config.load_defaults 6.1
  26. Rails.autoloaders.each do |autoloader|
  27. autoloader.ignore "#{config.root}/app/frontend"
  28. autoloader.do_not_eager_load "#{config.root}/lib/core_ext"
  29. autoloader.collapse "#{config.root}/lib/omniauth"
  30. autoloader.collapse "#{config.root}/lib/generators"
  31. autoloader.inflector.inflect(
  32. 'github_database' => 'GithubDatabase',
  33. 'otrs' => 'OTRS',
  34. 'db' => 'DB',
  35. 'pgp' => 'PGP',
  36. )
  37. end
  38. # Settings in config/environments/* take precedence over those specified here.
  39. # Application configuration can go into files in config/initializers
  40. # -- all .rb files in that directory are automatically loaded after loading
  41. # the framework and any gems in your application.
  42. # Custom directories with classes and modules you want to be autoloadable.
  43. config.add_autoload_paths_to_load_path = false
  44. config.autoload_paths += %W[#{config.root}/lib]
  45. # zeitwerk:check will only check preloaded paths. To make sure that also lib/ gets validated,
  46. # add it to the eager_load_paths only if zeitwerk:check is running.
  47. config.eager_load_paths += %W[#{config.root}/lib] if ArgvHelper.argv[0].eql? 'zeitwerk:check'
  48. config.active_job.queue_adapter = :delayed_job
  49. config.active_record.use_yaml_unsafe_load = true
  50. # Remove PDF from the allowed inline content types so they have to be downloaded first (#4479).
  51. config.active_storage.content_types_allowed_inline.delete('application/pdf')
  52. # Use custom logger to log Thread id next to Process pid
  53. config.log_formatter = ::Logger::Formatter.new
  54. # REST api path
  55. config.api_path = '/api/v1'
  56. # define cache store
  57. if ENV['MEMCACHE_SERVERS'].present? && !Zammad::SafeMode.enabled?
  58. require 'dalli' # Only load this gem when it is really used.
  59. config.cache_store = [:mem_cache_store, ENV['MEMCACHE_SERVERS'], { expires_in: 7.days }]
  60. else
  61. config.cache_store = [:zammad_file_store, Rails.root.join('tmp', "cache_file_store_#{Rails.env}"), { expires_in: 7.days }]
  62. end
  63. # define websocket session store
  64. # The web socket session store will fall back to localhost Redis usage if REDIS_URL is not set.
  65. # In this case, or if forced via ZAMMAD_WEBSOCKET_SESSION_STORE_FORCE_FS_BACKEND, the FS back end will be used.
  66. legacy_ws_use_redis = ENV['REDIS_URL'].present? && ENV['ZAMMAD_WEBSOCKET_SESSION_STORE_FORCE_FS_BACKEND'].blank? && !Zammad::SafeMode.enabled?
  67. config.websocket_session_store = legacy_ws_use_redis ? :redis : :file
  68. end
  69. end