From ec5542200b2da0afd15d920b3fdb54c01165c15c Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 22 Apr 2021 20:50:16 +0200 Subject: [PATCH 1/2] Pass port to preview url If the preview url has a port configured it uses that on the preview frame. --- lib/alchemy/admin/preview_url.rb | 1 + spec/libraries/admin/preview_url_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/alchemy/admin/preview_url.rb b/lib/alchemy/admin/preview_url.rb index 3bcde8a71e..697e3bda0c 100644 --- a/lib/alchemy/admin/preview_url.rb +++ b/lib/alchemy/admin/preview_url.rb @@ -45,6 +45,7 @@ def url_for(page) if @preview_config && uri uri_class.build( host: uri.host, + port: uri.port, path: page.url_path, userinfo: userinfo, ).to_s diff --git a/spec/libraries/admin/preview_url_spec.rb b/spec/libraries/admin/preview_url_spec.rb index 8c2b9e91f7..70e98c3685 100644 --- a/spec/libraries/admin/preview_url_spec.rb +++ b/spec/libraries/admin/preview_url_spec.rb @@ -71,6 +71,18 @@ end end + context "with a port configured" do + before do + stub_alchemy_config(:preview, { + "host" => "https://www.example.com:8080", + }) + end + + it "returns the configured preview url with userinfo" do + is_expected.to eq "https://www.example.com:8080/#{page.urlname}" + end + end + context "for a site" do before do stub_alchemy_config(:preview, config) From 7cc978b0f3d1b1f1a74f042cd3a626e0f8cc6d28 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 22 Apr 2021 20:54:15 +0200 Subject: [PATCH 2/2] Add alchemy_preview_mode=true to preview url In order to be able to treat a static site different if it's rendered inside the preview frame we pass the alchemy_preview_mode=true param. --- lib/alchemy/admin/preview_url.rb | 1 + spec/libraries/admin/preview_url_spec.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/alchemy/admin/preview_url.rb b/lib/alchemy/admin/preview_url.rb index 697e3bda0c..1e3abcb146 100644 --- a/lib/alchemy/admin/preview_url.rb +++ b/lib/alchemy/admin/preview_url.rb @@ -48,6 +48,7 @@ def url_for(page) port: uri.port, path: page.url_path, userinfo: userinfo, + query: { alchemy_preview_mode: true }.to_param, ).to_s else routes.admin_page_path(page) diff --git a/spec/libraries/admin/preview_url_spec.rb b/spec/libraries/admin/preview_url_spec.rb index 70e98c3685..24fa0c2cb4 100644 --- a/spec/libraries/admin/preview_url_spec.rb +++ b/spec/libraries/admin/preview_url_spec.rb @@ -39,7 +39,7 @@ end it "returns the configured preview url" do - is_expected.to eq "http://www.example.com/#{page.urlname}" + is_expected.to eq "http://www.example.com/#{page.urlname}?alchemy_preview_mode=true" end end @@ -51,7 +51,7 @@ end it "returns the configured preview url with https" do - is_expected.to eq "https://www.example.com/#{page.urlname}" + is_expected.to eq "https://www.example.com/#{page.urlname}?alchemy_preview_mode=true" end end @@ -67,7 +67,7 @@ end it "returns the configured preview url with userinfo" do - is_expected.to eq "https://foo:baz@www.example.com/#{page.urlname}" + is_expected.to eq "https://foo:baz@www.example.com/#{page.urlname}?alchemy_preview_mode=true" end end @@ -79,7 +79,7 @@ end it "returns the configured preview url with userinfo" do - is_expected.to eq "https://www.example.com:8080/#{page.urlname}" + is_expected.to eq "https://www.example.com:8080/#{page.urlname}?alchemy_preview_mode=true" end end @@ -98,7 +98,7 @@ end it "returns the configured preview url for that site" do - is_expected.to eq "http://new.example.com/#{page.urlname}" + is_expected.to eq "http://new.example.com/#{page.urlname}?alchemy_preview_mode=true" end end @@ -114,7 +114,7 @@ end it "returns the default configured preview url" do - is_expected.to eq "http://www.example.com/#{page.urlname}" + is_expected.to eq "http://www.example.com/#{page.urlname}?alchemy_preview_mode=true" end end @@ -144,7 +144,7 @@ end it "returns the preview url without urlname" do - is_expected.to eq "https://www.example.com/" + is_expected.to eq "https://www.example.com/?alchemy_preview_mode=true" end end end