Skip to content

Commit

Permalink
Merge pull request #2559 from tvdeyen/site-redirects/allow-other-host
Browse files Browse the repository at this point in the history
Allow redirecting to other host in site redirect
  • Loading branch information
tvdeyen authored Aug 14, 2023
2 parents f299cca + 1791ea1 commit 4687a02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/controllers/concerns/alchemy/site_redirects.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module SiteRedirects
private

def enforce_primary_host_for_site
redirect_to url_for(host: current_alchemy_site.host), status: :moved_permanently
redirect_to url_for(host: current_alchemy_site.host), status: :moved_permanently, allow_other_host: true
end

def needs_redirect_to_primary_host?
Expand Down
34 changes: 27 additions & 7 deletions spec/requests/alchemy/site_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,39 @@
require "rails_helper"

RSpec.describe "Site requests" do
let(:language) { create(:alchemy_language, site: site) }

let(:page) do
Alchemy::Site.current = site
root = create(:alchemy_page, :language_root, language: language)
create(:alchemy_page, :public, parent: root)
end

context "a site with host" do
let!(:site) { create(:alchemy_site, :public, host: "alchemy-cms.com") }
let(:language) { create(:alchemy_language, site: site) }

let(:page) do
Alchemy::Site.current = site
root = create(:alchemy_page, :language_root, language: language)
create(:alchemy_page, :public, parent: root)
end

it "loads this site by host" do
get "http://#{site.host}/#{page.urlname}"
expect(assigns(:current_alchemy_site).host).to eq(site.host)
end
end

context "a site with alias and redirecting to primary host" do
let!(:site) do
create(
:alchemy_site,
:public,
host: "real.example.com",
aliases: "something.alchemy-cms.com",
redirect_to_primary_host: true
)
end

context "requested by alias host" do
it "redirects to primary host" do
get "http://something.alchemy-cms.com/#{page.urlname}"
expect(response).to redirect_to("http://real.example.com/#{page.urlname}")
end
end
end
end

0 comments on commit 4687a02

Please sign in to comment.