Skip to content

Commit a4f18f2

Browse files
GoodForOneFareShinomix
authored andcommitted
Avoid storefront routes in local development
1 parent b8eee39 commit a4f18f2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/shopify_api/auth/oauth.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ def begin_auth(shop:, redirect_path:, is_online: true, scope_override: nil)
4646
}
4747

4848
query_string = URI.encode_www_form(query)
49+
auth_route = auth_base_uri(shop) + "/oauth/authorize?#{query_string}"
4950

50-
auth_route = "https://#{shop}/admin/oauth/authorize?#{query_string}"
5151
{ auth_route: auth_route, cookie: cookie }
5252
end
5353

@@ -106,6 +106,20 @@ def validate_auth_callback(cookies:, auth_query:)
106106

107107
{ session: session, cookie: cookie }
108108
end
109+
110+
private
111+
112+
sig { params(shop: String).returns(String) }
113+
def auth_base_uri(shop)
114+
return "https://#{shop}/admin" unless defined?(DevServer)
115+
116+
# For first-party apps in development only, we leverage DevServer to build the admin base URI
117+
admin_web = T.unsafe(Object.const_get("DevServer")).new("web") # rubocop:disable Sorbet/ConstantsFromStrings
118+
admin_host = admin_web.unsafe_unchecked_host(nonstandard_host_prefix: "admin")
119+
shop_name = shop.split(".").first
120+
121+
"https://#{admin_host}/store/#{shop_name}"
122+
end
109123
end
110124
end
111125
end

lib/shopify_api/clients/http_client.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def request(request, response_as_struct: false)
3939
headers = @headers
4040
headers["Content-Type"] = T.must(request.body_type) if request.body_type
4141
headers = headers.merge(T.must(request.extra_headers)) if request.extra_headers
42+
if headers["Host"].include?(".my.shop.dev")
43+
headers["x-forwarded-host"] = headers["Host"]
44+
headers["Host"] = "app.shop.dev"
45+
end
4246

4347
tries = 0
4448
response = HttpResponse.new(code: 0, headers: {}, body: "")

0 commit comments

Comments
 (0)