0

我正在尝试在本地环境(Windows 10)上使用 Mercure 和 Symfony 4 框架。

尝试使用symfony serve -d(https://localhost:8000/)php -S localhost:3000 -t public或 8000启动服务器

使用 PowerShell 启动 Mercure Hub: $env:MERCURE_PUBLISHER_JWT_KEY='!ChangeMe!';$env:MERCURE_SUBSCRIBER_JWT_KEY='!ChangeMe!'; .\mercure.exe run -config Caddyfile.dev

访问 https://localhost/.well-known/mercure/ui/ => Mercure Hub 界面,OK

访问https://localhost/.well-known/mercure:缺少“topic”参数(不知道是否正常)

.env.local 文件(在 jwt.io 上创建的 jwt !ChangeMe!)

MERCURE_PUBLISH_URL=https://localhost/.well-known/mercure
MERCURE_JWT_TOKEN=eyJhbGciOiJIUzI1NiJ9.eyJtZXJjdXJlIjp7InB1Ymxpc2giOlsiKiJdLCJzdWJzY3JpYmUiOlsiKiJdfX0.Ws4gtnaPtM-R2-z9DnH-laFu5lDZrMnmyTpfU8uKyQo

index.html.twig

监听 HUB 的脚本。

url.searchParams.append('topic', 'https://example.com/my-private-topic'); 
const eventSource = new EventSource(url);
eventSource.onmessage = e => {
      console.log(e);
}

在此页面中,我还有一个按钮,用于调用控制器中的路由,该控制器调用 Mercure HUB。

控制器(从 index.html.twig 访问的路由)

$update = new Update("https://example.com/my-private-topic","[]");
$publisher($update);

我在 Firefox 中的错误(在 Chrome 中相同):

Problem with the SSL CA cert (path? access rights?) for "https://localhost:8000/.well-known/mercure".

为什么涉及8000端口?我还没有在那个端口打开集线器。它设置为简单的本地主机。

结果在 Powershell

2021/03/20 15:42:19.193 ←[34mINFO←[0m   http.log.access handled request {"request": {"remote_addr": "127.0.0.1:51637", "proto": "HTTP/2.0", "method": "GET", "host": "localhost", "uri": "/.well-known/mercure?topic=https%3A%2F%2Fexample.com%2Fmy-private-topic", "headers": {"Accept-Language": ["fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3"], "Accept-Encoding": ["gzip, deflate, br"], "Referer": ["https://127.0.0.1:8000/"], "Pragma": ["no-cache"], "User-Agent": ["Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0"], "Accept": ["text/event-stream"], "Origin": ["https://127.0.0.1:8000"], "Cache-Control": ["no-cache"], "Te": ["trailers"]}, "tls": {"resumed": false, "version": 772, "cipher_suite": 4865, "proto": "h2", "proto_mutual": true, "server_name": "localhost"}}, "common_log": "127.0.0.1 - - [20/Mar/2021:16:42:19 +0100] \"GET /.well-known/mercure?topic=https%3A%2F%2Fexample.com%2Fmy-private-topic HTTP/2.0\" 200 2", "duration": 1.4322458, "size": 2, "status": 200, "resp_headers": {"X-Xss-Protection": ["1; mode=block"], "Content-Security-Policy": ["default-src 'self' mercure.rocks cdn.jsdelivr.net"], "Expire": ["0"], "X-Content-Type-Options": ["nosniff"], "Access-Control-Allow-Origin": ["*"], "Cache-Control": ["private, no-cache, no-store, must-revalidate, max-age=0"], "X-Frame-Options": ["DENY"], "Connection": ["keep-alive"], "Content-Type": ["text/event-stream"], "Pragma": ["no-cache"], "X-Accel-Buffering": ["no"], "Alt-Svc": ["h3-32=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000"], "Access-Control-Allow-Credentials": ["true"], "Server": ["Caddy"]}}  

任何帮助表示赞赏。

4

0 回答 0