Skip to content

Commit

Permalink
Merge pull request #1004 from hoppergee/http_webhook_registration_fix
Browse files Browse the repository at this point in the history
Support full URL and schemeless URL when register HTTP webhooks as usual
  • Loading branch information
mkevinosullivan committed Sep 16, 2022
2 parents e3ec2ad + 2bd5f24 commit bed77e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
## Version 11.1.0

- [#1002](https://github.com/Shopify/shopify-api-ruby/pull/1002) Add new method to construct the host app URL for an embedded app, allowing for safer redirect to app inside appropriate shop admin
- [#1004](https://github.com/Shopify/shopify-api-ruby/pull/1004) Support full URL and scheme-less URL when registering HTTP webhooks

## Version 11.0.1

Expand Down
8 changes: 7 additions & 1 deletion lib/shopify_api/webhooks/registrations/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ class Http < Registration

sig { override.returns(String) }
def callback_address
"https://#{Context.host_name}/#{@path}"
if @path.match?(%r{^https://})
@path
elsif @path.match?(/^#{Context.host_name}/)
"https://#{@path}"
else
"https://#{Context.host_name}/#{@path}"
end
end

sig { override.returns(T::Hash[Symbol, String]) }
Expand Down
8 changes: 8 additions & 0 deletions test/webhooks/registry_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def test_http_registration_add_and_update
do_registration_test(:http, "test-webhooks")
end

def test_http_registration_add_and_update_with_full_url
do_registration_test(:http, "https://app-address.com/test-webhooks")
end

def test_http_registration_add_and_update_with_schemeless_url
do_registration_test(:http, "app-address.com/test-webhooks")
end

def test_http_registration_with_fields_add_and_update
do_registration_test(:http, "test-webhooks", fields: "field1, field2")
end
Expand Down

0 comments on commit bed77e4

Please sign in to comment.