2

I'm trying to code a chat with Symfony 5 and Mercure, but I have some issues with the configuration. I work with Windows 10.

This is the documentation that I followed : https://github.com/dunglas/mercure/blob/main/docs/hub/install.md

I installed this version on my project: mercure_0.13.0_Windows_arm64.zip. Then, I decompressed it, and right after in my terminal, I ran "composer require symfony/mercure".

This is in my .env:

# See https://symfony.com/doc/current/mercure.html#configuration
# The URL of the Mercure hub, used by the app to publish updates (can be a local URL)
MERCURE_URL=:https://127.0.0.1:8000/.well-known/mercure
# The public URL of the Mercure hub, used by the browser to connect
MERCURE_PUBLIC_URL=https://127.0.0.1:8000/.well-known/mercure
# The secret used to sign the JWTs
MERCURE_JWT_SECRET="!ChangeMe!"
###< symfony/mercure-bundle ###```

Then I ran the Mercure server with this command line : ```$env:MERCURE_PUBLISHER_JWT_KEY='!ChangeMe!'; $env:MERCURE_SUBSCRIBER_JWT_KEY='!ChangeMe!'; .\mercure.exe run -config Caddyfile.dev```.

In my PowerShell, I have this : 
```2021/11/16 01:39:58.029 INFO    http    server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS {"server_name": "srv0", "https_port": 443}
2021/11/16 01:39:58.029 INFO    http    enabling automatic HTTP->HTTPS redirects        {"server_name": "srv0"}
2021/11/16 01:39:58.111 INFO    tls     cleaning storage unit   {"description": "FileStorage:C:\\Users\\toufi\\AppData\\Roaming\\Caddy"}
2021/11/16 01:39:58.113 INFO    tls     finished cleaning storage units
2021/11/16 01:39:58.134 INFO    pki.ca.local    root certificate is already trusted by system   {"path": "storage:pki/authorities/local/root.crt"}
2021/11/16 01:39:58.135 INFO    http    enabling automatic TLS certificate management   {"domains": ["localhost"]}
2021/11/16 01:39:58.136 WARN    tls     stapling OCSP   {"error": "no OCSP stapling for [localhost]: no OCSP server specified in certificate"}
2021/11/16 01:39:58.143 INFO    autosaved config (load with --resume flag)      {"file": "C:\\Users\\toufi\\AppData\\Roaming\\Caddy\\autosave.json"}
2021/11/16 01:39:58.143 INFO    serving initial configuration```

It seems to run well, but in my browser when I run ```https://localhost/.well-known/mercure```,
I have :
```Not Found
The requested URL was not found on this server.

Apache/2.4.46 (Win64) OpenSSL/1.1.1h PHP/7.4.25 Server at localhost Port 443```

Someone can help me because I don't know how to access to my Mercure server with my browser ?

Thank you very much
Ben
  • 15
  • 4

2 Answers2

1

Hey ben you should try and run https://localhost:8000/.well-known/mercure in ur browser instead of https://localhost/.well-known/mercure

  • I tried ```https://localhost:8000/.well-known/mercure``` in my browser but I got this message : ```Ce site ne peut pas fournir de connexion sécurisée localhost a envoyé une réponse incorrecte. Essayez d'exécuter les diagnostics réseau de Windows. ERR_SSL_PROTOCOL_ERROR``` – Ben Nov 16 '21 at 11:12
  • you have to config the ssl in your Caddyfile.dev file or disable it if you dont want to use https – Ouss Ma L'aire Bien Nov 16 '21 at 11:26
  • Sorry the only doc that I found to config the ssl is with Docker, but I didn't use it – Ben Nov 16 '21 at 21:54
  • To disable HTTPS entirely, set the auto_https global option to off in ur caddyfile.dev for more informations you can checkk this https://mercure.rocks/docs/hub/config – Ouss Ma L'aire Bien Nov 17 '21 at 08:54
  • I did this in my file : ```{ {$GLOBAL_OPTIONS} } { auto_https off } {$SERVER_NAME:localhost} log route { encode zstd gzip mercure { # Transport to use (default to Bolt) transport_url {$MERCURE_TRANSPORT_URL:bolt://mercure.db} # Publisher JWT key publisher_jwt {env.MERCURE_PUBLISHER_JWT_KEY} {env.MERCURE_PUBLISHER_JWT_ALG} # Subscriber JWT key subscriber_jwt {env.MERCURE_SUBSCRIBER_JWT_KEY} {env.MERCURE_SUBSCRIBER_JWT_ALG} # Extra directives {$MERCURE_EXTRA_DIRECTIVES} } respond /healthz 200 respond "Not Found" 404 } ``` – Ben Nov 18 '21 at 14:32
  • And I still have the same issue – Ben Nov 18 '21 at 14:35
0

Maybe you've allready figured out this problem in the last 3 months, but here are a thing it came to my mind.

You start Mercure 0.13 in dev mode (Caddyfile.dev) allowing to access the demo page. (Btw I miss the log entry here which tells you, that the server uses the file specified by you, and should be something like {"level":"info","ts":1646214769.1484525,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile.dev","config_adapter":""}) You may want to open this demo page to see if Mercure works or not. The default url is https://localhost/.well-known/mercure/ui/. It may vary depending on your settings. It worth to try also with http.

You don't provide the SERVER_NAME env variable, so I assume caddy attempts to use 80 and 443 ports. Therefore https://127.0.0.1:8000 in symfony config won't work. And 80 might fail if there is already a web server running to provide access for symfony. You can use SERVER_NAME=:8000 to launch mercure on port 8000, but in this case it will be only http, not https.

So, what I would do in your case, I would start mercure in dev mode, and check the demo page. If both http and https attempts fail, I would start mercure with additional SERVER_NAME (ex. 8000) and check http://localhost:8000/.well-known/mercure/ui/. If nothing goes wrong, one of them should work. And then you can proceed to configure symfony to use the mercury service.

Tyll
  • 33
  • 4