Can't do publish to mercure inside symfony controller, but I can do it from postMan and from demo mercure URL http://localhost:3000/.well-known/mercure/ui/
From class PublishController extends AbstractController I have:
$hub->publish($update); -
TransportException
Failed to connect to localhost port 3000 after 0 ms: Connection refused for "http://localhost:3000/.well-known/mercure".
docker-compose.yaml
mercure:
image: dunglas/mercure
restart: unless-stopped
environment:
SERVER_NAME: ':80'
DEMO: 1
PUBLISH_ALLOWED_ORIGINS: '*'
MERCURE_CORS_ALLOWED_ORIGINS: '*'
ALLOW_ANONYMOUS: 1
MERCURE_EXTRA_DIRECTIVES: |-
cors_origins "http://localhost:8000"
anonymous
MERCURE_PUBLISHER_JWT_KEY: '!ChangeMe!'
MERCURE_SUBSCRIBER_JWT_KEY: '!ChangeMe!'
# Comment the following line to disable the development mode
command: /usr/bin/caddy run -config /etc/caddy/Caddyfile.dev
In env file:
MERCURE_URL=http://localhost:3000/.well-known/mercure
# The public URL of the Mercure hub, used by the browser to connect
MERCURE_PUBLIC_URL=http://localhost:3000/.well-known/mercure
MERCURE_PUBLISH_URL=http://mercure:3000/.well-known/mercure
# The secret used to sign the JWTs
MERCURE_JWT_SECRET=!ChangeMe!
enter code here
Webserver URL http://localhost:8000 and I can even subscribe on events from front-end
<script>
const eventSource = new EventSource("{{ mercure('topic')|escape('js') }}");
eventSource.onmessage = event => {
// Will be called every time an update is published by the server
console.log(JSON.parse(event.data));
}
How to handle it?