Due to the way middleware stack is constructed in a deferred manner reordering middleware is terribly complicated.
6.0.3 you could get away with stuff like:
session_operations = Rails::Configuration::MiddlewareStackProxy.new([ [:delete, RailsMultisite::Middleware], [:unshift, [RailsMultisite::Middleware, RailsMultisite::DiscoursePatches.config]], ]) Rails.configuration.middleware = Rails.configuration.middleware + session_operations
However this terrible hack no longer works due to Ruby 2.7 fixes, that just store procs in the operation list.
Talks about this issue.
@rafaelfranca started a refactor here, which is still not merged:
The ideal result should be that we can do:
Rails.configuration.middleware.delete RailsMultisite::Middleware Rails.configuration.middleware.unshift RailsMultisite::Middleware, RailsMultisite::DiscoursePatches.config
It is a sensible API and it is just super surprising that the result of those two operations is that there is no
RailsMultisite::Middleware in the stack.
We added some apis to move middleware, but that is not enough, in some cases you want to remove / insert the same middleware with a different config.