2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-30 19:01:06 +08:00
|
|
|
# we want MesageBus to be close to the front
|
2015-12-09 08:48:41 +08:00
|
|
|
# this is important cause the vast majority of web requests go to it
|
|
|
|
# this allows us to avoid full middleware crawls each time
|
2020-03-30 19:01:06 +08:00
|
|
|
#
|
|
|
|
# We aren't manipulating the middleware stack directly because of
|
|
|
|
# https://github.com/rails/rails/pull/27936
|
2020-05-07 18:44:39 +08:00
|
|
|
session_operations = Rails::Configuration::MiddlewareStackProxy.new([
|
|
|
|
[:delete, MessageBus::Rack::Middleware],
|
|
|
|
[:unshift, MessageBus::Rack::Middleware],
|
|
|
|
])
|
2017-09-04 20:42:22 +08:00
|
|
|
|
2020-05-07 18:44:39 +08:00
|
|
|
Rails.configuration.middleware = Rails.configuration.middleware + session_operations
|
2015-12-09 08:48:41 +08:00
|
|
|
|
|
|
|
# no reason to track this in development, that is 300+ redis calls saved per
|
|
|
|
# page view (we serve all assets out of thin in development)
|
|
|
|
if Rails.env != 'development' || ENV['TRACK_REQUESTS']
|
|
|
|
require 'middleware/request_tracker'
|
|
|
|
Rails.configuration.middleware.unshift Middleware::RequestTracker
|
2019-06-05 14:08:11 +08:00
|
|
|
|
|
|
|
if GlobalSetting.enable_performance_http_headers
|
|
|
|
MethodProfiler.ensure_discourse_instrumentation!
|
|
|
|
end
|
2015-12-09 08:48:41 +08:00
|
|
|
end
|
2020-03-30 19:01:06 +08:00
|
|
|
|
|
|
|
if Rails.configuration.multisite
|
|
|
|
# Multisite needs to be first, because the request tracker and message bus
|
|
|
|
# rely on it
|
|
|
|
session_operations = Rails::Configuration::MiddlewareStackProxy.new([
|
|
|
|
[:delete, RailsMultisite::Middleware],
|
|
|
|
[:unshift, [RailsMultisite::Middleware, RailsMultisite::DiscoursePatches.config]],
|
|
|
|
])
|
|
|
|
|
|
|
|
Rails.configuration.middleware = Rails.configuration.middleware + session_operations
|
|
|
|
end
|