FEATURE: support for skip_multisite_middleware

FEATURE: support for skip_multisite_middleware

When configuring multisite you may want to control exactly where it is inserted.

Use Rails.configuration.skip_multisite_middleware = true to control this

Be careful to remember to delete ActionDispatch::Executor

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 26bb3dd..14c1808 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 2.1.2 - 08-05-2020
+
+ * Add support for `Rails.configuration.skip_multisite_middleware`, if configured railstie will avoid
+ all configuration of middleware.
+
 ## 2.1.1 - 13-03-2020
 
  * Add `current_db_hostnames` to get a listing of current db hostnames
diff --git a/lib/rails_multisite/railtie.rb b/lib/rails_multisite/railtie.rb
index b99d0b8..dddf8e6 100644
--- a/lib/rails_multisite/railtie.rb
+++ b/lib/rails_multisite/railtie.rb
@@ -7,20 +7,28 @@ module RailsMultisite
     end
 
     initializer "RailsMultisite.init" do |app|
-      Rails.configuration.multisite = false
+      app.config.multisite = false
 
       config_file = ConnectionManagement.default_config_filename
       if File.exist?(config_file)
         ConnectionManagement.config_filename = ConnectionManagement.default_config_filename
-        Rails.configuration.multisite = true
+        app.config.multisite = true
         Rails.logger.formatter = RailsMultisite::Formatter.new
-        app.middleware.insert_after(ActionDispatch::Executor, RailsMultisite::Middleware)
-        app.middleware.delete(ActionDispatch::Executor)
+
+        if !skip_middleware?(app.config)
+          app.middleware.insert_after(ActionDispatch::Executor, RailsMultisite::Middleware)
+          app.middleware.delete(ActionDispatch::Executor)
+        end
 
         if ENV['RAILS_DB'].present?
           ConnectionManagement.establish_connection(db: ENV['RAILS_DB'], raise_on_missing: true)
         end
       end
     end
+
+    def skip_middleware?(config)
+      return false if !config.respond_to?(:skip_multisite_middleware)
+      config.skip_multisite_middleware
+    end
   end
 end
diff --git a/lib/rails_multisite/version.rb b/lib/rails_multisite/version.rb
index 886b706..16da577 100644
--- a/lib/rails_multisite/version.rb
+++ b/lib/rails_multisite/version.rb
@@ -1,5 +1,5 @@
 # frozen_string_literal: true
 #
 module RailsMultisite
-  VERSION = "2.1.1"
+  VERSION = "2.1.2"
 end

GitHub sha: 969cdcfc