FEATURE: allow multiple asset hostnames

FEATURE: allow multiple asset hostnames

This is a breaking change … previous setting of asset_hostname is no longer supported

It was very short lived so we did not deprecate

diff --git a/README.md b/README.md
index 643f05b..aeafe4f 100644
--- a/README.md
+++ b/README.md
@@ -95,7 +95,7 @@ RAILS_DB=db_one rails console
 
 ### CDN origin support
 
-To avoid needing to configure many origins you can consider using `RailsMultisite::ConnectionManagement.asset_hostname`
+To avoid needing to configure many origins you can consider using `RailsMultisite::ConnectionManagement.asset_hostnames`
 
 When configured, requests to `asset_hostname`?__ws=another.host.name will be re-routed to the correct site. Cookies will
 be stripped on all incoming requests.
@@ -103,7 +103,7 @@ be stripped on all incoming requests.
 Example:
 
 - Multisite serves `sub.example.com` and `assets.example.com`
-- `RailsMultisite::ConnectionManagement.asset_hostname = 'assets.example.com'`
+- `RailsMultisite::ConnectionManagement.asset_hostnames = ['assets.example.com']`
 - Requests to `https://assets.example.com/route/?__ws=sub.example.com` will be routed to the `sub.example.com`
 
 
diff --git a/lib/rails_multisite/connection_management.rb b/lib/rails_multisite/connection_management.rb
index c20568d..0a870a9 100644
--- a/lib/rails_multisite/connection_management.rb
+++ b/lib/rails_multisite/connection_management.rb
@@ -35,12 +35,12 @@ module RailsMultisite
       end
     end
 
-    def self.asset_hostname
-      @asset_hostname
+    def self.asset_hostnames
+      @asset_hostnames
     end
 
-    def self.asset_hostname=(h)
-      @asset_hostname = h
+    def self.asset_hostnames=(h)
+      @asset_hostnames = h
     end
 
     def self.config_filename
@@ -380,7 +380,7 @@ module RailsMultisite
       request = Rack::Request.new(env)
 
       host =
-        if request['__ws'] && request.host == self.class.asset_hostname
+        if request['__ws'] && self.class.asset_hostnames&.include?(request.host)
           request.cookies.clear
           request['__ws']
         else
diff --git a/lib/rails_multisite/version.rb b/lib/rails_multisite/version.rb
index 837c015..b4bde4a 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.4.0"
+  VERSION = "2.5.0"
 end
diff --git a/spec/middleware_spec.rb b/spec/middleware_spec.rb
index 2b35192..1157144 100644
--- a/spec/middleware_spec.rb
+++ b/spec/middleware_spec.rb
@@ -32,7 +32,7 @@ describe RailsMultisite::Middleware do
   describe '__ws lookup support' do
     it 'returns 200 for valid site' do
 
-      RailsMultisite::ConnectionManagement.asset_hostname = "default.localhost"
+      RailsMultisite::ConnectionManagement.asset_hostnames = ["b.com", "default.localhost"]
 
       get 'http://second.localhost/html?__ws=default.localhost'
       expect(last_response).to be_ok
@@ -43,6 +43,13 @@ describe RailsMultisite::Middleware do
       expect(last_response).to be_ok
       expect(last_response.body).to include("default.localhost")
       expect(last_response.body).to_not include("second.localhost")
+
+      RailsMultisite::ConnectionManagement.asset_hostnames = nil
+
+      get 'http://second.localhost/html?__ws=default.localhost'
+      expect(last_response).to be_ok
+      expect(last_response.body).to include("second.localhost")
+      expect(last_response.body).to_not include("default.localhost")
     end
 
   end

GitHub sha: eef081c0

1 Like