Skip to content

fix: check if api is reachable during registration #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/EventListener/BeforeRegistrationStartsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __invoke(BeforeRegistrationStartsEvent $event): void
$shop = $event->getShop();

try {
$this->httpClient->request('HEAD', $shop->getShopUrl(), [
$this->httpClient->request('HEAD', sprintf("%s/api/_info/config", $shop->getShopUrl()), [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem with that is that we get always a 401 🤔. is that fine. @nsaliu

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this case when we do a HEAD instead of POST request 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, POST is not allowed but even a GET would return a HTTP 200 with the 401 error in the payload 🙈
But a HEAD does also return a 200 without any response body and also no error 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to our awesome community! 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MoritzKrafeld

But a HEAD does also return a 200 without any response body and also no error

Are you sure about that 🤔
When I try e.g. curl --head http://localhost:8000/api/_info/config, i am always getting 401 😬

How did you tried that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm you're right. I'm also getting 401 as a response. I tried this is a few APP_URL's of our customers and never had the problem with that and always got the 200 back 🙈
I will create a PR so that we also allow 401 (or something which would indicate us that the server is reachable) 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should hopefully be fixed in this PR: #58

'timeout' => 10,
'max_redirects' => 0,
]);
Expand Down
4 changes: 2 additions & 2 deletions tests/EventListener/BeforeRegistrationStartsListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function testListenerMustBeExecutedWithoutErrorsIfTheCheckIsSetToTrueInCo
$this->httpClient
->expects(self::once())
->method('request')
->with('HEAD', 'https://shop-url.com', [
->with('HEAD', 'https://shop-url.com/api/_info/config', [
'timeout' => 10,
'max_redirects' => 0,
]);
Expand Down Expand Up @@ -91,7 +91,7 @@ public function testListenerMustThrowExceptionBecauseTheShopURLIsNotReachable():
$this->httpClient
->expects(self::once())
->method('request')
->with('HEAD', 'https://shop-url.com', [
->with('HEAD', 'https://shop-url.com/api/_info/config', [
'timeout' => 10,
'max_redirects' => 0,
])
Expand Down
Loading