admin管理员组

文章数量:1391818

I have a project that I deployed with SSL certificate with Apache to do some visualization tests in "online" rather than local. I was trying to set up Mercure using the Symfony Bundle and the Caddyfile. I did not download the Mercure hub but I set up a caddyfile with this configuration:

3000
route {
encode gzip
mercure {
publisher_jwt "eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdfX0.8Qddz5nDJJHS3uuQelknCq0pfdeWs1_sPw7wI32ZuIU"
subscriber_jwt "eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InN1YnNjcmliZSI6WyIqIl19fQ.aOEYOnOJ4ZNSN0WIlUsAv-KcixDox2q9zk62EujFgpw"
anonymous
debug
}
respond "Mercure is running!"
}

Now if I insert Anonymous "apparently" it seems to work if I go to inspect element>network it returns 200, but if I remove it, it gives me an error with 401 Unauthorized.

Also in the case where I have anonymous and I try to send an "update", since I inserted a try and catch, in the catch, I inserted a dd if it fails, and in fact I get back: "Failed to send an update", even though in the network it is: 200. In my .env I have this configuration:

# The URL of the Mercure hub, used by the app to publish updates (can be a local URL)
MERCURE_URL=https://..../.well-known/mercure
# The public URL of the Mercure hub, used by the browser to connect
MERCURE_PUBLIC_URL=https://...../.well-known/mercure
#MERCURE_JWT_SECRET="s3cr3tK3ySup3rS3cur3"
MERCURE_JWT_SECRET="0123456789abcdef0123456789abcdef"

Where in the "..." there is my public ip address (ex. /), despite this it does not seem to work and I just can not make it communicate. I do not understand why though. I followed the documentation but I just can't...

In php I send events with:

$update = new Update(
'notifiche-utente-' . $utenteDestinatario->getId(),
$this->renderView('layouts/_turbo.notification-stream.html.twig', [
'notification' => $notifica,
'notificationsCount' => $notificheUnLette
])
);

$hub->publish($update);

And in JavaScript:

const url = "{{ mercure('notifiche-utente-' ~ app.user.id) }}";
const eventSource = new EventSource(url, { withCredentials: true });
eventSource.onmessage = event => {
Turbo.renderStreamMessage(event.data);
};

It doesn't work. Why?

I've tried everything and following the documentation I can't seem to fix it. Locally it seems to work fine with Docker, but in a deployment with SSL it doesn't seem to work.

本文标签: websocketSymfony with Mercure and Caddy not workingStack Overflow