Configuration of Mercure with Symfony 5

Viewed 973

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
2 Answers

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

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.

Related