Skip to content

Commit dc5c75c

Browse files
committed
Rewrite host domain for Shopify storefront URIs in development
1 parent d818d67 commit dc5c75c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

lib/shopify_app/utils.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ def sanitize_shop_domain(shop_domain)
2121

2222
return myshopify_domain_from_unified_admin(uri) if unified_admin?(uri) && from_trusted_domain
2323
return nil if no_shop_name_in_subdomain || uri.host&.empty?
24-
return uri.host if from_trusted_domain
24+
25+
next unless from_trusted_domain
26+
return dev_api_domain(uri.host) if storefront_domain?(uri)
27+
28+
return uri.host
2529
end
2630
nil
2731
end
@@ -65,6 +69,14 @@ def trusted_domains
6569
trusted_domains
6670
end
6771

72+
def storefront_domain?(uri)
73+
uri.host.include?(".my.shop.dev")
74+
end
75+
76+
def dev_api_domain(host)
77+
host.gsub(".my.shop.dev", ".dev-api.shop.dev")
78+
end
79+
6880
def uri_from_shop_domain(shop_domain)
6981
name = shop_domain.to_s.downcase.strip
7082
name += ".#{myshopify_domain}" if !name.include?(myshopify_domain.to_s) && !name.include?(".")

test/shopify_app/utils_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ class UtilsTest < ActiveSupport::TestCase
3434
end
3535
end
3636

37+
[
38+
"https://my-shop.my.shop.dev",
39+
"http://my-shop.my.shop.dev",
40+
"my-shop.my.shop.dev",
41+
].each do |good_url|
42+
test "sanitize_shop_domain replaces development storefront domain for (#{good_url}) with internal domain" do
43+
assert_equal "my-shop.dev-api.shop.dev", ShopifyApp::Utils.sanitize_shop_domain(good_url)
44+
end
45+
end
46+
3747
test "sanitize_shop_domain URL shopify spin.dev custom myshopify_domain" do
3848
myshop_domain = "http://shopify.foobar-part-onboard-0d6x.asdf-rygus.us.spin.dev"
3949
ShopifyApp.configuration.stubs(:myshopify_domain).returns(myshop_domain)

0 commit comments

Comments
 (0)