Python-带mercure_hub的烧瓶

时间:2020-09-23 14:00:28

标签: python flask mercure

我尝试从https://github.com/dunglas/mercure/tree/master/examples/chat开始跟踪聊天的实现。 但是到目前为止,我还没有成功实现这一目标。

对于Mercure集线器实施,我构建了一个小的docker compose:

OPTIONS

发布消息似乎可行: screenshot

在烧瓶方面,我还没有修改原始的仓库,我正在用pycharm(烧瓶运行)启动服务器:https://github.com/dunglas/mercure/tree/master/examples/chat 但是加载页面时出现此错误: enter image description here

如果我发布消息,我从水星那里得到了200,但瓶边没有任何东西。 我究竟做错了什么? 谢谢

编辑: 我发现问题出在我打电话时 enter image description here

为什么我尝试获得所有订阅者时得到404?我错过配置了吗?

1 个答案:

答案 0 :(得分:0)

我知道了:

因此,首先订阅1 issue

version: '3.5'
services: 
mercure:
    container_name: mercure
    image: dunglas/mercure
    environment:
        - JWT_KEY=!ChangeMe!
        - DEMO=1
        - ALLOW_ANONYMOUS=1
        - SUBSCRIPTIONS=1
        - CORS_ALLOWED_ORIGINS=http://127.0.0.1:5000
        - PUBLISH_ALLOWED_ORIGINS=http://127.0.0.1:5000
    ports:
        - "3000:80"

然后引用Doc中的报价:

此外,所有端点必须在返回的JSON-LD文档的根目录中设置lastEventID属性:

lastEventID:集线器在发出此请求时调度的最后一个事件的标识符(请参阅对帐)。如果尚未调度任何事件,则该值必须是最早的。订阅事件时,应将此属性的值传递回集线器,以防止数据丢失。>

  const subscribeURL = new URL(hubURL);
  subscribeURL.searchParams.append(
    "Last-Event-ID",
    subscriptionCollection.lastEventID
    );