我是这个平台的新用户,我正在尝试按照文档将 Mercure 集成到 Symfony:https ://symfony.com/blog/symfony-gets-real-time-push-capabilities 。一旦控制台中的所有步骤都遵循 chrome 对 Publisher 类的响应,就会生成错误:
净 :: ERR_ABORTED 406。
你能帮我理解如何使这个捆绑包工作吗?
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Mercure\Publisher;
use Symfony\Component\Mercure\Update;
class PublishController
{
public function __invoke(Publisher $publisher)
{
$update = new Update(
'http://example.com/books/1',
json_encode(['status' => 'OutOfStock'])
);
// The Publisher service is an invokable object
$publisher($update);
}
}
const es = new EventSource('https://www.davidecpr.online/hub?topic=' + encodeURIComponent('http://example.com/books/1'));
es.onmessage = e => {
// Will be called every time an update is published by the server
console.log(JSON.parse(e.data));
};
.env 变量设置如下: 'MERCURE_PUBLISH_URL' => ' http://www.davidecpr.online:3000/hub '