application.rb 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # frozen_string_literal: true
  2. require_relative 'boot'
  3. require 'rails'
  4. require 'active_record/railtie'
  5. # require 'active_storage/engine'
  6. require 'action_controller/railtie'
  7. require 'action_view/railtie'
  8. require 'action_mailer/railtie'
  9. require 'active_job/railtie'
  10. # require 'action_cable/engine'
  11. # require 'action_mailbox/engine'
  12. # require 'action_text/engine'
  13. # require 'rails/test_unit/railtie'
  14. # Used to be implicitly required in action_mailbox/engine
  15. require 'mail'
  16. # Require the gems listed in Gemfile, including any gems
  17. # you've limited to :test, :development, or :production.
  18. Bundler.require(*Rails.groups)
  19. require_relative '../lib/exceptions'
  20. require_relative '../lib/sanitize_ext/sanitize_config'
  21. require_relative '../lib/redis/namespace_extensions'
  22. require_relative '../lib/paperclip/url_generator_extensions'
  23. require_relative '../lib/paperclip/attachment_extensions'
  24. require_relative '../lib/paperclip/gif_transcoder'
  25. require_relative '../lib/paperclip/media_type_spoof_detector_extensions'
  26. require_relative '../lib/paperclip/transcoder'
  27. require_relative '../lib/paperclip/type_corrector'
  28. require_relative '../lib/paperclip/response_with_limit_adapter'
  29. require_relative '../lib/terrapin/multi_pipe_extensions'
  30. require_relative '../lib/mastodon/snowflake'
  31. require_relative '../lib/mastodon/version'
  32. require_relative '../lib/mastodon/rack_middleware'
  33. require_relative '../lib/public_file_server_middleware'
  34. require_relative '../lib/devise/strategies/two_factor_ldap_authenticatable'
  35. require_relative '../lib/devise/strategies/two_factor_pam_authenticatable'
  36. require_relative '../lib/elasticsearch/client_extensions'
  37. require_relative '../lib/chewy/settings_extensions'
  38. require_relative '../lib/chewy/index_extensions'
  39. require_relative '../lib/chewy/strategy/mastodon'
  40. require_relative '../lib/chewy/strategy/bypass_with_warning'
  41. require_relative '../lib/webpacker/manifest_extensions'
  42. require_relative '../lib/webpacker/helper_extensions'
  43. require_relative '../lib/rails/engine_extensions'
  44. require_relative '../lib/action_dispatch/remote_ip_extensions'
  45. require_relative '../lib/stoplight/redis_data_store_extensions'
  46. require_relative '../lib/active_record/database_tasks_extensions'
  47. require_relative '../lib/active_record/batches'
  48. require_relative '../lib/simple_navigation/item_extensions'
  49. Bundler.require(:pam_authentication) if ENV['PAM_ENABLED'] == 'true'
  50. module Mastodon
  51. class Application < Rails::Application
  52. # Initialize configuration defaults for originally generated Rails version.
  53. config.load_defaults 7.2
  54. # Please, add to the `ignore` list any other `lib` subdirectories that do
  55. # not contain `.rb` files, or that should not be reloaded or eager loaded.
  56. # Common ones are `templates`, `generators`, or `middleware`, for example.
  57. # config.autoload_lib(ignore: %w(assets tasks templates generators))
  58. # TODO: We should enable this eventually, but for now there are many things
  59. # in the wrong path from the perspective of zeitwerk.
  60. # Configuration for the application, engines, and railties goes here.
  61. #
  62. # These settings can be overridden in specific environments using the files
  63. # in config/environments, which are processed later.
  64. #
  65. # config.time_zone = "Central Time (US & Canada)"
  66. # config.eager_load_paths << Rails.root.join("extras")
  67. # config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
  68. # config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
  69. config.active_job.queue_adapter = :sidekiq
  70. config.action_mailer.deliver_later_queue_name = 'mailers'
  71. config.action_mailer.preview_paths << Rails.root.join('spec', 'mailers', 'previews')
  72. # We use our own middleware for this
  73. config.public_file_server.enabled = false
  74. config.middleware.use PublicFileServerMiddleware if Rails.env.local? || ENV['RAILS_SERVE_STATIC_FILES'] == 'true'
  75. config.middleware.use Rack::Attack
  76. config.middleware.use Mastodon::RackMiddleware
  77. config.before_configuration do
  78. require 'mastodon/redis_configuration'
  79. ::REDIS_CONFIGURATION = Mastodon::RedisConfiguration.new
  80. config.x.use_vips = ENV['MASTODON_USE_LIBVIPS'] == 'true'
  81. if config.x.use_vips
  82. require_relative '../lib/paperclip/vips_lazy_thumbnail'
  83. else
  84. require_relative '../lib/paperclip/lazy_thumbnail'
  85. end
  86. end
  87. config.x.captcha = config_for(:captcha)
  88. config.x.mastodon = config_for(:mastodon)
  89. config.x.translation = config_for(:translation)
  90. config.to_prepare do
  91. Doorkeeper::AuthorizationsController.layout 'modal'
  92. Doorkeeper::AuthorizedApplicationsController.layout 'admin'
  93. Doorkeeper::Application.include ApplicationExtension
  94. Doorkeeper::AccessGrant.include AccessGrantExtension
  95. Doorkeeper::AccessToken.include AccessTokenExtension
  96. Doorkeeper::OAuth::PreAuthorization.include OauthPreAuthorizationExtension
  97. Devise::FailureApp.include AbstractController::Callbacks
  98. Devise::FailureApp.include Localized
  99. end
  100. end
  101. end