0

I'm trying to setup a Mercure hub with my symfony app.

When I try to publish something on it using the Symfony\Component\Mercure\Publisher class, i'm getting a TransportException from curl : "Couldn't connect to server for "http://localhost:3000/.well-known/mercure"." No reaction from my Mercure hub (launched in local)

I'm trying since yesterday to locate what is wrong with my setup, but I fail to find more information to guide me (a wrong JWT token/key ? a bad allowed-origins setting ?)

I tried using the exact config displayed in Mercure's documentation :

./mercure --jwt-key='!ChangeMe!' --addr=':3000' --debug --allow-anonymous --cors-allowed-origins='*' --publish-allowed-origins='http://localhost:3000'

eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdLCJzdWJzY3JpYmUiOlsiaHR0cHM6Ly9leGFtcGxlLmNvbS9teS1wcml2YXRlLXRvcGljIiwie3NjaGVtZX06Ly97K2hvc3R9L2RlbW8vYm9va3Mve2lkfS5qc29ubGQiLCIvLndlbGwta25vd24vbWVyY3VyZS9zdWJzY3JpcHRpb25zey90b3BpY317L3N1YnNjcmliZXJ9Il0sInBheWxvYWQiOnsidXNlciI6Imh0dHBzOi8vZXhhbXBsZS5jb20vdXNlcnMvZHVuZ2xhcyIsInJlbW90ZUFkZHIiOiIxMjcuMC4wLjEifX19.z5YrkHwtkz3O_nOnhC_FP7_bmeISe3eykAkGbAl5K7c

I manage to subscribe to the hub via postman and via my symfony app (a small route that redirects to Mercure, in order to proxy the call through my app authentication).

Is there any way to get more information from mercure or symfony to help me troubleshot the issue ?

EDIT :

With more digging, it seems that the issue is that my Symfony is in a docker container while my mercure hub is on local... Still digging more.

Mouke
  • 854
  • 1
  • 7
  • 19
  • I suspect from within the docker container, the outside mercure server might not be on "localhost", just guessing though ;o/ – Jakumi Aug 13 '20 at 07:44
  • I had the same suspicion, but I have elements going with and against you (I can't reach the hub through a direct get query inside a controller, but I can redirect a get query to it). Maybe it's something in the headers... – Mouke Aug 13 '20 at 07:47
  • well, the redirect tells your browser (outside) to look at some ip, however, it's your browser making the connection, and it has access to the correct localhost.try port 3000 on the gateway ip, which is relevant with bridge networking – Jakumi Aug 13 '20 at 07:51
  • Indeed you were right. I'm going to make an answer. :) – Mouke Aug 13 '20 at 08:32
  • glad it worked ;o) – Jakumi Aug 13 '20 at 08:53

1 Answers1

1

So, after some digging and with the help of Jakumi (thank you, you rock), the issue was that my hub was on my machine localhost while symfony hits on its container localhost. Using http://host.docker.internal:3000, I manage to reach the hub and publish on it.

Thanks again Jakumi !

Mouke
  • 854
  • 1
  • 7
  • 19