【问题标题】:Python - Flask with mercure_hubPython - 带有 mercure_hub 的烧瓶
【发布时间】:2020-09-23 14:00:28
【问题描述】:

我试图从这里https://github.com/dunglas/mercure/tree/master/examples/chat 关注聊天实现。 但到目前为止,我还没有成功实现这一目标。

对于 Mercure hub 实施,我构建了一个小型 docker compose:

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

并且发布消息似乎有效:

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

如果我发布消息,我会从 Mercure 获得 200,但没有烧瓶侧。 我究竟做错了什么? 谢谢

编辑: 我发现问题出在我打电话的时候

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

【问题讨论】:

  • 请查看link
  • 我应该在安装部分看到有关订阅者 api 的内容吗??

标签: python flask mercure


【解决方案1】:

我想通了:

所以首先订阅 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
    );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    相关资源
    最近更新 更多