Python - Flask with mercure_hub

218 Views Asked by At

I tried to follow chat implementation from here https://github.com/dunglas/mercure/tree/master/examples/chat. But so far, I didn't succeed to achieve that.

For Mercure hub implementation I build a small 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"

And posting messages seems work : screenshot

And flask side, I haven't modify original depos, i am starting the server with pycharm (flask run): https://github.com/dunglas/mercure/tree/master/examples/chat But I get this error when page is loaded : enter image description here

And if i post message, i got 200 from mercure but nothing flask side. What am i doing wrong? Thank you

EDIT : I figured it out that the issue comes from when I call enter image description here

Si why I got 404 when I try to get all subscribers? did I miss-configuration?

1

There are 1 best solutions below

0
On

I figured it out :

So first SUBSCRIPTIONS to 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"

Then quote from Doc :

In addition, all endpoints MUST set the lastEventID property at the root of the returned JSON-LD document:

lastEventID: the identifier of the last event dispatched by the hub at the time of this request (see reconciliation). The value MUST be earliest if no events have been dispatched yet. The value of this property SHOULD be passed back to the hub when subscribing to subscription events to prevent data loss.>

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